diff --git a/.github/workflows/catalog.yml b/.github/workflows/catalog.yml new file mode 100644 index 0000000..e4f031b --- /dev/null +++ b/.github/workflows/catalog.yml @@ -0,0 +1,65 @@ +name: Catalog + +on: + schedule: + # The catalog repository refreshes Mondays 04:17 UTC; run later that day. + - cron: "42 4 * * 1" + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +concurrency: + group: catalog + cancel-in-progress: false + +jobs: + vendor: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Vendor catalog + run: go generate ./internal/app + + - name: Vet, test, build + run: | + go vet ./... + go test ./... + go build -trimpath ./cmd/cmdcode2api + + - name: Open a PR when the snapshot changed + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if git diff --quiet -- internal/app/allowances.json; then + echo "catalog unchanged" + exit 0 + fi + + branch="chore/catalog" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -b "$branch" + git add internal/app/allowances.json + git commit -m "chore: vendor latest catalog" + # Reuse the branch so an open PR updates instead of piling up. + git push --force origin "$branch" + + if [ -n "$(gh pr list --head "$branch" --state open --json number --jq '.[0].number')" ]; then + echo "updated the open $(basename "$branch") PR" + exit 0 + fi + + gh pr create \ + --base master \ + --head "$branch" \ + --title "chore: vendor latest catalog" \ + --body "Automated snapshot update from [commandcode-catalog](https://github.com/peach0x33a/commandcode-catalog). + +The workflow ran \`go vet\`, \`go test\`, and a build before opening this PR. It is opened with the repository's \`GITHUB_TOKEN\`, so the PR checks do not run on their own; the master build runs after merge."