-
-
Notifications
You must be signed in to change notification settings - Fork 58
165 lines (128 loc) · 5.27 KB
/
official-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
name: Official release
on:
workflow_dispatch: # Manually on demand
inputs:
versionBump:
description: 'Type of version bump'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
publish-config:
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the history, or this action won't work
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Prepare installation
uses: ./.github/actions/install-redis-linux
- name: Install dependencies
run: npm ci --ignore-scripts # install typescript and @types do not `setup first`
- name: Build TS files
run: npm run build
- name: Build Docs
run: npm run build:doc
- name: Run scripts
run: npm run preinstall && npm run install
- name: Test
run: npm test
- name: Determine the version bump
id: version
uses: actions/github-script@v7
env:
VERSION_BUMP: ${{ inputs.versionBump }}
with:
result-encoding: string
script: |
const semver = require('semver');
const prevVersion = require(`${process.env.GITHUB_WORKSPACE}/lerna.json`).version;
const parsed = semver.parse(prevVersion);
// Figure out the next version
const version = `${semver.inc(parsed, process.env.VERSION_BUMP)}`;
return version;
- name: Prepare io-package.json
env:
VERSION: ${{ steps.version.outputs.result }}
uses: actions/github-script@v7
with:
script: |
const semver = require('semver');
const fs = require('fs-extra');
const MAX_NEWS = 20;
const path = `${process.env.GITHUB_WORKSPACE}/packages/controller/io-package.json`;
const ioPack = require(path);
let news = ioPack.common.news;
const prevNewsVersion = Object.keys(news)[0];
// add new news as first entry
news = { [process.env.VERSION]: Object.values(news)[0], ...news };
const isPatch = semver.satisfies(process.env.VERSION, `~${prevNewsVersion}`);
if (isPatch) {
delete news[prevNewsVersion];
}
// if too much news, remove them
while (Object.keys(news).length > MAX_NEWS) {
const newsVersions = Object.keys(news);
delete news[newsVersions[newsVersions.length - 1]];
}
ioPack.common.news = news;
ioPack.common.version = process.env.VERSION;
fs.writeFileSync(path, JSON.stringify(ioPack, null, 2));
- name: Prepare changelog
env:
VERSION: ${{ steps.version.outputs.result }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs-extra');
const WIP_MARKER = '__WORK IN PROGRESS__';
const TEMP_PLACEHOLDER = '**TEMP_PLACEHOLDER_GH_ACTION**';
const changelog = fs
.readFileSync(`${process.env.GITHUB_WORKSPACE}/CHANGELOG.md`, { encoding: 'utf-8' })
.replace(WIP_MARKER, TEMP_PLACEHOLDER);
if (!changelog.includes(WIP_MARKER)) {
throw new Error(`${WIP_MARKER} is missing in changelog`);
}
const dateStr = new Date().toISOString().split('T')[0];
const versionDateStr = `${process.env.VERSION} (${dateStr})`;
fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/CHANGELOG.md`,
changelog.replace(WIP_MARKER, versionDateStr).replace(TEMP_PLACEHOLDER, WIP_MARKER),
{
encoding: 'utf-8'
}
);
- name: Bump version locally
env:
VERSION: ${{ steps.version.outputs.result }}
run: |
git config --global user.email "moritz.heusinger@gmail.com"
git config --global user.name "Github Action"
git add .
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
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.PR_TOKEN }}
commit-message: "[OFFICIAL RELEASE] ${{ steps.version.outputs.result }}"
committer: foxriver76 <moritz.heusinger@gmail.com>
author: foxriver76 <moritz.heusinger@gmail.com>
signoff: false
branch: official-release
delete-branch: true
title: "[OFFICIAL RELEASE] ${{ steps.version.outputs.result }}"
body: |
Update version by release action
labels: |
automated pr
assignees: foxriver76
draft: false