|
| 1 | +name: YAML2JSON |
| 2 | + |
| 3 | +# |
| 4 | +# This workflow updates the *.json files in the examples/v3.0 directory, |
| 5 | +# when the corresponding *.yaml files change. |
| 6 | +# JSON example files are automatically generated from the YAML example files. |
| 7 | +# Only the YAML files should be adjusted manually. |
| 8 | +# |
| 9 | + |
| 10 | +# run this on push to master |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - master |
| 15 | + - try-github-actions |
| 16 | + |
| 17 | +jobs: |
| 18 | + yaml2json: |
| 19 | + |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v1 # checkout repo content |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + cd examples/v3.0 |
| 28 | + echo '{}' > composer.json |
| 29 | + # fix versions to ensure reproduceable runs |
| 30 | + composer require cebe/php-openapi:1.3.1 symfony/yaml:4.2.12 cebe/indent:1.1.0 |
| 31 | +
|
| 32 | + - name: convert YAML examples to JSON |
| 33 | + run: | |
| 34 | + cd examples/v3.0 |
| 35 | + for file in *.yaml ; do |
| 36 | + target=`basename -s .yaml $file`.json |
| 37 | + echo "converting $file to $target ..." |
| 38 | + if [ "$file" != "api-with-examples.yaml" ] ; then |
| 39 | + vendor/bin/php-openapi convert --read-yaml $file --write-json $target |
| 40 | + vendor/bin/indent --tabs --tabstop=4 $target |
| 41 | + vendor/bin/indent --spaces --tabstop=2 $target |
| 42 | + fi |
| 43 | + done |
| 44 | + |
| 45 | + - name: cleanup |
| 46 | + run: | |
| 47 | + cd examples/v3.0 |
| 48 | + rm -rf vendor/ composer.* |
| 49 | +
|
| 50 | + - name: git diff |
| 51 | + run: | |
| 52 | + cd examples/v3.0 |
| 53 | + git add *.json |
| 54 | + git diff --staged |
| 55 | +
|
| 56 | + - name: Create Pull Request |
| 57 | + uses: peter-evans/create-pull-request@v1 |
| 58 | + with: |
| 59 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + branch-suffix: none |
| 61 | + branch: update-json-examples |
| 62 | + title: Update JSON example files |
| 63 | + commit-message: Update JSON example files |
| 64 | + body: | |
| 65 | + This pull request is automatically triggered by github actions [create-pull-request][1]. |
| 66 | + |
| 67 | + It seems the OpenAPI example YAML files have changed, so the JSON files are automatically being adjusted. |
| 68 | + |
| 69 | + [1]: https://github.com/peter-evans/create-pull-request |
| 70 | +
|
0 commit comments