Skip to content

Commit 82d63f2

Browse files
authored
Provide a github action for automatic releases (#2320)
* prepare pr action * try to use the release script * fix comment * skip tests test wise * prepare changelog * release script will bump version * fix * try it without release script * remove testing code * make it working for minor,. major too and adapt merge process * rename * bring back tests and pr token usage * release script manual plugin back to patch range * adapt description
1 parent cb37f86 commit 82d63f2

File tree

6 files changed

+246
-118
lines changed

6 files changed

+246
-118
lines changed

.github/workflows/ci-tests.yml

+11-86
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,18 @@ jobs:
154154
- name: Publish npm
155155
if: steps.automerge.outputs.mergeResult == 'merged'
156156
env:
157-
VERSION: ${{ steps.version.outputs.result }}
157+
PRERELEASE: ${{ contains(steps.version.outputs.result, '-') }}
158158
run: |
159159
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
160160
npm whoami
161161
162-
npx lerna publish from-package --yes --dist-tag dev
162+
if [[ "$PRERELEASE" == "true" ]]; then
163+
npx lerna publish from-package --yes --dist-tag dev
164+
else
165+
npx lerna publish from-package --yes
166+
fi
163167
164-
- name: Create Github Release for Nightly
168+
- name: Create Github Release
165169
if: steps.automerge.outputs.mergeResult == 'merged'
166170
uses: ncipollo/release-action@v1
167171
env:
@@ -170,10 +174,10 @@ jobs:
170174
tag: v${{ steps.version.outputs.result }}
171175
name: Release v${{ steps.version.outputs.result }}
172176
draft: false
173-
prerelease: true
174-
body: 'nightly release'
177+
prerelease: $PRERELEASE
178+
body: "${{ contains(steps.version.outputs.result, '-') && 'nightly release' || 'official release' }}"
175179

176-
- name: Notify Sentry.io about the Nightly release
180+
- name: Notify Sentry.io about the release
177181
if: steps.automerge.outputs.mergeResult == 'merged'
178182
env:
179183
VERSION: ${{ steps.version.outputs.result }}
@@ -186,83 +190,4 @@ jobs:
186190
export SENTRY_VERSION=iobroker.js-controller@${VERSION}
187191
sentry-cli releases new $SENTRY_VERSION
188192
sentry-cli releases set-commits $SENTRY_VERSION --auto
189-
sentry-cli releases finalize $SENTRY_VERSION
190-
191-
# Deploys the final package to NPM when a versioned tag was pushed
192-
deploy:
193-
needs: [ci]
194-
195-
# Trigger this step only when a commit on any branch is tagged with a version number
196-
if: |
197-
contains(github.event.head_commit.message, '[skip ci]') == false &&
198-
github.event_name == 'push' &&
199-
startsWith(github.ref, 'refs/tags/v')
200-
201-
runs-on: ubuntu-20.04
202-
strategy:
203-
matrix:
204-
node-version: [16]
205-
206-
steps:
207-
- name: Checkout code
208-
uses: actions/checkout@v3
209-
210-
- name: Use Node.js ${{ matrix.node }}
211-
uses: actions/setup-node@v3
212-
with:
213-
node-version: ${{ matrix.node }}
214-
215-
- name: Extract the version and commit body from the tag
216-
id: extract_release
217-
# The body may be multiline, therefore newlines and % need to be escaped
218-
run: |
219-
VERSION="${{ github.ref }}"
220-
VERSION=${VERSION##*/v}
221-
echo "::set-output name=VERSION::$VERSION"
222-
BODY=$(git show -s --format=%b)
223-
BODY="${BODY//'%'/'%25'}"
224-
BODY="${BODY//$'\n'/'%0A'}"
225-
BODY="${BODY//$'\r'/'%0D'}"
226-
echo "::set-output name=BODY::$BODY"
227-
228-
- name: Install dependencies
229-
run: npm ci --ignore-scripts # install typescript and @types do not `setup first`
230-
231-
- name: Build TS files
232-
run: npm run build
233-
234-
- name: Publish package to npm
235-
env:
236-
PRERELEASE: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
237-
run: |
238-
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
239-
npm whoami
240-
if [[ "$PRERELEASE" == "true" ]]; then
241-
npx lerna publish from-package --yes next
242-
else
243-
npx lerna publish from-package --yes
244-
fi
245-
246-
- name: Create Github Release
247-
uses: actions/create-release@v1
248-
env:
249-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
250-
with:
251-
tag_name: ${{ github.ref }}
252-
release_name: Release v${{ steps.extract_release.outputs.VERSION }}
253-
draft: false
254-
# Prerelease versions create prereleases on GitHub
255-
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
256-
body: ${{ steps.extract_release.outputs.BODY }}
257-
258-
- name: Notify Sentry.io about the release
259-
run: |
260-
npm i -g @sentry/cli
261-
export SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
262-
export SENTRY_URL=https://sentry.iobroker.net
263-
export SENTRY_ORG=iobroker
264-
export SENTRY_PROJECT=iobroker-js-controller
265-
export SENTRY_VERSION=iobroker.js-controller@${{ steps.extract_release.outputs.VERSION }}
266-
sentry-cli releases new $SENTRY_VERSION
267-
sentry-cli releases set-commits $SENTRY_VERSION --auto
268-
sentry-cli releases finalize $SENTRY_VERSION
193+
sentry-cli releases finalize $SENTRY_VERSION
+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Placeholder for the next version (at the beginning of the line):
44
## __WORK IN PROGRESS__
55
-->
6-
## 5.0.5 (2023-06-18) - Jana
6+
## __WORK IN PROGRESS__ - Jana
77
**BREAKING CHANGES**
88
* Support for Node.js 12 is dropped! Supported are Node.js 14.18.0+, 16.4.0+ and 18.x
99
* Backups created with the new js-controller version cannot be restored on hosts with lower js-controller version!

0 commit comments

Comments
 (0)