Skip to content

api-sync

api-sync #1387

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@v6
- uses: actions/setup-go@v6
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@v2
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@v8
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 }}