-
Notifications
You must be signed in to change notification settings - Fork 160
Imports Validation Schemas into the Examples README during CI #803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
JBBianchi
wants to merge
4
commits into
serverlessworkflow:main
from
JBBianchi:feat-examples-readme-hydration
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const YAML = require('yaml'); | ||
|
||
const examplesPath = path.resolve(__dirname, '../../examples/'); | ||
const readMeTemplatePath = path.resolve(examplesPath, 'README_TEMPLATE.md'); | ||
const readMeOutputPath = path.resolve(examplesPath, 'README.md'); | ||
const extractor = /<include file="(.*)" format="(.*)" \/>/g; | ||
const disclaimer = `<!-- | ||
|
||
|
||
!!! THIS IS A GENERATED FILE !!! | ||
Please do not update this file but the TEMPLATE instead! | ||
|
||
|
||
--> | ||
`; | ||
|
||
(async () => { | ||
let readMe = await fs.promises.readFile(readMeTemplatePath, 'utf8'); | ||
const includes = readMe.matchAll(extractor); | ||
for await(let include of includes) { | ||
const fileName = include[1]; | ||
const format = include[2]; | ||
let fileContent = await fs.promises.readFile(path.resolve(examplesPath, fileName), 'utf8'); | ||
if (format === 'yaml') { | ||
try { | ||
const schema = JSON.parse(fileContent); | ||
fileContent = YAML.stringify(schema); | ||
} | ||
catch(ex) { | ||
console.error('Enable to parse JSON or convert it to YAML, output as it is.', ex); | ||
} | ||
} | ||
readMe = readMe.replace(include[0], fileContent); | ||
}; | ||
await fs.promises.writeFile(readMeOutputPath, disclaimer + readMe, { encoding: 'utf8', flag: 'w' }); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "examples-readme-hydration", | ||
"version": "0.1.0", | ||
"description": "Builds ./examples/README.md based on ./examples/README_TEMPLATE.md", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"start": "node ./index.js" | ||
}, | ||
"keywords": ["cncf", "serverless", "workflow", "specification"], | ||
"author": "CNCF Serverless Workflow Specification", | ||
"license": "ISC", | ||
"dependencies": { | ||
"yaml": "^2.3.4" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Check examples README manual updates | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'examples/README.md' | ||
|
||
jobs: | ||
verification: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- if: contains(github.head_ref, 'automation-examples-readme') | ||
name: pass | ||
run: echo "The update is made by the bot, as expected." | ||
|
||
- if: contains(github.head_ref, 'automation-examples-readme') == false | ||
name: fail | ||
run: | | ||
echo "The file examples/README.md should not be manually edited !" | ||
echo "Please update examples/README_TEMPLATE.md instead" | ||
exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Examples README hydration | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: [ 'main'] | ||
paths: | ||
- 'examples/**/*' | ||
- '!examples/README.md' | ||
|
||
jobs: | ||
build: | ||
if: github.repository == 'serverlessworkflow/specification' && github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.BOT_PAT }} | ||
|
||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 21 | ||
|
||
- name: Import GPG key | ||
id: import-gpg | ||
uses: crazy-max/ghaction-import-gpg@v6 | ||
with: | ||
gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} | ||
git_config_global: true | ||
git_user_signingkey: true | ||
git_commit_gpgsign: true | ||
git_tag_gpgsign: true | ||
|
||
- run: | | ||
set -e | ||
|
||
# Reset origin | ||
git remote set-url origin https://${{ secrets.BOT_USERNAME }}:${{ secrets.BOT_PAT }}@github.com/${{ github.repository }}.git | ||
git checkout ${{ github.ref_name }} | ||
|
||
# Create a new git branch | ||
git checkout -b automation-examples-readme-${{ github.event.pull_request.number }} | ||
|
||
# Install & run JS scripts | ||
cd .ci/examples-readme-hydration/ | ||
npm ci | ||
npm start | ||
|
||
# Commit & push changes | ||
git config user.name '${{ secrets.BOT_USERNAME }}' | ||
git config user.email '${{ secrets.BOT_EMAIL }}' | ||
git commit -S -a -m 'Rebuilt examples README.md' | ||
git push origin automation-examples-readme-${{ github.event.pull_request.number }} | ||
|
||
# Create a PR on GH | ||
gh pr create -B main -H automation-examples-readme-${{ github.event.pull_request.number }} --title '[From CI] Rebuilt examples README' --body 'Automatic hydration of examples README.md' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.BOT_PAT }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ reference the [Ownership of Copyrights in CNCF Project Contributions](https://gi | |
### Communication | ||
|
||
- Community Slack Channel: [https://slack.cncf.io/](https://slack.cncf.io/) - #serverless-workflow | ||
- [Weekly project meetings](#Meetings) | ||
- [Weekly project meetings](#weekly-meetings) | ||
- Project Maintainers Email: [cncf-serverlessws-maintainers](mailto:[email protected]) | ||
- Serverless WG Email: [cncf-wg-serverless](mailto:[email protected]) | ||
- Serverless WG Subscription: [https://lists.cncf.io/g/cncf-wg-serverless](https://lists.cncf.io/g/cncf-wg-serverless) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which license is this? Can we change it to Apache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it's the default when generating the npm project I think. As far as I recall, I copy/pasted from https://github.com/serverlessworkflow/specification/blob/main/.ci/validation/package.json