|
| 1 | +name: skills-release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'skills/**' |
| 8 | + - 'scripts/**' |
| 9 | + - '.release-policy.yml' |
| 10 | + - '.github/workflows/skills-release.yml' |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + version_override: |
| 14 | + description: 'Optional explicit version tag (vX.Y.Z)' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + bump_type: |
| 18 | + description: 'Semver bump type when no version_override is set' |
| 19 | + required: false |
| 20 | + default: 'patch' |
| 21 | + type: choice |
| 22 | + options: |
| 23 | + - patch |
| 24 | + - minor |
| 25 | + - major |
| 26 | + - auto |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: write |
| 30 | + |
| 31 | +jobs: |
| 32 | + release: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + - uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: '3.11' |
| 41 | + |
| 42 | + - name: Validate skills |
| 43 | + run: python scripts/validate_skills.py |
| 44 | + |
| 45 | + - name: Read release policy |
| 46 | + id: policy |
| 47 | + run: | |
| 48 | + python - << 'PY' |
| 49 | + from pathlib import Path |
| 50 | + txt = Path('.release-policy.yml').read_text(encoding='utf-8') |
| 51 | + auto = 'auto_release: true' in txt |
| 52 | + with open(Path.cwd() / '.policy_out', 'w', encoding='utf-8') as f: |
| 53 | + f.write(f"auto_release={'true' if auto else 'false'}\n") |
| 54 | + PY |
| 55 | + cat .policy_out >> "$GITHUB_OUTPUT" |
| 56 | +
|
| 57 | + - name: Decide whether release is allowed |
| 58 | + id: gate |
| 59 | + run: | |
| 60 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 61 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 62 | + elif [ "${{ steps.policy.outputs.auto_release }}" = "true" ]; then |
| 63 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 64 | + else |
| 65 | + echo "should_release=false" >> "$GITHUB_OUTPUT" |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Stop (policy gate) |
| 69 | + if: steps.gate.outputs.should_release != 'true' |
| 70 | + run: echo "Release policy disabled for push events; exiting successfully." |
| 71 | + |
| 72 | + - name: Determine bump from PR labels |
| 73 | + if: steps.gate.outputs.should_release == 'true' && github.event_name == 'push' |
| 74 | + id: prlabels |
| 75 | + uses: actions/github-script@v7 |
| 76 | + with: |
| 77 | + script: | |
| 78 | + const {owner, repo} = context.repo; |
| 79 | + let bump = 'patch'; |
| 80 | + try { |
| 81 | + const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 82 | + owner, |
| 83 | + repo, |
| 84 | + commit_sha: context.sha, |
| 85 | + }); |
| 86 | + if (prs.data && prs.data.length > 0) { |
| 87 | + const labels = (prs.data[0].labels || []).map(l => l.name); |
| 88 | + if (labels.includes('release:major')) bump = 'major'; |
| 89 | + else if (labels.includes('release:minor')) bump = 'minor'; |
| 90 | + } |
| 91 | + } catch (e) { |
| 92 | + core.warning(`Could not infer PR labels: ${e.message}`); |
| 93 | + } |
| 94 | + core.setOutput('bump', bump); |
| 95 | +
|
| 96 | + - name: Compute version |
| 97 | + if: steps.gate.outputs.should_release == 'true' |
| 98 | + id: version |
| 99 | + env: |
| 100 | + INPUT_BUMP: ${{ github.event.inputs.bump_type }} |
| 101 | + INPUT_VERSION: ${{ github.event.inputs.version_override }} |
| 102 | + PUSH_BUMP: ${{ steps.prlabels.outputs.bump }} |
| 103 | + run: | |
| 104 | + if [ -n "${INPUT_VERSION:-}" ]; then |
| 105 | + VERSION="$INPUT_VERSION" |
| 106 | + else |
| 107 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 108 | + BUMP="${INPUT_BUMP:-patch}" |
| 109 | + else |
| 110 | + BUMP="${PUSH_BUMP:-patch}" |
| 111 | + fi |
| 112 | + VERSION=$(python scripts/compute_next_version.py --bump "$BUMP") |
| 113 | + fi |
| 114 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 115 | +
|
| 116 | + - name: Check tag does not already exist |
| 117 | + if: steps.gate.outputs.should_release == 'true' |
| 118 | + run: | |
| 119 | + if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 120 | + echo "Tag ${{ steps.version.outputs.version }} already exists" >&2 |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | +
|
| 124 | + - name: Determine release range |
| 125 | + if: steps.gate.outputs.should_release == 'true' |
| 126 | + id: range |
| 127 | + run: | |
| 128 | + PREV=$(git tag --list 'v*' --sort=-v:refname | head -n 1 || true) |
| 129 | + if [ -n "$PREV" ]; then |
| 130 | + FROM="$PREV" |
| 131 | + else |
| 132 | + FROM=$(git rev-list --max-parents=0 HEAD) |
| 133 | + fi |
| 134 | + echo "from_ref=$FROM" >> "$GITHUB_OUTPUT" |
| 135 | + echo "to_ref=${GITHUB_SHA}" >> "$GITHUB_OUTPUT" |
| 136 | +
|
| 137 | + - name: Build release notes |
| 138 | + if: steps.gate.outputs.should_release == 'true' |
| 139 | + run: | |
| 140 | + python scripts/build_release_notes.py \ |
| 141 | + --from-ref "${{ steps.range.outputs.from_ref }}" \ |
| 142 | + --to-ref "${{ steps.range.outputs.to_ref }}" \ |
| 143 | + --version "${{ steps.version.outputs.version }}" \ |
| 144 | + --repo "${{ github.repository }}" \ |
| 145 | + --output RELEASE_NOTES.md |
| 146 | +
|
| 147 | + - name: Create and push tag |
| 148 | + if: steps.gate.outputs.should_release == 'true' |
| 149 | + run: | |
| 150 | + git config user.name "github-actions[bot]" |
| 151 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 152 | + git tag "${{ steps.version.outputs.version }}" "${GITHUB_SHA}" |
| 153 | + git push origin "${{ steps.version.outputs.version }}" |
| 154 | +
|
| 155 | + - name: Create GitHub release |
| 156 | + if: steps.gate.outputs.should_release == 'true' |
| 157 | + uses: softprops/action-gh-release@v2 |
| 158 | + with: |
| 159 | + tag_name: ${{ steps.version.outputs.version }} |
| 160 | + name: ${{ steps.version.outputs.version }} |
| 161 | + body_path: RELEASE_NOTES.md |
0 commit comments