1
+ name : Official release
2
+
3
+ on :
4
+ workflow_dispatch : # Manually on demand
5
+ inputs :
6
+ versionBump :
7
+ description : ' Type of version bump'
8
+ required : true
9
+ default : ' patch'
10
+ type : choice
11
+ options :
12
+ - patch
13
+ - minor
14
+ - major
15
+
16
+ jobs :
17
+ publish-config :
18
+ runs-on : ubuntu-20.04
19
+
20
+ strategy :
21
+ matrix :
22
+ node : [16.x] # This should be LTS
23
+
24
+ steps :
25
+ - name : Checkout code
26
+ uses : actions/checkout@v3
27
+ with :
28
+ fetch-depth : 0 # Fetch the history, or this action won't work
29
+
30
+ - name : Use Node.js ${{ matrix.node }}
31
+ uses : actions/setup-node@v3
32
+ with :
33
+ node-version : ${{ matrix.node }}
34
+
35
+ - name : Prepare installation
36
+ run : |
37
+ sudo add-apt-repository ppa:chris-lea/redis-server -y
38
+ sudo apt-get update -q
39
+ sudo apt-get install redis-server redis-sentinel -y
40
+ sudo systemctl start redis-server
41
+
42
+ - name : Install dependencies
43
+ run : npm ci --ignore-scripts # install typescript and @types do not `setup first`
44
+
45
+ - name : Build TS files
46
+ run : npm run build
47
+
48
+ - name : Build Docs
49
+ run : npm run build:doc
50
+
51
+ - name : Run scripts
52
+ run : npm run preinstall && npm run install
53
+
54
+ - name : Test
55
+ if : steps.changes.outputs.result == 'ok'
56
+ run : npm test
57
+
58
+ - name : Determine the version bump
59
+ id : version
60
+ uses : actions/github-script@v6
61
+ env :
62
+ VERSION_BUMP : ${{ inputs.versionBump }}
63
+ with :
64
+ result-encoding : string
65
+ script : |
66
+ const semver = require('semver');
67
+
68
+ const prevVersion = require(`${process.env.GITHUB_WORKSPACE}/lerna.json`).version;
69
+
70
+ const parsed = semver.parse(prevVersion);
71
+
72
+ // Figure out the next version
73
+ const version = `${semver.inc(parsed, process.env.VERSION_BUMP)}`;
74
+
75
+ return version;
76
+
77
+ - name : Prepare io-package.json
78
+ env :
79
+ VERSION : ${{ steps.version.outputs.result }}
80
+ uses : actions/github-script@v6
81
+ with :
82
+ script : |
83
+ const semver = require('semver');
84
+ const fs = require('fs-extra');
85
+
86
+ const MAX_NEWS = 20;
87
+ const path = `${process.env.GITHUB_WORKSPACE}/packages/controller/io-package.json`;
88
+
89
+ const ioPack = require(path);
90
+
91
+ let news = ioPack.common.news;
92
+
93
+ const prevNewsVersion = Object.keys(news)[0];
94
+
95
+ // add new news as first entry
96
+ news = { [process.env.VERSION]: Object.values(news)[0], ...news };
97
+
98
+ const isPatch = semver.satisfies(process.env.VERSION, `~${prevNewsVersion}`);
99
+
100
+ if (isPatch) {
101
+ delete news[prevNewsVersion];
102
+ }
103
+
104
+ // if too much news, remove them
105
+ while (Object.keys(news).length > MAX_NEWS) {
106
+ const newsVersions = Object.keys(news);
107
+ delete news[newsVersions[newsVersions.length - 1]];
108
+ }
109
+
110
+ ioPack.common.news = news;
111
+ ioPack.common.version = process.env.VERSION;
112
+
113
+ fs.writeFileSync(path, JSON.stringify(ioPack, null, 2));
114
+
115
+
116
+ - name : Prepare changelog
117
+ env :
118
+ VERSION : ${{ steps.version.outputs.result }}
119
+ uses : actions/github-script@v6
120
+ with :
121
+ script : |
122
+ const fs = require('fs-extra');
123
+
124
+ const WIP_MARKER = '__WORK IN PROGRESS__';
125
+
126
+ const TEMP_PLACEHOLDER = '**TEMP_PLACEHOLDER_GH_ACTION**';
127
+ const changelog = fs
128
+ .readFileSync(`${process.env.GITHUB_WORKSPACE}/CHANGELOG.md`, { encoding: 'utf-8' })
129
+ .replace(WIP_MARKER, TEMP_PLACEHOLDER);
130
+
131
+ if (!changelog.includes(WIP_MARKER)) {
132
+ throw new Error(`${WIP_MARKER} is missing in changelog`);
133
+ }
134
+
135
+ const dateStr = new Date().toISOString().split('T')[0];
136
+
137
+ const versionDateStr = `${process.env.VERSION} (${dateStr})`;
138
+
139
+ fs.writeFileSync(
140
+ `${process.env.GITHUB_WORKSPACE}/CHANGELOG.md`,
141
+ changelog.replace(WIP_MARKER, versionDateStr).replace(TEMP_PLACEHOLDER, WIP_MARKER),
142
+ {
143
+ encoding: 'utf-8'
144
+ }
145
+ );
146
+
147
+ - name : Bump version locally
148
+ env :
149
+ VERSION : ${{ steps.version.outputs.result }}
150
+ run : |
151
+ git config --global user.email "[email protected] "
152
+ git config --global user.name "Github Action"
153
+
154
+ git add .
155
+ git commit -m "v${VERSION}" && npx lerna version ${VERSION} --no-push --exact --ignore-scripts --no-commit-hooks --yes --amend --force-publish || npx lerna version ${VERSION} --exact --no-push --ignore-scripts --no-commit-hooks --yes --force-publish
156
+
157
+ - name : Create Pull Request
158
+ id : cpr
159
+ uses : peter-evans/create-pull-request@v5
160
+ with :
161
+ token : ${{ secrets.PR_TOKEN }}
162
+ commit-message : " [OFFICIAL RELEASE] ${{ steps.version.outputs.result }}"
163
+ committer :
foxriver76 <[email protected] >
164
+ author :
foxriver76 <[email protected] >
165
+ signoff : false
166
+ branch : official-release
167
+ delete-branch : true
168
+ title : " [OFFICIAL RELEASE] ${{ steps.version.outputs.result }}"
169
+ body : |
170
+ Update version by release action
171
+ labels : |
172
+ automated pr
173
+ assignees : foxriver76
174
+ draft : false
0 commit comments