Repository navigation
122 lines (112 loc) · 5.31 KB
/
Copy pathsync-skills.yml
File metadata and controls
122 lines (112 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Manual skills sync, for when the release-time sync could not run.
#
# The sync-skills job in release.yml is `needs: [release]`, so anything that
# fails the release job after publication — an unreachable AUR, say — skips the
# sync entirely and leaves basecamp/skills stale against a shipped release.
# release.yml no longer fails that way, but a skipped or failed sync still needs
# a way back without cutting a new tag. This is it.
#
# scripts/sync-skills.sh mirrors the skills/ tree at the given ref into
# basecamp/skills — only this CLI's skills, tracked in its own manifest there
# (.managed-skills.basecamp-cli); other CLIs' skills are never touched — and
# no-ops when the content already matches, so re-running it for an
# already-synced release is safe.
name: Sync skills
on:
workflow_dispatch:
inputs:
tag:
description: 'Release tag to sync from, with the v prefix (e.g. v0.8.0)'
required: true
type: string
dry_run:
description: 'Preview the sync without pushing'
required: false
default: false
type: boolean
permissions: {}
concurrency:
group: sync-skills
cancel-in-progress: false
jobs:
sync:
name: Sync skills
runs-on: ubuntu-latest
timeout-minutes: 10
environment: release
permissions:
contents: read
steps:
- name: Validate tag input
env:
TAG: ${{ inputs.tag }}
GH_TOKEN: ${{ github.token }}
run: |
# No prerelease suffix: the automatic sync in release.yml excludes
# prereleases deliberately, and this path must not smuggle prerelease
# content into the distribution repo's main branch.
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid tag '${TAG}' — expected a stable v-prefixed semver tag (e.g. v0.8.0)"
exit 1
fi
# sync-skills.sh mirrors this CLI's skills wholesale, so syncing an
# older tag would roll them back in basecamp/skills. Unlike the AUR, there is no
# independent record of what the distribution repo currently holds, and
# the only reason to run this by hand is that the newest release failed
# to sync — so require exactly that release.
latest=$(gh release view --repo "${GITHUB_REPOSITORY}" --json tagName --jq .tagName)
if [ "$TAG" != "$latest" ]; then
echo "::error::Refusing to sync ${TAG}: the latest stable release is ${latest}. Syncing an older tag would roll basecamp/skills back."
exit 1
fi
# Two checkouts: sync logic from the dispatching ref, skills content from
# the release tag. A defect in scripts/sync-skills.sh is one of the ways
# the automatic sync fails, and running the tagged copy here would just
# re-run the defective script — recovery must be able to run a fix merged
# to main without cutting a new tag.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# The content still mirrors the skills tree as it was released, even if
# main has moved on since: SKILLS_SOURCE points the script at this
# checkout. Fully qualified: actions/checkout resolves a bare name as a
# branch before a tag, so a branch sharing the tag's name would win and
# mirror unreleased content.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: refs/tags/${{ inputs.tag }}
path: release
persist-credentials: false
# Needed for dry runs too: the honest preview clones the target, so it
# cannot run tokenless. Dry runs get a read-only token, which is also what
# stops DRY_RUN=remote from pushing even if the script were wrong.
- name: Generate token for skills repo
id: skills-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
client-id: ${{ vars.RELEASE_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
owner: basecamp
repositories: skills
permission-contents: ${{ inputs.dry_run && 'read' || 'write' }}
# github.sha is the dispatching ref's SHA (main), not the tag's, so
# resolve the tagged commit from its own checkout — otherwise the sync
# records the wrong provenance for the release it claims to mirror.
- name: Resolve the tagged commit
id: source
env:
TAG: ${{ inputs.tag }}
run: echo "sha=$(git -C release rev-parse --verify "refs/tags/${TAG}^{commit}")" >> "$GITHUB_OUTPUT"
# DRY_RUN=remote, not local: the local path never clones basecamp/skills
# and diffs against an empty repo, so every skill reads as newly added and
# the deletions a real sync would make never appear. That is the opposite
# of what a preview is for. Remote clones the actual target and stops
# before the push.
- name: Sync skills to distribution repo
env:
SKILLS_TOKEN: ${{ steps.skills-token.outputs.token }}
RELEASE_TAG: ${{ inputs.tag }}
SOURCE_SHA: ${{ steps.source.outputs.sha }}
SKILLS_SOURCE: release/skills
DRY_RUN: ${{ inputs.dry_run && 'remote' || '' }}
run: scripts/sync-skills.sh