Skip to content

api-sync

api-sync #2009

Workflow file for this run

name: API Sync
on:
repository_dispatch:
types:
- api-sync
workflow_dispatch: # allow manual triggering
# Add explicit permissions
permissions:
contents: write
pull-requests: write
jobs:
sync:
name: Sync API Types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- name: Run codegen
run: go generate
- name: Check for changes
id: check
run: |
if git diff --ignore-space-at-eol --exit-code --quiet pkg; then
echo "No changes detected"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Generate token
id: app-token
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Create Pull Request
if: steps.check.outputs.has_changes == 'true'
id: cpr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: "chore: sync API types from infrastructure"
title: "chore: sync API types from infrastructure"
body: |
This PR was automatically created to sync API types from the infrastructure repository.
Changes were detected in the generated API code after syncing with the latest spec from infrastructure.
branch: sync/api-types
base: develop
- name: Approve a PR
if: steps.check.outputs.has_changes == 'true'
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enable Pull Request Automerge
if: steps.check.outputs.has_changes == 'true'
run: gh pr merge --auto --squash "${{ steps.cpr.outputs.pull-request-number }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}