-
Notifications
You must be signed in to change notification settings - Fork 7
188 lines (166 loc) · 6.16 KB
/
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
188
name: Release
# triggers on pushes to the 'prod' branch
on:
push:
# NOTE(thuang): Since REGEX is not supported for branches, we cannot target
# any versioned branch: "+([0-9])?(.{+([0-9]),x}).x" as specified in
# .releaserc.js. So we'll need to manually add such branch's name here manually
branches:
- prod
jobs:
# Job 1
release:
name: Release
runs-on: ubuntu-latest # Use the latest version of the Ubuntu runner environment
steps:
# Step 1: Check out the repository code
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Step 2: Set up Node.js environment and cache Yarn dependencies
- name: Setup Node.js and Cache yarn
uses: actions/setup-node@v3
with:
node-version-file: ".node-version" # Specify the Node.js version from '.node-version' file
cache: "yarn" # Cache Yarn dependencies for faster builds
# Step 3: Set up npm and authentication
- name: "Setup npm"
run: |
npm set "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Step 4: Ensure npm access
- name: Ensure NPM access
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Step 5: Install project dependencies using Yarn
- name: Install dependencies
run: yarn
# Step 6: Build the component library in 'dist/' directory
- name: Build component library in dist/
run: yarn build
# Step 7: Configure git user for pushing release changes back to prod branch
- name: Config git user
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
# Step 8: Reset working directory
- name: Reset working directory
run: git checkout -- .
# Step 9: Lerna Version
- name: Lerna Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn version:ci
# Step 10: Commit changes
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore(release): Publish"
branch: ${{ github.head_ref }}
# Step 11: Publish NPM packages
- name: Lerna Publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: yarn publish:ci
# Step 12: Post breaking changes to a Slack channel
- name: Post breaking changes to a Slack channel
env:
SLACK_WEBHOOK_URL: ${{ secrets.SDS_BREAKING_CHANGES_SLACK_WEBHOOK }}
uses: act10ns/slack@v1
with:
status: complete
channel: "#sci-design-system-breaking-changes"
config: .github/config/slack.yml
if: contains(toJson(github.event.commits.*.message), 'BREAKING CHANGE')
# Step 13: Merge prod branch into main
- name: Create PR to merge prod into main
id: createpr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: actions/github-script@v6
with:
script: |
const ownerAndRepo = '${{ github.repository }}';
const [owner, repo] = ownerAndRepo.split('/');
const head = "prod";
const base = "main";
const title = "chore(release): Merge prod into main";
const pr = await github.rest.pulls.list({owner, repo, base, head: `${owner}:${head}`})
if (pr.data.length>0) {
return pr.data[0].number;
}
const result = await github.rest.pulls.create({
owner,
repo,
head,
base,
title,
});
return result.data.number;
# Steps 13 - 15 are temporarily disable until we find a solution
# to the issue of GitHub Actions not being able to merge PRs
# Step 13: Automerge PR
# - name: Enable Automerge PR
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# uses: peter-evans/enable-pull-request-automerge@v3
# with:
# pull-request-number: ${{steps.createpr.outputs.result}}
# merge-method: squash
# Step 14: Generate token for autoapproving PR
# - name: Generate token
# id: generate_token
# uses: chanzuckerberg/[email protected]
# with:
# app_id: ${{ secrets.CZI_GITHUB_HELPER_APP_ID }}
# private_key: ${{ secrets.CZI_GITHUB_HELPER_PK }}
# Step 15: Autoapprove PR
# - name: Autoapprove PR
# run: gh pr review --approve "${{steps.createpr.outputs.result}}"
# env:
# GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
# Job 2
create-version-matrix:
needs: release
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
# Step 1: Check out the repository code
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: prod
# Step 2: Create a matrix of package versions and names
- name: Create Versions Matrix
id: set-matrix
run: |
matrix="["
for package_json in $(find ./packages -name package.json); do
version=$(jq -r .version "$package_json")
name=$(jq -r .name "$package_json")
matrix="${matrix}{\"name\":\"${name}\", \"version\":\"${version}\"},"
done
matrix="${matrix%,}" # Remove trailing comma
matrix="${matrix}]" # Close the JSON array
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
# Job 3
create-github-release:
needs: create-version-matrix
runs-on: ubuntu-latest
strategy:
matrix:
cfg: ${{fromJson(needs.create-version-matrix.outputs.matrix)}}
steps:
# Step 1: Create a GitHub release for the latest version
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: "${{ matrix.cfg.name }}@${{ matrix.cfg.version }}"