Skip to content

Commit c48f145

Browse files
committed
chore: add github action for release
1 parent 304a238 commit c48f145

File tree

4 files changed

+137
-10
lines changed

4 files changed

+137
-10
lines changed

.github/workflows/release.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Release - cli
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
schedule:
7+
# 08:00am UTC everyday: https://crontab.guru/#0_8_*_*_*
8+
# https://dateful.com/convert/utc?t=8am
9+
- cron: "0 8 * * *"
10+
11+
jobs:
12+
lint-all:
13+
if: |
14+
github.event_name == 'schedule' ||
15+
github.event_name == 'workflow_dispatch' ||
16+
startsWith(github.head_ref, 'release/')
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Use Node.js 16.x
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 16.x
24+
cache: npm
25+
- run: node bin/npm-cli.js run resetdeps
26+
- run: node bin/npm-cli.js run lint-all
27+
28+
smoke-publish:
29+
if: |
30+
github.event_name == 'schedule' ||
31+
github.event_name == 'workflow_dispatch' ||
32+
startsWith(github.head_ref, 'release/')
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
node-version:
37+
- 12.13.0
38+
- 12.x
39+
- 14.15.0
40+
- 14.x
41+
- 16.0.0
42+
- 16.x
43+
platform:
44+
- os: ubuntu-latest
45+
shell: bash
46+
- os: macos-latest
47+
shell: bash
48+
- os: windows-latest
49+
shell: cmd
50+
runs-on: ${{ matrix.platform.os }}
51+
defaults:
52+
run:
53+
shell: ${{ matrix.platform.shell }}
54+
steps:
55+
- uses: actions/checkout@v3
56+
- name: Use Node.js 16.x
57+
uses: actions/setup-node@v3
58+
with:
59+
node-version: 16.x
60+
cache: npm
61+
- name: Pack
62+
run: |
63+
node bin/npm-cli.js run resetdeps
64+
git clean -fd
65+
node bin/npm-cli.js ls --production
66+
node bin/npm-cli.js link -f --ignore-scripts
67+
node bin/npm-cli.js prune --production --no-save --no-audit --no-fund
68+
node bin/npm-cli.js pack
69+
- if: matrix.platform.os == 'windows-latest'
70+
run: for %%i in (*.tgz) DO tar xf %%i
71+
- if: matrix.platform.os != 'windows-latest'
72+
run: tar xf npm-*.tgz
73+
- name: Run smoke tests
74+
env:
75+
SMOKE_TEST_NPM_PACKAGE: package
76+
run: |
77+
node bin/npm-cli.js run resetdeps
78+
node bin/npm-cli.js run smoke-tests
79+
- name: git status
80+
if: matrix.platform.os != 'windows-latest'
81+
run: node scripts/git-dirty.js
82+
83+
test-all:
84+
if: |
85+
github.event_name == 'schedule' ||
86+
github.event_name == 'workflow_dispatch' ||
87+
startsWith(github.head_ref, 'release/')
88+
strategy:
89+
fail-fast: false
90+
matrix:
91+
node-version:
92+
- 12.13.0
93+
- 12.x
94+
- 14.15.0
95+
- 14.x
96+
- 16.0.0
97+
- 16.x
98+
platform:
99+
- os: ubuntu-latest
100+
shell: bash
101+
- os: macos-latest
102+
shell: bash
103+
- os: windows-latest
104+
shell: cmd
105+
runs-on: ${{ matrix.platform.os }}
106+
defaults:
107+
run:
108+
shell: ${{ matrix.platform.shell }}
109+
steps:
110+
- uses: actions/checkout@v3
111+
- name: Use Node.js ${{ matrix.node-version }}
112+
uses: actions/setup-node@v3
113+
with:
114+
node-version: ${{ matrix.node-version }}
115+
cache: npm
116+
- run: node bin/npm-cli.js run resetdeps
117+
- run: node bin/npm-cli.js link -f --ignore-scripts
118+
- run: node bin/npm-cli.js run test-all --ignore-scripts
119+
- name: git status
120+
if: matrix.platform.os != 'windows-latest'
121+
run: node scripts/git-dirty.js

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ docs/content/commands/npm-%.md: docs/bin/config-doc-command.js lib/commands/%.js
7878

7979
freshdocs:
8080
touch lib/utils/config/definitions.js
81-
touch "docs/bin/*.js"
81+
touch docs/bin/*.js
8282
make docs
8383

8484
test: deps
@@ -100,11 +100,10 @@ link: uninstall
100100
node bin/npm-cli.js link -f --ignore-scripts
101101

102102
prune: deps
103-
node bin/npm-cli.js prune --production --no-save --no-audit
104-
@[[ "$(shell git status -s)" != "" ]] && echo "ERR: found unpruned files" && exit 1 || echo "git status is clean"
103+
node bin/npm-cli.js prune --production --no-save --no-audit --no-fund
104+
node scripts/git-dirty.js
105105

106106
publish: gitclean ls-ok link test smoke-tests docs prune
107-
@git push origin :v$(shell node bin/npm-cli.js --no-timing -v) 2>&1 || true
108107
git push origin $(BRANCH) &&\
109108
git push origin --tags &&\
110109
node bin/npm-cli.js publish --tag=$(PUBLISHTAG)

scripts/git-dirty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
const { spawnSync } = require('child_process')
3-
const changes = spawnSync('git', ['status', '--porcelain', '-uno'])
3+
const changes = spawnSync('git', ['status', '--porcelain', '-uall'])
44
const stdout = changes.stdout.toString('utf8')
55
const stderr = changes.stderr.toString('utf8')
66
const { status, signal } = changes

smoke-tests/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ const { join, resolve } = require('path')
55
const t = require('tap')
66
const rimraf = promisify(require('rimraf'))
77

8+
const cwd = process.cwd()
9+
const npmDir = resolve(__dirname, '..', process.env.SMOKE_TEST_NPM_PACKAGE || '')
10+
811
const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/')
9-
const cwd = normalizePath(process.cwd())
12+
1013
t.cleanSnapshot = s =>
1114
s
12-
.split(cwd)
15+
.split(normalizePath(npmDir))
16+
.join('{CWD}')
17+
.split(normalizePath(cwd))
1318
.join('{CWD}')
1419
.split(registry)
1520
.join('https://registry.npmjs.org/')
1621
.split(normalizePath(process.execPath))
1722
.join('node')
18-
.split(process.cwd())
23+
.split(npmDir)
24+
.join('{CWD}')
25+
.split(cwd)
1926
.join('{CWD}')
2027
.replace(/\\+/g, '/')
2128
.replace(/\r\n/g, '\n')
@@ -37,7 +44,7 @@ const path = t.testdir({
3744
})
3845
const localPrefix = resolve(path, 'project')
3946
const userconfigLocation = resolve(path, '.npmrc')
40-
const npmLocation = resolve(__dirname, '../bin/npm-cli.js')
47+
const npmLocation = join(npmDir, 'bin', 'npm-cli.js')
4148
const cacheLocation = resolve(path, 'cache')
4249
const binLocation = resolve(path, 'bin')
4350
const env = {
@@ -55,7 +62,7 @@ const npmOpts = [
5562
const npmBin = `"${process.execPath}" "${npmLocation}" ${npmOpts}`
5663
const exec = async cmd => {
5764
const res = await execAsync(cmd, { cwd: localPrefix, env })
58-
if (res.stderr) {
65+
if (res.stderr && process.env.CI) {
5966
console.error(res.stderr)
6067
}
6168
return String(res.stdout)

0 commit comments

Comments
 (0)