Optimize GitHub Actions workflows

Most notably:

- Stop using unmaintained setup-rust action
- Cache cargo and target directories
- Use sccache (https://github.com/mozilla/sccache/)
This commit is contained in:
Nick Groenen 2023-09-23 13:22:00 +02:00
parent b38e4d53b5
commit c27d7b96b6
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
2 changed files with 143 additions and 66 deletions

View File

@ -1,9 +1,12 @@
name: Create release
on: on:
push: push:
tags: tags:
- "v*" - "v*"
name: Create release env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs: jobs:
create-release: create-release:
@ -28,17 +31,21 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
~/.cargo/registry/cache/
- uses: actions-rs/cargo@v1 ~/.cargo/git/db/
with: target/
command: build key: "cargo-build-linux-${{ steps.setup_rust.outputs.cachekey }}"
args: --release --locked - name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo build --release --locked
- run: strip target/release/obsidian-export - run: strip target/release/obsidian-export
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
@ -62,17 +69,21 @@ jobs:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
~/.cargo/registry/cache/
- uses: actions-rs/cargo@v1 ~/.cargo/git/db/
with: target/
command: build key: "cargo-build-linux-${{ steps.setup_rust.outputs.cachekey }}"
args: --release --locked - name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo build --release --locked
- run: strip target/release/obsidian-export.exe - run: strip target/release/obsidian-export.exe
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
@ -96,17 +107,21 @@ jobs:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
~/.cargo/registry/cache/
- uses: actions-rs/cargo@v1 ~/.cargo/git/db/
with: target/
command: build key: "cargo-build-linux-${{ steps.setup_rust.outputs.cachekey }}"
args: --release --locked - name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo build --release --locked
- run: strip target/release/obsidian-export - run: strip target/release/obsidian-export
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3

View File

@ -1,74 +1,136 @@
name: CI tests
on: [push, pull_request] on: [push, pull_request]
name: CI tests env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs: jobs:
linting: build:
name: Run lints name: Build project
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
rustc_cache_key: ${{ steps.setup_rust.outputs.cachekey }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
id: setup_rust
with: with:
profile: minimal components: "rustfmt, clippy"
toolchain: stable - uses: actions/cache@v3
override: true with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-base-${{ steps.setup_rust.outputs.cachekey }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-base-${{ env.RUSTC_CACHEKEY }}
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo build --locked --all-targets
- run: rustup component add rustfmt lint:
- uses: actions-rs/cargo@v1 name: Run lints
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with: with:
command: fmt path: |
args: --all -- --check ~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-lint-${{ needs.build.outputs.rustc_cache_key }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-lint-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- uses: actions-rs/cargo@v1 - run: cargo fmt --all -- --check
with: - run: cargo check
command: check - run: cargo clippy -- -D warnings
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
test-linux: test-linux:
name: Test on Linux name: Test on Linux
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
- uses: actions-rs/cargo@v1 ~/.cargo/registry/cache/
with: ~/.cargo/git/db/
command: test target/
key: "cargo-test-${{ needs.build.outputs.rustc_cache_key }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-test-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo test
test-windows: test-windows:
name: Test on Windows name: Test on Windows
runs-on: windows-latest runs-on: windows-latest
needs: build
steps: steps:
- run: git config --system core.autocrlf false && git config --system core.eol lf - run: git config --system core.autocrlf false && git config --system core.eol lf
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: dtolnay/rust-toolchain@stable
id: setup_rust
- uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
- uses: actions-rs/cargo@v1 ~/.cargo/registry/cache/
with: ~/.cargo/git/db/
command: test target/
key: "cargo-windows-${{ needs.build.outputs.rustc_cache_key }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-windows-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- run: cargo test
coverage: coverage:
name: Code coverage name: Code coverage
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: build
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1 - uses: actions/cache@v3
with: with:
profile: minimal path: |
toolchain: stable ~/.cargo/bin/
override: true ~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: "cargo-coverage-${{ needs.build.outputs.rustc_cache_key }}-${{ hashFiles('**/Cargo.lock') }}"
restore-keys: |
cargo-coverage-${{ env.RUSTC_CACHEKEY }}
cargo-base-${{ env.RUSTC_CACHEKEY }}
fail-on-cache-miss: true
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
- uses: actions-rs/tarpaulin@v0.1 - uses: actions-rs/tarpaulin@v0.1
with: with:
# Constrained by https://github.com/actions-rs/tarpaulin/pull/23 # Constrained by https://github.com/actions-rs/tarpaulin/pull/23