-
Notifications
You must be signed in to change notification settings - Fork 87
187 lines (164 loc) · 7.53 KB
/
publish-new-release.yml
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
name: Publish New Release to GitHub
on:
pull_request:
branches:
- main
types:
- closed
env:
NODE_OPTIONS: '--no-warnings'
jobs:
release:
name: Publish new release
# For publishing GitHub release, we need to only use the GitHub hosted runners
runs-on: ubuntu-latest
# only merged pull requests must trigger this job
if: >
(startsWith(github.event.pull_request.head.ref, 'release/') ||
startsWith(github.event.pull_request.head.ref, 'hotfix-release/')) &&
github.event.pull_request.merged == true
steps:
- name: Extract version from branch name (for release branches)
id: extract-version
env:
BRANCH_NAME_REF: ${{ github.event.pull_request.head.ref }}
run: |
BRANCH_NAME="${BRANCH_NAME_REF}"
VERSION=${BRANCH_NAME#hotfix-}
VERSION=${VERSION#release/}
# Extract the ticket ID (case-insensitive match for -SDK-<ticket_number>)
RELEASE_TICKET_ID=$(echo "$BRANCH_NAME" | grep -oE '[sS][dD][kK]-[0-9]+')
echo "release_ticket_id=$RELEASE_TICKET_ID" >> $GITHUB_OUTPUT
# Remove the -SDK-<ticket_number> suffix case insensitively
VERSION=$(echo "$VERSION" | awk '{sub(/-[sS][dD][kK]-[0-9]+$/, ""); print}')
echo "release_version=$VERSION" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}
# 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 [email protected]
- name: Create monorepo release tag
id: create_monorepo_release
run: |
git tag -a v${{ steps.extract-version.outputs.release_version }} -m "chore(monorepo): release v${{ steps.extract-version.outputs.release_version }}"
git push origin refs/tags/v${{ steps.extract-version.outputs.release_version }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup workspace
env:
HUSKY: 0
run: |
npm run setup:deps
- name: Get the two latest versions
run: |
CURRENT_VERSION=$(git tag -l "v3*" --sort=-version:refname | head -n 1)
LAST_VERSION=$(git tag -l "v3*" --sort=-version:refname | head -n 2 | awk 'NR == 2 { print $1 }')
echo "Current version: $CURRENT_VERSION"
echo "Previous version: $LAST_VERSION"
echo "current_monorepo_version=$(echo $CURRENT_VERSION)" >> $GITHUB_ENV
echo "last_monorepo_version=$(echo $LAST_VERSION)" >> $GITHUB_ENV
echo "DATE=$(date)" >> $GITHUB_ENV
- name: Create GitHub releases
id: create_release
continue-on-error: true
env:
HUSKY: 0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# The default behavior of Nx is to consider changes to package-lock.json
# as impacting all the packages.
# Here is a work around to ignore package-lock.json and package.json
# files before publishing the releases.
# Ref: https://github.com/nrwl/nx/issues/15116#issuecomment-1535260119
echo package-lock.json >> .nxignore
echo package.json >> .nxignore
npm run release:github -- --base=${{ env.last_monorepo_version }} --head=${{ env.current_monorepo_version }}
# Restore working copy
git checkout -- .nxignore
- name: Create pull request into develop
if: always()
continue-on-error: true
uses: repo-sync/pull-request@v2
with:
source_branch: 'main'
destination_branch: 'develop'
github_token: ${{ secrets.PAT }}
pr_title: 'chore(release): merge main into develop after release v${{ steps.extract-version.outputs.release_version }} [${{ steps.extract-version.outputs.release_ticket_id }}]'
pr_body: |
:crown: **Automated Post-Release PR**
This pull request was created automatically by the GitHub Actions workflow. It merges changes from the `main` branch into the `develop` branch after a release has been completed.
This ensures that the `develop` branch stays up to date with all release-related changes from the `main` branch.
### Details
- **Release Version**: v${{ steps.extract-version.outputs.release_version }}
- **Related Ticket**: [${{ steps.extract-version.outputs.release_ticket_id }}](https://linear.app/rudderstack/issue/${{ steps.extract-version.outputs.release_ticket_id }})
---
Please review and merge it before closing the release ticket. :rocket:
- name: Send message to Slack channel
id: slack
if: always()
continue-on-error: true
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
PROJECT_NAME: 'JS SDK Monorepo'
TAG_COMPARE_URL: 'https://github.com/rudderlabs/rudder-sdk-js/compare/'
RELEASES_URL: 'https://github.com/rudderlabs/rudder-sdk-js/releases/tag/'
with:
channel-id: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}
payload: |
{
"text": "*New Release: ${{ env.PROJECT_NAME }} - <${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SHJ20350>",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New Release: ${{ env.PROJECT_NAME }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<${{ env.TAG_COMPARE_URL }}${{ env.last_monorepo_version }}...v${{ steps.extract-version.outputs.release_version }}|v${{ steps.extract-version.outputs.release_version }}>*\n${{ env.DATE }}\nCC: <!subteam^S0555JBV36D> <!subteam^S03SW7DM8P3> <!subteam^S03SHJ20350>"
},
"accessory": {
"type": "image",
"image_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"alt_text": "GitHub Icon"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "For more details, check the full release notes <${{ env.RELEASES_URL }}v${{ steps.extract-version.outputs.release_version }}|here>."
}
]
}
]
}
publish-npm-packages:
needs: release
name: Publish packages to NPM
uses: ./.github/workflows/deploy-npm.yml
with:
is_called: 'true'
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
RS_PROD_BUGSNAG_API_KEY: ${{ secrets.RS_PROD_BUGSNAG_API_KEY }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_RELEASE_CHANNEL_ID: ${{ secrets.SLACK_RELEASE_CHANNEL_ID }}