Skip to content

Commit 559e74d

Browse files
committed
ci: make build a reusable workflow
1 parent 653a869 commit 559e74d

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

.github/workflows/browserstack.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
PR: ${{ github.event.number }}
2525
REPO: ${{ github.event.repository.full_name }}
2626

27+
build:
28+
uses: ./.github/workflows/build.yml
29+
2730
cert:
2831
if: ${{ !startsWith(github.event_name, 'pull_request') || (github.event_name == 'pull_request_target' && github.event.label.name == 'trigger-browserstack') }}
2932
uses: panva/.github/.github/workflows/cert-for-browserstack.yml@main
@@ -35,6 +38,7 @@ jobs:
3538

3639
browserstack:
3740
needs:
41+
- build
3842
- cert
3943
if: ${{ !startsWith(github.event_name, 'pull_request') || (github.event_name == 'pull_request_target' && github.event.label.name == 'trigger-browserstack') }}
4044
runs-on: ubuntu-latest
@@ -65,7 +69,13 @@ jobs:
6569
cache: 'npm'
6670
- run: npm clean-install
6771
- run: npm install --global testcafe@2 testcafe-browser-provider-browserstack@1
68-
- run: npm run build:browser
72+
- name: Load cached dist
73+
uses: actions/cache@v3
74+
id: dist
75+
with:
76+
path: dist
77+
key: ${{ needs.build.outputs.cache-key }}
78+
fail-on-cache-miss: true
6979
- name: BrowserStack Env Setup
7080
uses: browserstack/github-actions/setup-env@eede0bfff248c2bea3f4039fea92e2416ce9898d
7181
with:

.github/workflows/build.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
cache-key:
7+
value: ${{ jobs.build.outputs.cache-key }}
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
cache-key: ${{ steps.cache-key.outputs.value }}
14+
steps:
15+
- name: Environment Information
16+
run: npx envinfo
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Setup node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: lts/hydrogen # 18
23+
cache: 'npm'
24+
- run: npm clean-install
25+
- id: cache-key
26+
run: echo "value=dist-${{ hashFiles('src/**/*.ts', 'tsconfig/*.json', '.github/workflows/*.yml', 'package-lock.json') }}" >> $GITHUB_OUTPUT
27+
- name: Cache dist
28+
uses: actions/cache@v3
29+
id: dist
30+
with:
31+
path: dist
32+
key: ${{ steps.cache-key.outputs.value }}
33+
- name: Build
34+
run: npm run build-all
35+
if: ${{ steps.dist.outputs.cache-hit != 'true' }}
36+
- uses: actions/upload-artifact@v3
37+
with:
38+
name: dist
39+
path: dist
40+
- run: git reset HEAD --hard

.github/workflows/test.yml

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,7 @@ on:
1212

1313
jobs:
1414
build:
15-
runs-on: ubuntu-latest
16-
outputs:
17-
cache-key: ${{ steps.cache-key.outputs.value }}
18-
steps:
19-
- name: Environment Information
20-
run: npx envinfo
21-
- name: Checkout
22-
uses: actions/checkout@v3
23-
- name: Setup node
24-
uses: actions/setup-node@v3
25-
with:
26-
node-version: lts/hydrogen # 18
27-
cache: 'npm'
28-
- run: npm clean-install
29-
- id: cache-key
30-
run: echo "value=dist-${{ hashFiles('src/**/*.ts', 'tsconfig/*.json', '.github/workflows/*.yml', 'package-lock.json') }}" >> $GITHUB_OUTPUT
31-
- name: Cache dist
32-
uses: actions/cache@v3
33-
id: dist
34-
with:
35-
path: dist
36-
key: ${{ steps.cache-key.outputs.value }}
37-
- name: Build
38-
run: npm run build-all
39-
if: ${{ steps.dist.outputs.cache-hit != 'true' }}
40-
- uses: actions/upload-artifact@v3
41-
with:
42-
name: dist
43-
path: dist
44-
- run: git reset HEAD --hard
15+
uses: ./.github/workflows/build.yml
4516

4617
typings:
4718
needs:

0 commit comments

Comments
 (0)