-
Notifications
You must be signed in to change notification settings - Fork 1.4k
176 lines (142 loc) · 5.98 KB
/
desktop_auto_release.yml
File metadata and controls
176 lines (142 loc) · 5.98 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
name: Auto Release Desktop on Main
on:
push:
branches: ["main"]
paths:
- 'desktop/**'
- '!desktop/CHANGELOG.json'
permissions:
contents: write
pull-requests: write
concurrency:
group: desktop-auto-release-main
cancel-in-progress: false
jobs:
tag-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Wait for previous desktop release build
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
if [ -z "${GH_TOKEN:-}" ]; then
echo "PAT_TOKEN is not configured; cannot inspect previous release build status."
exit 1
fi
LATEST=$(git tag -l 'v*-macos' | sort -V | tail -1)
if [ -z "$LATEST" ]; then
echo "No previous macOS tag found."
exit 0
fi
SHA=$(gh api "repos/${{ github.repository }}/git/ref/tags/$LATEST" --jq '.object.sha')
echo "Latest tag: $LATEST ($SHA)"
for i in {1..120}; do
STATUS=$(gh api "repos/${{ github.repository }}/commits/$SHA/check-runs" \
--jq '.check_runs[] | select(.name=="Release OMI Desktop (Swift)") | .status' | head -n1 || true)
CONCLUSION=$(gh api "repos/${{ github.repository }}/commits/$SHA/check-runs" \
--jq '.check_runs[] | select(.name=="Release OMI Desktop (Swift)") | .conclusion' | head -n1 || true)
if [ -z "$STATUS" ]; then
echo "No Codemagic release check found for $LATEST yet; continuing."
exit 0
fi
echo "Previous release build status: $STATUS (${CONCLUSION:-n/a})"
if [ "$STATUS" = "completed" ]; then
exit 0
fi
sleep 60
done
echo "Timed out waiting for previous desktop release build to finish."
exit 1
- name: Compute next version and consolidate changelog
id: version
run: |
# Get latest desktop release tag
LATEST=$(git tag -l 'v*-macos' | sort -V | tail -1)
if [ -z "$LATEST" ]; then
VERSION="0.0.1"
else
# Strip v prefix and +build-macos suffix e.g. v0.11.11+11011-macos -> 0.11.11
VER=$(echo "$LATEST" | sed -E 's/^v([0-9.]+)\+[0-9]+-macos$/\1/')
MAJOR=$(echo "$VER" | cut -d. -f1)
MINOR=$(echo "$VER" | cut -d. -f2)
PATCH=$(echo "$VER" | cut -d. -f3)
PATCH=$((${PATCH:-0} + 1))
VERSION="$MAJOR.$MINOR.$PATCH"
fi
# Build number: 0.11.12 -> 11012 (each component * 1000, summed)
BUILD_NUMBER=$(echo "$VERSION" | tr '.' '\n' | awk '{s=s*1000+$1}END{print s}')
RELEASE_TAG="v${VERSION}+${BUILD_NUMBER}-macos"
echo "Latest tag : ${LATEST:-none}"
echo "New version: $VERSION"
echo "New tag : $RELEASE_TAG"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
# Consolidate unreleased changelog entries into a versioned release
TODAY=$(date -u +%Y-%m-%d)
python3 -c "
import json, sys
with open('desktop/CHANGELOG.json', 'r') as f:
data = json.load(f)
unreleased = data.get('unreleased', [])
if not unreleased:
unreleased = ['Bug fixes and improvements']
new_release = {
'version': '$VERSION',
'date': '$TODAY',
'changes': unreleased
}
data.setdefault('releases', []).insert(0, new_release)
data['unreleased'] = []
with open('desktop/CHANGELOG.json', 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
print(f'Consolidated {len(unreleased)} changelog entries for v$VERSION')
"
- name: Commit changelog and create tag
run: |
VERSION="${{ steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add desktop/CHANGELOG.json
git commit -m "chore: consolidate changelog for v${VERSION}" || echo "No changelog changes to commit"
# Tag the changelog commit first; Codemagic uses this tag to trigger builds.
# NOTE: commit message must NOT contain [skip ci].
git tag "$RELEASE_TAG"
git push origin "$RELEASE_TAG"
- name: Create and auto-merge PR to sync changelog back to main
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
if [ -z "${GH_TOKEN:-}" ]; then
echo "PAT_TOKEN is not configured; cannot auto-merge changelog PR."
exit 1
fi
VERSION="${{ steps.version.outputs.version }}"
BRANCH="changelog/v${VERSION}"
git checkout -B "$BRANCH"
git push --force-with-lease origin "$BRANCH"
PR_NUMBER=$(gh pr list \
--head "$BRANCH" \
--base main \
--state open \
--json number \
--jq '.[0].number')
if [ -z "$PR_NUMBER" ]; then
PR_URL=$(gh pr create \
--title "Update CHANGELOG.json for v${VERSION} [skip ci]" \
--body "Auto-generated: consolidates unreleased entries into v${VERSION} and clears the unreleased array." \
--base main \
--head "$BRANCH")
PR_NUMBER=$(echo "$PR_URL" | awk -F/ '{print $NF}')
fi
# Merge changelog PR in protected branches:
# 1) admin merge if allowed, 2) auto-merge if repo supports it, 3) regular merge if already mergeable.
gh pr merge "$PR_NUMBER" --merge --admin || \
gh pr merge "$PR_NUMBER" --merge --auto || \
gh pr merge "$PR_NUMBER" --merge || \
echo "Changelog PR #$PR_NUMBER requires manual merge."