forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (161 loc) · 6.93 KB
/
Copy pathdraft-release.yml
File metadata and controls
183 lines (161 loc) · 6.93 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
name: 'Draft Release'
on:
workflow_dispatch:
inputs:
channel:
description: 'Release channel'
required: true
type: choice
options:
- beta
- production
ref:
description:
'Branch or tag to release from (default: development for beta, latest
beta tag for production). Use for hotfixes.'
required: false
type: string
dry-run:
description: 'Generate notes without creating a release branch'
required: false
type: boolean
default: false
permissions:
contents: write
pull-requests: write
jobs:
draft-release:
name: Draft Release
runs-on: ubuntu-latest
steps:
- name: Generate app token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DESKTOP_RELEASES_APP_ID }}
private-key: ${{ secrets.DESKTOP_RELEASES_APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ inputs.ref || github.event.repository.default_branch }}
token: ${{ steps.generate-token.outputs.token }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Determine previous and next versions
id: version
run: >
yarn ts-node -P script/tsconfig.json script/draft-release/ci.ts
version ${{ inputs.channel }}
- name: Generate release notes (beta only)
id: notes
if: ${{ inputs.channel == 'beta' }}
uses: github/copilot-release-notes@v1
with:
base-ref: release-${{ steps.version.outputs.compare-base }}
head-ref: ${{ inputs.ref || 'development' }}
instructions: .github/release-notes-instructions.md
env:
GITHUB_TOKEN: ${{ github.token }}
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
- name: Parse changelog entries
id: changelog
env:
CHANNEL: ${{ inputs.channel }}
RELEASE_NOTES: ${{ steps.notes.outputs.release-notes }}
RELEASE_NOTES_JSON: ${{ steps.notes.outputs.release-notes-json }}
UNCERTAIN: ${{ steps.notes.outputs.uncertain-entries }}
SKIPPED: ${{ steps.notes.outputs.skipped-prs }}
PREVIOUS: ${{ steps.version.outputs.previous }}
NEXT: ${{ steps.version.outputs.next }}
run: |
if [ "$CHANNEL" = "production" ]; then
# Production: aggregate existing beta entries via shared script
ENTRIES=$(yarn --silent ts-node -P script/tsconfig.json \
script/draft-release/ci.ts changelog-entries "$PREVIOUS")
else
# Beta: extract descriptions from structured JSON output
if [ -z "$RELEASE_NOTES_JSON" ] || [ "$RELEASE_NOTES_JSON" = "[]" ]; then
echo "::warning::No structured release notes JSON returned"
ENTRIES="[]"
else
ENTRIES=$(echo "$RELEASE_NOTES_JSON" | jq -ce 'map(.description)')
fi
fi
# Write entries as single-line JSON to output
echo "entries=$ENTRIES" >> "$GITHUB_OUTPUT"
COUNT=$(echo "$ENTRIES" | jq 'length')
# Step summary
if [ "$CHANNEL" = "production" ]; then
echo "## Production Release Notes — $NEXT" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "Aggregated $COUNT entries from beta releases since $PREVIOUS:" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "$ENTRIES" | jq -r '.[]' >> "$GITHUB_STEP_SUMMARY"
else
echo "## Draft Release Notes — $NEXT" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "$RELEASE_NOTES" >> "$GITHUB_STEP_SUMMARY"
if [ -n "$UNCERTAIN" ] && [ "$UNCERTAIN" != "[]" ] && [ "$UNCERTAIN" != "" ]; then
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### ⚠️ Entries needing human review" >> "$GITHUB_STEP_SUMMARY"
echo "$UNCERTAIN" >> "$GITHUB_STEP_SUMMARY"
fi
if [ -n "$SKIPPED" ] && [ "$SKIPPED" != "[]" ] && [ "$SKIPPED" != "" ]; then
SKIPPED_COUNT=$(echo "$SKIPPED" | jq 'length' 2>/dev/null || echo 0)
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "<details><summary>$SKIPPED_COUNT PRs excluded from notes</summary>" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "$SKIPPED" >> "$GITHUB_STEP_SUMMARY"
echo "</details>" >> "$GITHUB_STEP_SUMMARY"
fi
fi
echo "📝 Parsed $COUNT changelog entries"
- name: Create release branch and commit
if: ${{ inputs.dry-run == false }}
env:
CHANNEL: ${{ inputs.channel }}
NEXT_VERSION: ${{ steps.version.outputs.next }}
LATEST_BETA: ${{ steps.version.outputs.latest-beta }}
REF_OVERRIDE: ${{ inputs.ref }}
ENTRIES: ${{ steps.changelog.outputs.entries }}
run: |
BRANCH="releases/$NEXT_VERSION"
# Check if the release branch already exists
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
echo "::error::Branch $BRANCH already exists. Delete it first or use dry-run."
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [ -n "$REF_OVERRIDE" ]; then
# Hotfix: already on the correct ref from checkout step
git checkout -b "$BRANCH"
echo "🔧 Hotfix: branched from $REF_OVERRIDE"
elif [ "$CHANNEL" = "production" ]; then
# Production: branch from the latest beta tag
if [ -z "$LATEST_BETA" ]; then
echo "::error::Cannot create a production release branch because no latest beta version was found."
exit 1
fi
git checkout -b "$BRANCH" "release-$LATEST_BETA"
else
# Beta: already on development from checkout step
git checkout -b "$BRANCH"
fi
# Bump app/package.json and update changelog.json
yarn --silent ts-node -P script/tsconfig.json \
script/draft-release/ci.ts prepare "$NEXT_VERSION" "$ENTRIES"
# Ensure changelog.json passes Prettier (ci.ts writes with
# JSON.stringify which differs from Prettier's formatting)
yarn prettier --write changelog.json
git add app/package.json changelog.json
git commit -m "Draft release $NEXT_VERSION"
git push origin "$BRANCH"
echo "✅ Pushed $BRANCH — release-pr.yml will create the draft PR"