Skip to content

Commit

Permalink
ci(schema): auto commit schema changes (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 authored Jul 23, 2024
1 parent a464125 commit cb4c6a3
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/pr-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,64 @@ jobs:
repo: context.repo.repo,
body: commentBody
});
auto-commit-schemas:
needs: [compare-graphql-schema, compare-openapi-schema, checkout-branch, update-schemas]
runs-on: ubuntu-latest
if: needs.update-schemas.outputs.OPENAPI_STATUS != '0' || needs.update-schemas.outputs.GRAPHQL_STATUS != '0'
steps:
- name: Check out PR branch
uses: actions/checkout@v3
with:
repository: ${{ needs.checkout-branch.outputs.PR_repo }}
ref: ${{ needs.checkout-branch.outputs.PR_head_ref }}
submodules: true
fetch-depth: 0
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Download OpenAPI diff
uses: actions/download-artifact@v3
with:
name: openapi-diff
path: diffs
- name: Download GraphQL diff
uses: actions/download-artifact@v3
with:
name: graphql-diff
path: diffs
- name: List downloaded files
run: ls -l diffs/
- name: Apply OpenAPI diff
if: needs.update-schemas.outputs.OPENAPI_STATUS != '0'
run: |
patch -p1 < diffs/openapi.diff
echo "Contents of OpenAPI schema after patch:"
cat schema/openapi.yaml
- name: Apply GraphQL diff
if: needs.update-schemas.outputs.GRAPHQL_STATUS != '0'
run: |
patch -p1 < diffs/graphql.diff
echo "Contents of GraphQL schema after patch:"
cat schema/schema.graphql
- name: Commit and push schema changes
run: |
git add schema/openapi.yaml schema/schema.graphql
git commit -S -m "chore(schema): automatic update"
git push origin ${{ needs.checkout-branch.outputs.PR_head_ref }}
- name: Comment on schema update
uses: actions/github-script@v6
with:
script: |
const prNumber = ${{ needs.checkout-branch.outputs.PR_num }};
const comment = "Schema changes committed by the CI.";
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});

0 comments on commit cb4c6a3

Please sign in to comment.