-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (185 loc) · 6.77 KB
/
draft-release.yml
File metadata and controls
216 lines (185 loc) · 6.77 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Create Draft Release
run-name: "Draft release v${{ github.event.inputs.version }}"
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.1.0)"
required: true
permissions:
contents: write
jobs:
validate:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.SGPCTL_SYNC_APP_ID }}
private-key: ${{ secrets.SGPCTL_SYNC_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
fetch-tags: true
fetch-depth: 0
- name: Validate version format
run: |
VERSION="${{ github.event.inputs.version }}"
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid version format '$VERSION'. Must be semver (e.g. 1.2.3)"
exit 1
fi
- name: Check tag does not already exist
run: |
TAG="v${{ github.event.inputs.version }}"
if git tag -l | grep -qx "$TAG"; then
echo "::error::Tag $TAG already exists"
exit 1
fi
- name: Check version is newer than latest release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ github.event.inputs.version }}"
LATEST=$(gh release list --repo "${{ github.repository }}" --limit 1 --json tagName -q '.[0].tagName // empty' 2>/dev/null || echo "")
LATEST="${LATEST#v}"
if [ -n "$LATEST" ]; then
# Compare versions using sort -V
HIGHER=$(printf '%s\n%s' "$LATEST" "$VERSION" | sort -V | tail -1)
if [ "$HIGHER" = "$LATEST" ]; then
echo "::error::Version $VERSION is not newer than latest release $LATEST"
exit 1
fi
fi
echo "Tagging v${VERSION} (latest: ${LATEST:-none})"
- name: Create and push tag
run: |
TAG="v${{ github.event.inputs.version }}"
git tag "$TAG"
git push origin "$TAG"
check:
needs: validate
runs-on: ubuntu-latest
outputs:
should-build: ${{ steps.compare.outputs.should-build }}
sgp-commit: ${{ steps.sgp-sha.outputs.sha }}
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.SGPCTL_SYNC_APP_ID }}
private-key: ${{ secrets.SGPCTL_SYNC_PRIVATE_KEY }}
repositories: |
sgp
- name: Checkout sgp repo (sparse)
uses: actions/checkout@v4
with:
repository: scaleapi/sgp
token: ${{ steps.app-token.outputs.token }}
sparse-checkout: services/sgpctl
sparse-checkout-cone-mode: true
- name: Get latest SGP commit for services/sgpctl
id: sgp-sha
run: |
echo "sha=$(git log -1 --format=%H -- services/sgpctl)" >> "$GITHUB_OUTPUT"
- name: Compare with last release
id: compare
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the sgp-commit.txt asset from the latest release
LAST_SHA=$(gh release view --repo "${{ github.repository }}" --json assets -q '.assets[] | select(.name=="sgp-commit.txt") | .url' 2>/dev/null | xargs -I{} curl -sL -H "Authorization: token $GH_TOKEN" -H "Accept: application/octet-stream" {} 2>/dev/null || echo "")
CURRENT_SHA="${{ steps.sgp-sha.outputs.sha }}"
echo "Last release SGP commit: ${LAST_SHA:-none}"
echo "Current SGP commit: $CURRENT_SHA"
if [ "$LAST_SHA" = "$CURRENT_SHA" ]; then
echo "No changes to services/sgpctl/ since last release — skipping build."
echo "should-build=false" >> "$GITHUB_OUTPUT"
else
echo "Changes detected — proceeding with build."
echo "should-build=true" >> "$GITHUB_OUTPUT"
fi
build:
needs: check
if: needs.check.outputs.should-build == 'true'
strategy:
matrix:
include:
- runner: ubuntu-latest
artifact: sgpctl-linux-amd64
- runner: macos-latest
artifact: sgpctl-darwin-arm64
- runner: windows-latest
artifact: sgpctl-windows-amd64.exe
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.SGPCTL_SYNC_APP_ID }}
private-key: ${{ secrets.SGPCTL_SYNC_PRIVATE_KEY }}
repositories: |
sgp
- name: Checkout sgp repo (sparse)
uses: actions/checkout@v4
with:
repository: scaleapi/sgp
token: ${{ steps.app-token.outputs.token }}
sparse-checkout: services/sgpctl
sparse-checkout-cone-mode: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
pip install ./services/sgpctl
pip install pyinstaller
- name: Build with PyInstaller
run: |
pyinstaller --onefile --name sgpctl services/sgpctl/sgpctl/cli.py
- name: Rename binary (Windows)
if: runner.os == 'Windows'
run: |
mv dist/sgpctl.exe dist/${{ matrix.artifact }}
- name: Rename binary (Unix)
if: runner.os != 'Windows'
run: |
mv dist/sgpctl dist/${{ matrix.artifact }}
- name: Smoke test
run: |
./dist/${{ matrix.artifact }} --help
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}
release:
needs: [check, build]
if: needs.check.outputs.should-build == 'true'
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Write SGP commit SHA
run: |
echo "${{ needs.check.outputs.sgp-commit }}" > artifacts/sgp-commit.txt
- name: Create draft release with assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="v${{ github.event.inputs.version }}"
REPO="${{ github.repository }}"
# Create a draft release
gh release create "$TAG" --repo "$REPO" --title "$TAG" --generate-notes --draft
# Upload sgp-commit.txt for future change detection
gh release upload "$TAG" artifacts/sgp-commit.txt --repo "$REPO"
# Upload all binaries
for dir in artifacts/*/; do
for file in "$dir"*; do
gh release upload "$TAG" "$file" --repo "$REPO"
done
done