Skip to content

Commit

Permalink
ci: make build a reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Feb 28, 2023
1 parent 653a869 commit 559e74d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
PR: ${{ github.event.number }}
REPO: ${{ github.event.repository.full_name }}

build:
uses: ./.github/workflows/build.yml

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

browserstack:
needs:
- build
- cert
if: ${{ !startsWith(github.event_name, 'pull_request') || (github.event_name == 'pull_request_target' && github.event.label.name == 'trigger-browserstack') }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -65,7 +69,13 @@ jobs:
cache: 'npm'
- run: npm clean-install
- run: npm install --global testcafe@2 testcafe-browser-provider-browserstack@1
- run: npm run build:browser
- name: Load cached dist
uses: actions/cache@v3
id: dist
with:
path: dist
key: ${{ needs.build.outputs.cache-key }}
fail-on-cache-miss: true
- name: BrowserStack Env Setup
uses: browserstack/github-actions/setup-env@eede0bfff248c2bea3f4039fea92e2416ce9898d
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build

on:
workflow_call:
outputs:
cache-key:
value: ${{ jobs.build.outputs.cache-key }}

jobs:
build:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-key.outputs.value }}
steps:
- name: Environment Information
run: npx envinfo
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: lts/hydrogen # 18
cache: 'npm'
- run: npm clean-install
- id: cache-key
run: echo "value=dist-${{ hashFiles('src/**/*.ts', 'tsconfig/*.json', '.github/workflows/*.yml', 'package-lock.json') }}" >> $GITHUB_OUTPUT
- name: Cache dist
uses: actions/cache@v3
id: dist
with:
path: dist
key: ${{ steps.cache-key.outputs.value }}
- name: Build
run: npm run build-all
if: ${{ steps.dist.outputs.cache-hit != 'true' }}
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- run: git reset HEAD --hard
31 changes: 1 addition & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-key.outputs.value }}
steps:
- name: Environment Information
run: npx envinfo
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: lts/hydrogen # 18
cache: 'npm'
- run: npm clean-install
- id: cache-key
run: echo "value=dist-${{ hashFiles('src/**/*.ts', 'tsconfig/*.json', '.github/workflows/*.yml', 'package-lock.json') }}" >> $GITHUB_OUTPUT
- name: Cache dist
uses: actions/cache@v3
id: dist
with:
path: dist
key: ${{ steps.cache-key.outputs.value }}
- name: Build
run: npm run build-all
if: ${{ steps.dist.outputs.cache-hit != 'true' }}
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- run: git reset HEAD --hard
uses: ./.github/workflows/build.yml

typings:
needs:
Expand Down

0 comments on commit 559e74d

Please sign in to comment.