Added new way to merge samples

This commit is contained in:
Hugo Bernier 2024-03-24 14:31:20 -04:00 committed by GitHub
parent ac169ca034
commit df246d48aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 0 deletions

45
.github/workflows/merge-json.yml vendored Normal file
View File

@ -0,0 +1,45 @@
name: Merge JSON files
on:
push:
paths:
- '/samples/**/assets/sample.json'
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Download samples.json
run: wget https://raw.githubusercontent.com/pnp/sp-dev-fx-extensions/main/.metadata/samples.json
- name: Install dependencies
run: npm install glob lodash
- name: Merge JSON files
run: node .github/workflows/merge.js
- name: Commit to Docs branch
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout Docs
git add docs/samples.json
git commit -m "Update samples.json"
git push
- name: Commit to gh-pages branch
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout gh-pages
git add samples.json
git commit -m "Update samples.json"
git push

14
.github/workflows/merge.js vendored Normal file
View File

@ -0,0 +1,14 @@
const glob = require('glob');
const fs = require('fs');
const _ = require('lodash');
let result = {};
glob("samples/**/assets/sample.json", function (er, files) {
files.forEach(file => {
const data = JSON.parse(fs.readFileSync(file));
result = _.merge(result, data);
});
fs.writeFileSync('samples.json', JSON.stringify(result));
});