Skip to content

sync-api

sync-api #1876

Workflow file for this run

# This workflow will sync the API types from the cloudnative-pg repository to the API repository, and
# tidy the go.mod file.
# It is supposed to be triggered by a repository_dispatch event whenever the cloudnative-pg api is updated,
# but can also be triggered manually using the "Sync API" workflow_dispatch event.
name: Sync API
on:
workflow_dispatch:
repository_dispatch:
types: [ sync-api ]
permissions: read-all
# A release dispatches a tag-carrying sync while the push to main triggers a
# second, tag-less sync. Serialize them so they don't race on the commit to main
# and the tag-carrying run tags the already-synced commit.
concurrency:
group: sync-api
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout API repository
uses: actions/checkout@v7
with:
token: ${{ secrets.REPO_PAT }}
- name: Checkout cloudnative-pg repository
uses: actions/checkout@v7
with:
path: cloudnative-pg
repository: cloudnative-pg/cloudnative-pg
sparse-checkout: api/v1
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: cloudnative-pg/go.mod
- name: Copy types files from cloudnative-pg
run: |
rm -rf pkg/api/v1
mkdir -p pkg/api/v1
cp -v cloudnative-pg/api/v1/*_types.go pkg/api/v1
cp -v cloudnative-pg/api/v1/doc.go pkg/api/v1
cp -v cloudnative-pg/api/v1/groupversion_info.go pkg/api/v1
cp -v cloudnative-pg/api/v1/zz_*.go pkg/api/v1
cp -v cloudnative-pg/go.mod cloudnative-pg/go.sum .
sed -i '1 s|^.*$|module github.com/cloudnative-pg/api|' go.mod
go mod tidy
go vet ./...
# We want to prevent the "include administrators" branch protection from blocking the commit,
# but it should be usually there to avoid accidental pushes to main.
- name: Temporarily disable "include administrators" branch protection
if: ${{ github.ref == 'refs/heads/main' }}
id: disable_include_admins
uses: benjefferies/branch-protection-bot@v1.1.2
with:
access_token: ${{ secrets.REPO_PAT }}
branch: main
enforce_admins: false
- uses: EndBug/add-and-commit@v10
with:
author_name: CloudNativePG Automated Updates
author_email: noreply@cnpg.com
message: 'chore: sync API'
add: pkg/api/v1 go.mod go.sum
- name: Enable "include administrators" branch protection
uses: benjefferies/branch-protection-bot@v1.1.2
if: ${{ always() && github.ref == 'refs/heads/main' }}
with:
access_token: ${{ secrets.REPO_PAT }}
branch: main
enforce_admins: ${{ steps.disable_include_admins.outputs.initial_status }}
# When the sync is triggered by a release, the cloudnative-pg release-tag
# workflow passes the release tag in the dispatch payload. Tag the freshly
# synced commit so the API repository keeps the same tags as cloudnative-pg.
- name: Tag the synced release
if: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.tag != '' }}
env:
TAG: ${{ github.event.client_payload.tag }}
run: |
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q .; then
echo "Tag ${TAG} already exists, nothing to do."
exit 0
fi
git tag "${TAG}"
git push origin "${TAG}"