From 94be0db14284a181e1f532750f6a997472a76d8e Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Mon, 16 Jun 2025 15:29:45 -0400 Subject: [PATCH] Automate checking for Pyxis schema updates Signed-off-by: Caleb Xu --- .github/workflows/schema-update.yaml | 65 ++++++++++++++++++++++++++++ Makefile | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/schema-update.yaml diff --git a/.github/workflows/schema-update.yaml b/.github/workflows/schema-update.yaml new file mode 100644 index 0000000..19953ee --- /dev/null +++ b/.github/workflows/schema-update.yaml @@ -0,0 +1,65 @@ +name: Check for schema updates + +on: workflow_dispatch + +jobs: + update: + name: Update generated schema and code for Pyxis + runs-on: ubuntu-latest + steps: + - name: Check for existing pull request + id: check_pr + run: | + pr_count=$(gh pr list --repo "${GITHUB_REPOSITORY}" \ + --state open \ + --json number,url,title \ + --label schema-update \ + --jq '. | length') + echo "Found ${pr_count} pull request(s) currently open for schema update." + echo "pr_count=${pr_count}" | tee -a "${GITHUB_OUTPUT}" + env: + GH_TOKEN: ${{ github.token }} + + - uses: actions/checkout@v4 + if: ${{ steps.check_pr.outputs.pr_count == '0' }} + + - name: Set up Go + uses: actions/setup-go@v5 + if: ${{ steps.check_pr.outputs.pr_count == '0' }} + with: + go-version-file: go.mod + + - name: Generate changes + if: ${{ steps.check_pr.outputs.pr_count == '0' }} + run: | + # Collect the exit code, but a diff here should not be fatal + set +e + make ci.generate + rc=$? + set -e + + if [ "${rc}" != "0" ]; then + # 41898282 is the user id of the GitHub Actions bot. + # https://github.com/actions/checkout#push-a-commit-using-the-built-in-token + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + timestamp=$(date +%s) + git checkout -b "pyxis-schema-update-${timestamp}" + git add internal/genpyxis/schema.graphql internal/genpyxis/generated.go + git commit -m "Update generated schema and code for Pyxis" + git push -u origin "pyxis-schema-update-${timestamp}" + + gh pr create --repo "${GITHUB_REPOSITORY}" \ + --title "Update generated schema and code for Pyxis" \ + --body "${PR_BODY}" \ + --base "${BASE_BRANCH}" \ + --head "pyxis-schema-update-${timestamp}" + else + echo "Schema and code generation completed. No changes were detected." + fi + env: + GH_TOKEN: ${{ github.token }} + BASE_BRANCH: ${{ github.ref_name }} + PR_BODY: | + This pull request was automatically generated by [GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). diff --git a/Makefile b/Makefile index d84c627..aaac66a 100644 --- a/Makefile +++ b/Makefile @@ -89,6 +89,10 @@ diff-check: ci.fmt: fmt diff-check echo "=> ci.fmt done" +.PHONY: ci.generate +ci.generate: generate diff-check + echo "=> ci.generate done" + .PHONY: ci.tidy ci.tidy: tidy diff-check echo "=> ci.tidy done"