-
-
Notifications
You must be signed in to change notification settings - Fork 58
144 lines (120 loc) · 5.08 KB
/
nightly-dev-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
name: Publish nightly dev releases
on:
schedule:
- cron: 0 2 * * * # Every day at 02:00
workflow_dispatch: # Manually on demand
jobs:
publish-config:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [16.x] # This should be LTS
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch the history, or this action won't work
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Detect changes (git)
id: changes
run: |
# ===============================
# Detect changes using git
# ===============================
LAST_TAG=$(git describe --abbrev=0 --tags)
echo "Checking for changes since last tag $LAST_TAG"
# Figure out if anything changed in the package directories
CHANGES=$(git diff "$LAST_TAG" --name-only | grep -E "^packages\/" | grep -vE "^packages\/controller\/doc\/" || true)
if [ -z "$CHANGES" ] ; then
echo "🔸 No package changes since latest version, aborting..."
echo "::set-output name=result::unchanged"
else
echo "::set-output name=result::ok"
fi
- name: Prepare installation
if: steps.changes.outputs.result == 'ok'
run: |
sudo add-apt-repository ppa:chris-lea/redis-server -y
sudo apt-get update -q
sudo apt-get install redis-server redis-sentinel -y
sudo systemctl start redis-server
- name: Install dependencies
if: steps.changes.outputs.result == 'ok'
run: npm ci --ignore-scripts # install typescript and @types do not `setup first`
- name: Build TS files
if: steps.changes.outputs.result == 'ok'
run: npm run build
- name: Build Docs
if: steps.changes.outputs.result == 'ok'
run: npm run build:doc
- name: Run scripts
if: steps.changes.outputs.result == 'ok'
run: npm run preinstall && npm run install
- name: Test
if: steps.changes.outputs.result == 'ok'
run: npm test
- name: Determine the version bump
if: steps.changes.outputs.result == 'ok'
id: version
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const semver = require("semver");
const now = new Date();
const today = new Date(now.getTime() - now.getTimezoneOffset()*60000);
const dateStr = today.toISOString().split("T")[0].replace(/-/g, "");
const sha = require("child_process").execSync("git rev-parse --short HEAD").toString("utf8").trim();
const prevVersion = require(`${process.env.GITHUB_WORKSPACE}/lerna.json`).version;
const parsed = semver.parse(prevVersion);
const prereleaseIdentifier = parsed.prerelease[0] || "alpha";
for (let i = 1; i < parsed.prerelease.length; i++) {
const part = parsed.prerelease[i];
if (typeof part === "number") {
continue;
}
// Parse stuff like `8-20210909-001a711c` back to `8`
const numeric = parseInt(part);
if (!Number.isNaN(numeric)) {
parsed.prerelease[i] = numeric;
}
}
// Figure out the next version
const nightlyVersion = `${semver.inc(parsed, "prerelease", prereleaseIdentifier)}-${dateStr}-${sha}`;
// ensure that io-pack is in sync
const fs = require('fs');
const ioPack = JSON.parse(fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/packages/controller/io-package.json`));
ioPack.common.version = semver.inc(nightlyVersion, 'patch');;
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/packages/controller/io-package.json`, JSON.stringify(ioPack, null, 2));
return nightlyVersion;
- name: Bump version locally
if: steps.changes.outputs.result == 'ok'
env:
VERSION: ${{ steps.version.outputs.result }}
run: |
git config --global user.email "[email protected]"
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
if: steps.changes.outputs.result == 'ok'
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.PR_TOKEN }}
commit-message: "[NIGHTLY DEV RELEASE] ${{ steps.version.outputs.result }}"
committer: foxriver76 <[email protected]>
author: foxriver76 <[email protected]>
signoff: false
branch: nightly-release
delete-branch: true
title: "[NIGHTLY DEV RELEASE] ${{ steps.version.outputs.result }}"
body: |
Update version by nightly dev release
labels: |
automated pr
assignees: foxriver76
draft: false