-
Notifications
You must be signed in to change notification settings - Fork 15
274 lines (234 loc) · 11 KB
/
Copy pathdraft-new-release.yml
File metadata and controls
274 lines (234 loc) · 11 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
name: Draft a new release
on:
workflow_dispatch:
inputs:
release_ticket_id:
description: Release ticket ID (Ex:- SDK-1234)
required: true
slack_message_link:
description: Slack message URL of the release
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_OPTIONS: '--no-warnings'
jobs:
validate-actor:
# Only allow to draft a new release from develop and hotfix branches
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/hotfix/')
uses: ./.github/workflows/validate-actor.yml
with:
team_names: 'js-sdk,integrations'
secrets:
PAT: ${{ secrets.PAT }}
draft-new-release:
needs: validate-actor
name: Draft a new release
runs-on: [self-hosted, Linux, X64]
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup workspace
env:
HUSKY: 0
run: |
npm run setup:deps
# In order to make a commit, we need to initialize a user.
# You may choose to write something less generic here if you want, it doesn't matter functionality wise.
- name: Initialize mandatory git config
run: |
git config user.name "GitHub actions"
git config user.email noreply@github.com
# Calculate the next release version based on conventional semantic release
- name: Create release branch
id: create-release
env:
HUSKY: 0
run: |
source_branch_name=${GITHUB_REF#refs/heads/}
release_type=release
grep -q "hotfix/" <<< "${GITHUB_REF}" && release_type=hotfix-release
git fetch origin main
git fetch --tags origin
git merge origin/main
current_version=$(jq -r .version package.json)
npm run bump-version:monorepo
new_version=$(jq -r .version package.json)
git reset --hard
branch_name="${release_type}/${new_version}-${{ github.event.inputs.release_ticket_id }}"
echo "Source branch for new release is $source_branch_name"
echo "Current version is $current_version"
echo "Release type is $release_type"
echo "New version is $new_version"
echo "New release branch name is $branch_name"
git checkout -b "$branch_name"
git push --set-upstream origin "$branch_name"
echo "source_branch_name=$source_branch_name" >> $GITHUB_OUTPUT
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
echo "new_version=$new_version" >> $GITHUB_OUTPUT
echo "CURRENT_VERSION_VALUE=$current_version" >> $GITHUB_ENV
echo "NEW_VERSION_VALUE=$new_version" >> $GITHUB_ENV
- name: Update changelog & bump version
id: finish-release
env:
HUSKY: 0
BASE_BRANCH: ${{ steps.create-release.outputs.branch_name }}
run: |
echo "Current version: $CURRENT_VERSION_VALUE"
echo "New version: $NEW_VERSION_VALUE"
git fetch --no-tags --prune --depth=100 origin main
npm run release
./scripts/sync-tags-in-nx-projects.sh
./scripts/generate-last-release-changelog.sh
npm run bump-version:monorepo
npx replace $CURRENT_VERSION_VALUE $NEW_VERSION_VALUE sonar-project.properties
npm install
npm run clean
git add .
git commit -m "chore(monorepo): sync versions and generate release logs" -n
- name: Generate packages versions table
id: packages-versions
run: |
chmod +x ./scripts/collect-packages-versions.sh
./scripts/collect-packages-versions.sh > packages_versions.md
- name: Push new version in release branch
run: |
git push --follow-tags
- name: Create pull request into main
id: create-pr
env:
GH_TOKEN: ${{ secrets.PAT }}
run: |
pr_title="chore(release): merge ${{ steps.create-release.outputs.branch_name }} into main [${{ github.event.inputs.release_ticket_id }}]"
# Create PR body with proper formatting
cat > pr_body.md << EOF
:crown: **Automated Release PR**
This pull request was created automatically by the GitHub Actions workflow. It merges the release branch (\`${{ steps.create-release.outputs.branch_name }}\`) into the \`main\` branch.
This ensures that the latest release branch changes are incorporated into the \`main\` branch for production.
### Details
- **Monorepo Release Version**: v${{ env.NEW_VERSION_VALUE }}
- **Release Branch**: \`${{ steps.create-release.outputs.branch_name }}\`
- **Related Ticket**: [${{ github.event.inputs.release_ticket_id }}](https://linear.app/rudderstack/issue/${{ github.event.inputs.release_ticket_id }})
### Version updates
$(cat packages_versions.md)
---
Please review and merge when ready. :rocket:
EOF
# Create the PR using GitHub CLI and capture the URL
pr_url=$(gh pr create \
--base main \
--head ${{ steps.create-release.outputs.branch_name }} \
--title "$pr_title" \
--body-file pr_body.md)
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT
- name: Extract Slack channel and thread info
id: slack-info
continue-on-error: true
run: |
link="${{ github.event.inputs.slack_message_link }}"
# Extract channel ID from the link (after /archives/ and before the next /)
channel_id=$(echo "$link" | sed -n 's|.*\/archives\/\([^\/]*\)\/.*|\1|p')
# Check if thread_ts parameter exists in URL (for messages within a thread)
if echo "$link" | grep -q "thread_ts="; then
# Extract thread_ts parameter value
thread_ts=$(echo "$link" | sed -n 's|.*thread_ts=\([0-9]*\.[0-9]*\).*|\1|p')
echo "Using thread_ts from URL parameter: $thread_ts"
else
# Extract timestamp from /p part and convert to timestamp format (for parent messages)
thread_ts=$(echo "$link" | sed -n 's|.*\/p\([0-9]*\).*|\1|p')
# Convert from Slack link format (p1640995200123456) to timestamp format (1640995200.123456)
if [ ${#thread_ts} -eq 16 ]; then
# Split into seconds and microseconds parts
seconds=${thread_ts:0:10}
microseconds=${thread_ts:10:6}
thread_ts="${seconds}.${microseconds}"
fi
echo "Using timestamp from /p part: $thread_ts"
fi
echo "Extracted channel ID: $channel_id"
echo "Final thread timestamp: $thread_ts"
echo "channel_id=$channel_id" >> $GITHUB_OUTPUT
echo "thread_ts=$thread_ts" >> $GITHUB_OUTPUT
- name: Create release info artifact
if: ${{ steps.slack-info.outputs.thread_ts != '' && steps.slack-info.outputs.channel_id != '' }}
run: |
# Create directory for artifact
mkdir -p release-info
# Create JSON file with release information
cat > release-info/release-info.json << EOF
{
"channel_id": "${{ steps.slack-info.outputs.channel_id }}",
"thread_ts": "${{ steps.slack-info.outputs.thread_ts }}",
"pr_url": "${{ steps.create-pr.outputs.pr_url }}",
"release_version": "${{ env.NEW_VERSION_VALUE }}",
"release_branch": "${{ steps.create-release.outputs.branch_name }}",
"release_ticket_id": "${{ github.event.inputs.release_ticket_id }}",
"created_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
echo "Created release info artifact:"
cat release-info/release-info.json
- name: Upload release info artifact
if: ${{ steps.slack-info.outputs.thread_ts != '' && steps.slack-info.outputs.channel_id != '' }}
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: release-info-v${{ env.NEW_VERSION_VALUE }}-${{ github.event.inputs.release_ticket_id }}
path: release-info/
retention-days: 30
- name: Reply in Slack thread
if: ${{ steps.slack-info.outputs.thread_ts != '' && steps.slack-info.outputs.channel_id != '' }}
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
continue-on-error: true
with:
method: chat.postMessage
payload-templated: true
retries: rapid
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
{
"channel": "${{ steps.slack-info.outputs.channel_id }}",
"thread_ts": "${{ steps.slack-info.outputs.thread_ts }}",
"text": ":rocket: Release PR created: <${{ steps.create-pr.outputs.pr_url }}|${{ steps.create-pr.outputs.pr_url }}>\nCC: <!subteam^S0555JBV36D> <!subteam^S03SW7DM8P3> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":rocket: *Release PR Created*: \n<${{ steps.create-pr.outputs.pr_url }}|${{ steps.create-pr.outputs.pr_url }}>\n\n*Monorepo Version:* v${{ env.NEW_VERSION_VALUE }}\n*Release Branch:* `${{ steps.create-release.outputs.branch_name }}`\n\n:point_right: Review and merge when ready!\nCC: <!subteam^S0555JBV36D> <!subteam^S03SW7DM8P3> <!subteam^S03SHJ20350>"
}
}
]
}
- name: Delete hotfix release base branch
continue-on-error: true
if: startsWith(github.ref_name, 'hotfix/')
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const branchToDelete = '${{ github.ref_name }}';
const owner = context.repo.owner;
const repo = context.repo.repo;
const ref = `heads/${branchToDelete}`;
try {
await github.rest.git.deleteRef({
owner,
repo,
ref
});
console.log(`Branch ${branchToDelete} deleted successfully.`);
} catch (error) {
console.error(`Error deleting branch ${branchToDelete}:`, error);
process.exit(1); // Fail the workflow if branch deletion fails
}