Skip to content

Commit ab4de5f

Browse files
Add GitHub Actions workflow to auto-sync API from calico-private (#183)
Same approach as the projectcalico/api sync workflow (projectcalico/api#120), but pulls from `tigera/calico-private` instead. Uses `MARVIN_PAT` for private repo access (same pattern as the operator `sync-versions` workflow). Auto-discovers `master` + the two most recent `release-calient-*` branches, so it doesn't need updating when new release branches are created. Runs hourly + manual dispatch.
2 parents 546021d + 8e76c44 commit ab4de5f

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Sync API files from tigera/calico-private into this repo.
2+
# Creates or updates a PR if anything changed.
3+
---
4+
name: Sync Calico API
5+
on: # yamllint disable-line rule:truthy
6+
schedule:
7+
- cron: '0 * * * *' # every hour
8+
workflow_dispatch: {}
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
discover-branches:
16+
if: github.repository == 'tigera/api'
17+
runs-on: ubuntu-latest
18+
outputs:
19+
branches: ${{ steps.branches.outputs.branches }}
20+
steps:
21+
- name: Discover branches
22+
id: branches
23+
run: |
24+
# Get master + the two most recent release branches (by semver).
25+
branches=$(gh api repos/${{ github.repository }}/branches --paginate --jq '
26+
[.[] | select(.name | test("^release-calient-v[0-9]+\\.[0-9]+$")) | .name]
27+
| sort_by(ltrimstr("release-calient-v") | split(".") | map(tonumber))
28+
| .[-2:]
29+
| ["master"] + .
30+
')
31+
echo "branches=${branches}" >> "$GITHUB_OUTPUT"
32+
env:
33+
GH_TOKEN: ${{ github.token }}
34+
35+
sync:
36+
needs: discover-branches
37+
runs-on: ubuntu-latest
38+
concurrency:
39+
group: sync-calico-api-${{ matrix.branch }}
40+
cancel-in-progress: true
41+
strategy:
42+
fail-fast: false
43+
matrix:
44+
branch: ${{ fromJson(needs.discover-branches.outputs.branches) }}
45+
steps:
46+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
47+
with:
48+
ref: ${{ matrix.branch }}
49+
persist-credentials: false
50+
51+
- name: Configure git auth
52+
run: |
53+
git config --global credential.helper store
54+
echo "https://marvin-tigera:${GITHUB_TOKEN}@github.com" > ~/.git-credentials
55+
git config --global url."https://github.com/".insteadOf "git@github.com:"
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.MARVIN_PAT }}
58+
59+
- name: Sync API from calico-private
60+
run: make -f Makefile.local update
61+
62+
- uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
63+
with:
64+
token: ${{ secrets.GITHUB_TOKEN }}
65+
commit-message: "Automatic API update from tigera/calico-private ${{ matrix.branch }}"
66+
branch: auto-api-update-${{ matrix.branch }}
67+
base: ${{ matrix.branch }}
68+
title: "Auto: sync API from tigera/calico-private [${{ matrix.branch }}]"
69+
body: |
70+
Automated sync of API files from `tigera/calico-private` `${{ matrix.branch }}`
71+
branch into this repo via `make -f Makefile.local update`.
72+
73+
Triggered by scheduled workflow.
74+
labels: docs-not-required,release-note-not-required,merge-when-ready,delete-branch
75+
delete-branch: true

0 commit comments

Comments
 (0)