Skip to content

Commit

Permalink
conditional ci, publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Feb 15, 2024
1 parent 97b635b commit 1338522
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 79 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/compile-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ name: Compile WASM
on: [workflow_call, workflow_dispatch]

jobs:
compile-wasm:
wasm:
runs-on: buildjet-16vcpu-ubuntu-2204 # buildjet for rust, github standard for everything else
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3 # turbo cache, shared between buildjet and github
id: turbo-cache
- id: compiled
uses: actions/cache@v3 # turbo cache, shared between buildjet and github
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-compiled
restore-keys: |
${{ runner.os }}-turbo-
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}
- uses: pnpm/action-setup@v2
- uses: buildjet/setup-node@v4 # node cache, distinct between buildjet and github
with:
Expand Down
28 changes: 19 additions & 9 deletions .github/workflows/extension-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,34 @@ on:
workflow_dispatch:

jobs:
compile:
uses: ./.github/workflows/compile-wasm.yml

publish:
name: Publish chrome extension
environment: ext-publish
runs-on: ubuntu-latest
needs: compile

steps:
- name: Checkout sources
uses: actions/checkout@v3

- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-publish
restore-keys: |
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-compiled
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
version: 8
node-version: '21'
cache: 'pnpm'

- run: pnpm install --frozen-lockfile

- name: Install dependencies
run: pnpm install
- run: pnpm turbo telemetry disable

- name: Build monorepo
run: pnpm build
- run: pnpm turbo download-keys --force --cache-dir=.turbo
- run: pnpm turbo build --cache-dir=.turbo

- name: Package up extension
run: zip -r dist.zip apps/extension/dist
Expand Down
38 changes: 0 additions & 38 deletions .github/workflows/test-wasm.yml

This file was deleted.

103 changes: 76 additions & 27 deletions .github/workflows/turbo-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,68 @@ on: [pull_request, workflow_dispatch]
# pnpm deps are cached by lockfile hash

jobs:
wasm-diff:
check-diff:
outputs:
wasm-diff: ${{ steps.diff.outputs.exit_code }}
wasm-diff-main: ${{ steps.run-wasm-diff-main.outcome }}
wasm-diff-prev: ${{ steps.run-wasm-diff-prev.outcome }}
name: Diff
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' # only run on PRs
steps:
- uses: actions/checkout@v4
- id: diff # store diff exit code in output
run: git diff --exit-code main packages/wasm/crate
- run: git fetch origin main:main
- run: git fetch origin ${{ github.head_ref }}:${{ github.head_ref }}
- id: run-wasm-diff-main
run: git diff main --exit-code packages/wasm/crate
continue-on-error: true
- id: run-wasm-diff-prev
run: git diff ${{ github.head_ref }} --exit-code packages/wasm/crate
continue-on-error: true

turbo-compile:
name: Compile
needs: wasm-diff
# only run if wasm crate changed, or dispatch
if: github.workflow_dispatch || needs.wasm-diff.outputs.wasm-diff == '1'
needs: check-diff
# only run if wasm crate changed, rerun was requested, or manually dispatched
if: github.event_name == 'workflow_dispatch' || needs.check-diff.outputs.wasm-diff-main == 'failure'|| needs.check-diff.outputs.wasm-diff-prev == 'failure' || github.run_attempt > 1
uses: ./.github/workflows/compile-wasm.yml

test-rust:
name: test:rust
needs: turbo-compile
uses: ./.github/workflows/test-wasm.yml
turbo-test-rust:
name: 'test:rust'
runs-on: buildjet-16vcpu-ubuntu-2204 # buildjet for rust, github standard for everything else
needs: [turbo-compile, turbo-build]
steps:
- uses: actions/checkout@v4
- id: compiled # this also compiles, so we can use or write the same cache
uses: actions/cache@v3 # turbo cache, shared between buildjet and github
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-test:rust
restore-keys: |
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-built
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}
- uses: pnpm/action-setup@v2
- uses: buildjet/setup-node@v4 # node cache, distinct between buildjet and github
with:
node-version: '21'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile # commit your lockfile
- run: pnpm turbo telemetry disable

- uses: dtolnay/rust-toolchain@stable # rust only on buildjet
with:
targets: wasm32-unknown-unknown
- uses: astriaorg/[email protected] # buildjet rust cache
- uses: jetli/[email protected] # preinstall wasm-pack
with:
version: 'latest'
- uses: browser-actions/setup-firefox@v1 # wasm tests in ffx

- run: pnpm turbo test:rust --cache-dir=.turbo # test wasm

- run: cargo tree --invert mio --edges features # debug tree
if: failure()
working-directory: packages/wasm/crate

turbo-lint:
name: Lint
Expand All @@ -40,13 +79,16 @@ jobs:
if: always() # always run even if we skip compile
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3 # turbo cache, shared between buildjet and github
id: turbo-cache
- id: lint
uses: actions/cache@v3 # turbo cache, shared between buildjet and github
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-lint
restore-keys: |
${{ runner.os }}-turbo-
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-compiled
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4 # node cache, distinct between buildjet and github
with:
Expand All @@ -64,13 +106,16 @@ jobs:
if: always() # always run even if we skip compile
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
id: turbo-cache
- id: built
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-built
restore-keys: |
${{ runner.os }}-turbo-
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-compiled
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
Expand All @@ -83,25 +128,29 @@ jobs:
turbo-test:
strategy:
matrix:
task: ['test', 'test:browser'] # all typescript tests
name: ${{ matrix.task }}
test: ['test', 'test:browser'] # all typescript tests
name: ${{ matrix.test }}
runs-on: ubuntu-latest
needs: turbo-build
if: always() # always run even if we skip compile
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
id: turbo-cache
- id: tested
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
key: ${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-${{ matrix.test }}
restore-keys: |
${{ runner.os }}-turbo-
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-built
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}-compiled
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}-${{ github.sha }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}-${{ github.ref }}
${{ runner.os }}-turbo-${{ hashFiles('packages/wasm/cargo/src/**') }}
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v4
with:
node-version: '21'
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm turbo telemetry disable
- run: pnpm turbo ${{ matrix.task }} --cache-dir=.turbo
- run: pnpm turbo ${{ matrix.test }} --cache-dir=.turbo

0 comments on commit 1338522

Please sign in to comment.