Skip to content

Commit ec816c2

Browse files
authored
Merge pull request #3 from hankei6km/topic/test-release-event
Change workflow
2 parents d8b4acf + bb112eb commit ec816c2

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

.github/workflows/npm_pkg.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,49 @@
22
name: Node.js Package
33
on:
44
release:
5-
types: [created]
5+
# draft から publish への対応でサンプルの created から変更
6+
types: [published]
67
jobs:
78
build:
89
runs-on: ubuntu-latest
910
environment: npm_pkg
11+
1012
steps:
1113
- uses: actions/checkout@v2
14+
1215
# npm に公開するように .npmrc ファイルを設定する
1316
- uses: actions/setup-node@v2
1417
with:
1518
node-version: '14.x'
1619
registry-url: 'https://registry.npmjs.org'
17-
- run: npm install
18-
# prepublishOnly を外してここで明示的に buiuld の方が良いか
20+
21+
# https://docs.github.com/ja/free-pro-team@latest/actions/guides/caching-dependencies-to-speed-up-workflows
22+
- name: Cache node modules
23+
uses: actions/cache@v2
24+
env:
25+
cache-name: cache-node-modules
26+
with:
27+
# npm キャッシュファイルは Linux/macOS の「~/.npm」に保存される
28+
path: ~/.npm
29+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
30+
restore-keys: |
31+
${{ runner.os }}-build-${{ env.cache-name }}-
32+
${{ runner.os }}-build-
33+
34+
# https://dev.classmethod.jp/articles/github-actions-npm-automatic-release/
35+
# activity type を published へ変更したので念の為
36+
- name: can-npm-publish
37+
run: npx can-npm-publish
38+
39+
- name: Install modules
40+
run: npm ci
41+
42+
- name: Run tests
43+
run: npm run test
44+
45+
- name: Build
46+
run: npm run build
47+
1948
- run: npm publish
2049
env:
2150
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
name: test
33
on:
44
push:
5-
branches_ignore:
6-
- master
5+
branches:
6+
- '**'
7+
tags:
8+
- '!v*'
79
jobs:
810

911
jest:

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# my-starter-npm-cli-and-lib
22

3-
typescript で npm 用の CLI とライブラリのパッケージを作成するスターター。
3+
TypeScript で npm 用の CLI とライブラリのパッケージを作成するスターター。
4+
CodeSandbox 上でコードを編集し、GitHub Actions から npm レジストリーへ publish することを想定している。
45

56
## 利用方法
67

78
まだ記述の途中。
89

910
1. GitHub から import する(GitHubBox からは https://githubbox.com/hankei6km/my-starter-npm-cli-and-lib)
1011
1. fork
11-
1. `package.json``name` `version` `description` `license``LICENSE` あたりを新しいパッケージにあわせて変更
12-
1. 新しい terminal を開き `$ npm run upgrade-interactive` 等でパッケージを更新
12+
1. `package.json``name` `version` `description` `license``LICENSE` あたりを新しいパッケージにあわせて変更
13+
1. 新しい terminal を開き `$ npm run upgrade-interactive` 等でパッケージを更新
1314

1415
これで 'npm run csb:test'(`jest --watchAll`) が terminal(「yarn start」タブ) 内で実行される。
1516

@@ -21,20 +22,30 @@ typescript で npm 用の CLI とライブラリのパッケージを作成す
2122
- コマンドのフラグ等を変更: `src/main.ts` を編集。
2223
- コマンドの処理を変更: `src/cli.ts` を編集。
2324

24-
### ライブラリ部分の変更
25+
### ライブラリー部分の変更
2526

2627
`src/count.ts` を削除し、ライブラリのコードを記述。エクスポートしたい項目を `src/index.ts` へ記述。
2728

29+
### npm publish
30+
31+
GitHub で Release を Publish するとビルド実行後に `npm pulish` される。
32+
33+
なお、`prepublishOnly` 等は定義されていないので、手動で `npm publish` 等を実行してもビルドはされないので注意。
34+
35+
2836
## 既知の問題
2937

3038
## 参考
3139

3240
- [TypeScript で npm ライブラリ開発ことはじめ - Qiita](https://qiita.com/saltyshiomix/items/d889ba79978dadba63fd)
3341
- [TypeScript で CLI ツールを作って、npm パッケージにする - Qiita](https://qiita.com/suzuki_sh/items/f3349efbfe1bdfc0c634)
3442
- [yarn upgrade-interactive と同じように npm でも対話型な更新をしたい! - Qiita](https://qiita.com/kotarella1110/items/08afeb61d493829711eb)
43+
- [Node.jsパッケージの公開 - GitHub Docs](https://docs.github.com/ja/actions/guides/publishing-nodejs-packages)
44+
- [GitHub Actionsでnpmに自動でリリースするworkflowを作ってみた | DevelopersIO](https://dev.classmethod.jp/articles/github-actions-npm-automatic-release/)
3545

3646
## ライセンス
3747

3848
MIT License
3949

4050
Copyright (c) 2021 hankei6km
51+

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"start:watch": "nodemon --watch src --ext ts --exec ts-node src/main.ts",
1616
"build": "tsc",
1717
"test": "jest",
18-
"prepublishOnly": "npm run build",
1918
"clean": "rm dist/*",
2019
"upgrade-interactive": "npm-check --update",
2120
"csb:test": "npm test -- --watchAll"

0 commit comments

Comments
 (0)