Repository navigation
153 lines (134 loc) · 5.27 KB
/
Copy pathpublish-release.yml
File metadata and controls
153 lines (134 loc) · 5.27 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: "Publish Release"
on:
workflow_dispatch:
inputs:
branch:
description: 'Release branch name (e.g. "release/v1.1.0"). Auto-detected if omitted.'
required: false
type: string
permissions: {}
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
publish-release:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
- name: Configure git identity
run: |
git config --global user.name "aignostics-release-bot[bot]"
git config --global user.email "aignostics-release-bot[bot]@users.noreply.github.com"
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 0
- name: Resolve release branch
id: branch
env:
INPUT: ${{ inputs.branch }}
run: |
if [ -n "$INPUT" ]; then
BRANCH="$INPUT"
else
MATCHES=$(git ls-remote --heads origin 'release/v*' | awk '{print $2}' | sed 's|refs/heads/||')
if [ -z "$MATCHES" ]; then
echo "❌ No release/v* branches found. Run 'make prepare-release' first."
exit 1
fi
COUNT=$(echo "$MATCHES" | wc -l | tr -d ' ')
if [ "$COUNT" -gt 1 ]; then
echo "❌ Multiple release/v* branches found. Specify one explicitly:"
echo "$MATCHES"
exit 1
fi
BRANCH="$MATCHES"
fi
# Validate branch name pattern
if ! echo "$BRANCH" | grep -qE '^release/v[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "❌ Branch '${BRANCH}' does not match 'release/vX.Y.Z'. Aborting."
exit 1
fi
# Validate branch exists on origin
if ! git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null 2>&1; then
echo "❌ Branch '${BRANCH}' does not exist on origin. Aborting."
exit 1
fi
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
echo "✅ Using release branch: ${BRANCH}"
- name: Checkout release branch
run: git checkout "${{ steps.branch.outputs.branch }}"
- name: Install uv
uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
version-file: "pyproject.toml"
enable-cache: true
cache-dependency-glob: uv.lock
- name: Install dependencies
run: uv sync --locked
- name: Read version info
id: version
run: |
NEW_VERSION=$(cat VERSION)
TAG_NAME="v${NEW_VERSION}"
PREV_TAG=$(git describe --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$PREV_TAG" ]; then
PREV_VERSION="${PREV_TAG#v}"
else
PREV_VERSION="(initial)"
fi
echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag_name=${TAG_NAME}" >> "$GITHUB_OUTPUT"
echo "prev_tag=${PREV_TAG}" >> "$GITHUB_OUTPUT"
echo "prev_version=${PREV_VERSION}" >> "$GITHUB_OUTPUT"
- name: Generate changelog
run: |
PREV_TAG="${{ steps.version.outputs.prev_tag }}"
TAG_NAME="${{ steps.version.outputs.tag_name }}"
if [ -n "$PREV_TAG" ]; then
uv run --locked git-cliff --tag "$TAG_NAME" --prepend CHANGELOG.md "${PREV_TAG}..HEAD"
else
uv run --locked git-cliff --tag "$TAG_NAME" --output CHANGELOG.md
fi
- name: Commit changelog
run: |
TAG_NAME="${{ steps.version.outputs.tag_name }}"
git add CHANGELOG.md
if git diff --staged --quiet; then
echo "No changelog changes to commit."
else
git commit --no-verify -m "chore: update changelog for ${TAG_NAME}"
fi
- name: Create annotated tag
run: |
git tag -a "${{ steps.version.outputs.tag_name }}" \
-m "Bump version: ${{ steps.version.outputs.prev_version }} → ${{ steps.version.outputs.new_version }}"
- name: Push branch and tag
run: git push origin "${{ steps.branch.outputs.branch }}" --follow-tags
- name: Print job summary
run: |
BRANCH="${{ steps.branch.outputs.branch }}"
TAG_NAME="${{ steps.version.outputs.tag_name }}"
cat >> "$GITHUB_STEP_SUMMARY" << EOF
## ✅ Release published
| | |
|---|---|
| **Branch** | \`${BRANCH}\` |
| **Tag** | \`${TAG_NAME}\` |
| **Version** | ${{ steps.version.outputs.prev_version }} → ${{ steps.version.outputs.new_version }} |
### Next steps
1. Monitor the CI/CD pipeline triggered by the tag:
[View CI runs](https://github.com/aignostics/python-sdk/actions)
2. Once CI passes and the package is published, merge the release branch:
\`\`\`bash
make merge-release
\`\`\`
EOF