Skip to content

Commit 29199a3

Browse files
committed
chore(build) detect prereleases in publish workflow
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 1e9cf11 commit 29199a3

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ jobs:
8080
npm install lerna@^3.22.0
8181
./node_modules/.bin/lerna bootstrap 2>&1
8282
83-
- name: Create tag with timestamp
84-
id: tag
83+
- name: timestamp
84+
id: timestamp
8585
run: |
86-
node ./scripts/tag.js
86+
node ./scripts/timestamp.js
8787
8888
- name: build and publish
8989
run: |
9090
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
91-
npm version --no-git-tag-version --yes --exact ${{ steps.tag.outputs.stamp }}
92-
./node_modules/.bin/lerna version --no-git-tag-version --yes --exact ${{ steps.tag.outputs.stamp }}
91+
npm version --no-git-tag-version --yes --exact ${{ steps.timestamp.outputs.stamp }}
92+
./node_modules/.bin/lerna version --no-git-tag-version --yes --exact ${{ steps.timestamp.outputs.stamp }}
9393
./node_modules/.bin/lerna exec -- npm publish --access public --tag=unstable 2>&1
9494
rm ~/.npmrc

.github/workflows/publish.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,28 @@ jobs:
2323
npm install lerna@^3.22.0
2424
./node_modules/.bin/lerna bootstrap 2>&1
2525
26+
- name: tag
27+
id: tag
28+
run: |
29+
node ./scripts/tag.js ${{ github.event.release.tag_name }}
30+
2631
- name: build and publish
2732
run: |
2833
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
2934
npm version --no-git-tag-version --yes --exact ${{ github.event.release.tag_name }}
3035
./node_modules/.bin/lerna version --no-git-tag-version --yes --exact ${{ github.event.release.tag_name }}
31-
./node_modules/.bin/lerna exec -- npm publish --access public 2>&1
36+
echo "./node_modules/.bin/lerna exec -- npm publish --access public ${{ steps.tag.outputs.tag }} 2>&1"
3237
rm ~/.npmrc
3338
3439
- name: Create Pull Request
35-
id: cpr
3640
uses: peter-evans/create-pull-request@v3
3741
with:
3842
base: master
3943
commit-message: 'chore(actions): publish ${{ github.event.release.tag_name }} to npm'
4044
committer: GitHub <[email protected]>
4145
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
4246
signoff: false
43-
branch: clausehq-publish-${{ github.event.release.tag_name }}
47+
branch: ap-publish-${{ github.event.release.tag_name }}
4448
delete-branch: true
4549
title: 'chore(actions): publish ${{ github.event.release.tag_name }} to npm'
4650
body: |

scripts/tag.js

100644100755
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515

1616
'use strict';
1717

18-
const path = require('path');
1918
const semver = require('semver');
20-
const dayjs = require('dayjs');
21-
const utc = require('dayjs/plugin/utc');
22-
dayjs.extend(utc);
19+
const targetVersion = process.argv[2];
2320

24-
const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');
21+
if (!semver.valid(targetVersion)) {
22+
console.error(`Error: the version "${targetVersion}" is invalid!`);
23+
process.exit(1);
24+
}
2525

26-
const lernaDirectory = path.resolve('.');
27-
const lernaConfigFile = path.resolve(lernaDirectory, 'lerna.json');
28-
const lernaConfig = require(lernaConfigFile);
29-
lernaConfig.version.replace(/-.*/, '');
30-
const targetVersion = semver.inc(lernaConfig.version, 'patch') + '-' + timestamp;
31-
console.log(`::set-output name=stamp::${targetVersion}`);
26+
const prerelease = semver.prerelease(targetVersion);
27+
const tag = prerelease ? 'unstable' : 'stable';
28+
29+
console.log(`::set-output name=tag::--tag=${tag}`);

scripts/timestamp.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const path = require('path');
19+
const semver = require('semver');
20+
const dayjs = require('dayjs');
21+
const utc = require('dayjs/plugin/utc');
22+
dayjs.extend(utc);
23+
24+
const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');
25+
26+
const lernaDirectory = path.resolve('.');
27+
const lernaConfigFile = path.resolve(lernaDirectory, 'lerna.json');
28+
const lernaConfig = require(lernaConfigFile);
29+
lernaConfig.version.replace(/-.*/, '');
30+
const targetVersion = semver.inc(lernaConfig.version, 'patch') + '-' + timestamp;
31+
console.log(`::set-output name=stamp::${targetVersion}`);

0 commit comments

Comments
 (0)