-
Notifications
You must be signed in to change notification settings - Fork 83
134 lines (117 loc) · 4.59 KB
/
draft-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
name: Draft a new release
on:
workflow_dispatch:
inputs:
release_ticket_id:
description: Release ticket ID (Ex:- SDK-1234)
required: true
env:
NODE_OPTIONS: '--no-warnings'
jobs:
draft-new-release:
name: Draft a new release
runs-on: [self-hosted, Linux, X64]
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/hotfix/')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
env:
HUSKY: 0
run: |
npm run setup:ci
# 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]
# 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
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: Push new version in release branch
run: |
git push --follow-tags
- name: Create pull request into main
uses: repo-sync/pull-request@v2
with:
source_branch: ${{ steps.create-release.outputs.branch_name }}
destination_branch: 'main'
github_token: ${{ secrets.PAT }}
pr_title: 'chore(release): pull ${{ steps.create-release.outputs.branch_name }} into main'
pr_body: |
:crown: *An automated PR*
\n\n
Linear Ticket:
https://linear.app/rudderstack/issue/${{ github.event.inputs.release_ticket_id }}
- name: Delete hotfix release base branch
continue-on-error: true
if: startsWith(github.ref_name, 'hotfix/')
uses: actions/github-script@v7
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
}