Skip to content

Commit

Permalink
use Cargo.lock for caches, remove libjose caches (#390)
Browse files Browse the repository at this point in the history
* use Cargo.lock for caches, remove libjose caches

* fix sccache env

* Update .github/workflows/build-and-test.yml

Co-authored-by: Craig Bester <craig.bester@iota.org>

* Update .github/workflows/build-and-test.yml

Co-authored-by: Craig Bester <craig.bester@iota.org>

Co-authored-by: Craig Bester <craig.bester@iota.org>
  • Loading branch information
eike-hass and cycraig authored Sep 8, 2021
1 parent b755a40 commit d5d46dc
Showing 1 changed file with 22 additions and 78 deletions.
100 changes: 22 additions & 78 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:

env:
RUST_BACKTRACE: full
RUSTC_WRAPPER: sccache
SCCACHE_DOWNLOAD_LINK: https://github.com/mozilla/sccache/releases/download
SCCACHE_VERSION: v0.2.15
SCCACHE_CACHE_SIZE: 2G
Expand All @@ -39,6 +38,7 @@ jobs:
sccache-path: C:\\Users\\runner\\AppData\\Local\\Mozilla\\sccache\\cache
env:
SCCACHE_DIR: ${{ matrix.sccache-path }}
RUSTC_WRAPPER: sccache

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -74,15 +74,22 @@ jobs:
${{ matrix.os }}-cargo-${{ github.job }}-
${{ matrix.os }}-cargo-
# Generate Cargo.lock files for build, sccache cache keys.
# Allows dependencies updated on crates.io between runs to trigger storing an updated cache,
# which hashing Cargo.toml files alone does not.
- name: Cargo update
uses: actions-rs/cargo@v1
with:
command: update

- name: Cache build target
uses: actions/cache@v2.1.4
with:
path: target
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
key: ${{ matrix.os }}-target-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ matrix.os }}-target-${{ github.job }}-
${{ matrix.os }}-target-
Expand All @@ -91,9 +98,8 @@ jobs:
continue-on-error: false
with:
path: ${{ matrix.sccache-path }}
key: ${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
key: ${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ runner.os }}-sccache-${{ github.job }}-
${{ runner.os }}-sccache-
Expand Down Expand Up @@ -154,9 +160,6 @@ jobs:
os: [ ubuntu-latest ]
include:
- os: ubuntu-latest
sccache-path: /home/runner/.cache/sccache
env:
SCCACHE_DIR: ${{ matrix.sccache-path }}

steps:
- uses: actions/checkout@v2
Expand All @@ -167,69 +170,6 @@ jobs:
toolchain: stable
override: true

- name: Get current date
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: Cache cargo
uses: actions/cache@v2.1.4
with:
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ matrix.os }}-cargo-${{ github.job }}-
${{ matrix.os }}-cargo-
- name: Cache libjose build target
uses: actions/cache@v2.1.4
with:
path: libjose/target
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-libjose-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-libjose-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ matrix.os }}-libjose-target-${{ github.job }}-
${{ matrix.os }}-libjose-target-
- name: Cache sccache
uses: actions/cache@v2.1.6
continue-on-error: false
with:
path: ${{ matrix.sccache-path }}
key: ${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
restore-keys: |
${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ runner.os }}-sccache-${{ github.job }}-
${{ runner.os }}-sccache-
- name: Install sccache (ubuntu-latest)
if: matrix.os == 'ubuntu-latest'
run: |
SCCACHE_PREFIX="sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl"
SCCACHE_TAR="${SCCACHE_PREFIX}.tar.gz"
DOWNLOAD_LINK="${SCCACHE_DOWNLOAD_LINK}/${SCCACHE_VERSION}/${SCCACHE_TAR}"
curl -L "${DOWNLOAD_LINK}" --output ${SCCACHE_TAR}
echo "$(curl -L ${DOWNLOAD_LINK}.sha256) ${SCCACHE_TAR}" | shasum -a 256 --check --status
tar xzf ${SCCACHE_TAR}
BIN_DIR="$HOME/.local/bin"
mkdir -p ${BIN_DIR}
mv -f ${SCCACHE_PREFIX}/sccache ${BIN_DIR}/sccache
chmod a+x "${BIN_DIR}/sccache"
echo ${BIN_DIR} >> $GITHUB_PATH
- name: Start sccache
run: |
sccache --start-server
sccache -s
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -242,9 +182,6 @@ jobs:
command: test
args: --manifest-path ./libjose/Cargo.toml --release

- name: Stop sccache server
run: sccache --stop-server || true

build-and-test-wasm:
runs-on: ubuntu-latest
strategy:
Expand All @@ -256,6 +193,7 @@ jobs:
sccache-path: /home/runner/.cache/sccache
env:
SCCACHE_DIR: ${{ matrix.sccache-path }}
RUSTC_WRAPPER: sccache

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -289,15 +227,22 @@ jobs:
${{ matrix.os }}-cargo-${{ github.job }}-
${{ matrix.os }}-cargo-
# Generate Cargo.lock files for build, sccache cache keys.
# Allows dependencies updated on crates.io between runs to trigger storing an updated cache,
# which hashing Cargo.toml files alone does not.
- name: Cargo update
uses: actions-rs/cargo@v1
with:
command: update

- name: Cache wasm target
uses: actions/cache@v2.1.4
with:
path: bindings/wasm/target
# Add date to the cache to keep it up to date
key: ${{ matrix.os }}-wasm-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
key: ${{ matrix.os }}-wasm-target-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.os }}-wasm-target-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ matrix.os }}-wasm-target-${{ github.job }}-
${{ matrix.os }}-wasm-target-
Expand All @@ -306,9 +251,8 @@ jobs:
continue-on-error: false
with:
path: ${{ matrix.sccache-path }}
key: ${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
key: ${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-sccache-${{ github.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ runner.os }}-sccache-${{ github.job }}-
${{ runner.os }}-sccache-
Expand Down

0 comments on commit d5d46dc

Please sign in to comment.