Skip to content

Commit a858fed

Browse files
committed
fix: optimize github workflows
1 parent 0ed70c1 commit a858fed

3 files changed

Lines changed: 43 additions & 36 deletions

File tree

.github/actions/yarn-cache.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
- name: Get yarn cache
2-
id: yarn-cache-dir-path
3-
run: echo "::set-output name=dir::$(yarn cache dir)"
4-
5-
- name: Cache dependencies
1+
- name: Cache node modules
62
uses: actions/cache@v2
7-
# use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
8-
id: yarn-cache
3+
env:
4+
cache-name: cache-node-modules
95
with:
10-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
11-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
6+
# yarn cache files are stored in `~/.yarn` on Linux/macOS
7+
path: ~/.yarn
8+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
129
restore-keys: |
13-
${{ runner.os }}-yarn-
10+
${{ runner.os }}-build-${{ env.cache-name }}-
11+
${{ runner.os }}-build-
12+
${{ runner.os }}-

.github/workflows/create-release.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Create Release
22

33
on:
44
push:
5-
branches:
6-
- main
5+
# branches:
6+
# - main
77
# Sequence of patterns matched against refs/tags
88
tags:
99
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
@@ -17,9 +17,11 @@ jobs:
1717
uses: actions/checkout@v2
1818
with:
1919
fetch-depth: 0 # This is important for the Git history
20+
2021
- name: Extract Repo Attributes
2122
id: attrs # This is important for future referencing
2223
uses: ibnesayeed/repo-attrs@master
24+
2325
- name: Create Release
2426
id: create_release
2527
uses: actions/create-release@v1

.github/workflows/npm-publish.yaml

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
name: Node.js Package
1+
name: Publish Package
22

33
on:
44
release:
55
types: [created]
66

77
jobs:
8-
build:
8+
test:
99
name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
1010
runs-on: ${{ matrix.os }}
1111
strategy:
1212
matrix:
1313
node_version: ["8", "10", "12"]
1414
os: [ubuntu-latest, windows-latest, macOS-latest]
15-
env:
16-
OS: ${{ matrix.os }}
17-
NODE: 10
18-
1915
steps:
2016
- name: Checkout code
2117
uses: actions/checkout@v2
2218
with:
2319
fetch-depth: 1
24-
- name: Cache node modules
25-
uses: actions/cache@v2
26-
env:
27-
cache-name: cache-node-modules
28-
with:
29-
# yarn cache files are stored in `~/.yarn` on Linux/macOS
30-
path: ~/.yarn
31-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-build-${{ env.cache-name }}-
34-
${{ runner.os }}-build-
35-
${{ runner.os }}-
3620

3721
- name: Use Node.js ${{ matrix.node_version }}
3822
uses: actions/setup-node@v1
3923
with:
4024
node-version: ${{ matrix.node_version }}
41-
- name: Npm install, build, and test
25+
26+
- name: Npm install, build and test
4227
run: |
4328
yarn install
4429
yarn build
4530
yarn test
46-
- name: Use Node.js ${{ jobs.build.env.NODE }} coverage
47-
uses: actions/setup-node@v1
31+
32+
coverage:
33+
needs: test
34+
name: Generate coverage
35+
runs-on: ubuntu-latest
36+
env:
37+
OS: ${{ runner.os }}
38+
NODE: 10
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v2
4842
with:
49-
node-version: ${{ jobs.build.env.NODE }}
43+
fetch-depth: 1
44+
45+
- uses: actions/setup-node@v1
46+
with:
47+
node-version: ${{ jobs.coverage.env.NODE }}
48+
5049
- name: Npm install, build, and coverage
5150
run: |
5251
yarn install
5352
yarn build
5453
yarn coverage
54+
5555
- name: Upload coverage to Codecov
5656
uses: codecov/codecov-action@v1
5757
with:
@@ -66,13 +66,14 @@ jobs:
6666
path_to_write_report: ./coverage/codecov_report.gz
6767

6868
publish:
69-
needs: build
69+
needs: coverage
7070
runs-on: ubuntu-latest
7171
steps:
7272
- name: Checkout code
7373
uses: actions/checkout@v2
7474
with:
7575
fetch-depth: 1
76+
7677
- name: Cache node modules
7778
uses: actions/cache@v2
7879
env:
@@ -88,19 +89,24 @@ jobs:
8889
8990
- uses: actions/setup-node@v1
9091
with:
91-
node-version: 12
92+
node-version: ${{ jobs.build.env.NODE }}
9293
registry-url: https://registry.npmjs.org/
94+
9395
- name: Npm install, and build
9496
run: |
9597
yarn install
9698
yarn build
99+
97100
- name: Publish to npm
98101
run: yarn publish
99102
env:
100103
NODE_AUTH_TOKEN: ${{secrets.NPMJS_TOKEN}}
104+
101105
- uses: actions/setup-node@v1
102106
with:
107+
node-version: ${{ jobs.build.env.NODE }}
103108
registry-url: https://npm.pkg.github.com/
109+
104110
- name: Publish to github package
105111
run: yarn publish
106112
env:

0 commit comments

Comments
 (0)