Skip to content

api-sync

api-sync #257

name: API Sync
on:
repository_dispatch:
types:
- api-sync
workflow_dispatch: # allow manual triggering
permissions:
contents: read
jobs:
sync:
name: Sync API Types
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: apps/cli-go/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@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permission-pull-requests: write
permission-contents: write
- 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' && steps.cpr.outputs.pull-request-operation == 'created'
continue-on-error: true
run: gh pr review --approve --repo "${{ github.repository }}" "${STEPS_CPR_OUTPUTS_PULL_REQUEST_NUMBER}"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
STEPS_CPR_OUTPUTS_PULL_REQUEST_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
- name: Enable Pull Request Automerge
if: steps.check.outputs.has_changes == 'true'
run: gh pr merge --auto --squash --repo "${{ github.repository }}" "${STEPS_CPR_OUTPUTS_PULL_REQUEST_NUMBER}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
STEPS_CPR_OUTPUTS_PULL_REQUEST_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
defaults:
run:
working-directory: apps/cli-go