This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
107 lines (96 loc) · 4.71 KB
/
Copy pathrust.yml
File metadata and controls
107 lines (96 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Rust
on:
pull_request:
branches:
- 'develop'
- 'main'
env:
CARGO_TERM_COLOR: always
GH_TOKEN: ${{ github.token }}
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@v3
- name: Npm install
run: |
cd dev
npm install
# Check if rust is formatted correctly
- name: Rust formatting check
run: |
cd dev
npm run cli -- fmt --check --toolchain nightly --docker
# take ownership of the build files so they can be cached
npm run cli -- chown
# Restore the cargo build from cache, if available
- name: Restore cached cargo build
uses: actions/cache/restore@v3
with:
path: |
target
# the cached build is based on the OS, architecture, a tag and the hash of the config files for this build, i.e. the Cargo configuration. The cargo configs may differ across workflows, so the files have to be the same to reuse the cached build image across workflows
# restore from a cache matching the key, e.g. "Linux-X64-cargo-env-abcdef123"
# "abcdef123" could be anything, it is a random string to differentiate cache usages
# e.g. "Linux-X64-cargo-a1" may be from 1/1/23, whereas "Linux-X64-cargo-b2" may be from 2/1/23.
# github will match the most recent cache ("b2") when searching for caches and finding multiple matches
# the "-" on the end of the key acts like "-*" where the "*" can be any number of characters, including none
key: cargo-build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: |
cargo-build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}-
cargo-build-${{ runner.os }}-${{ runner.arch }}-
cargo-build-${{ runner.os }}-
cargo-build-
# Check for clippy advice
- name: Clippy
run: |
cd dev
npm run cli -- clippy --toolchain nightly --docker
# take ownership of the build files so they can be cached
npm run cli -- chown
# Do the build
- name: Build contract
id: build
run: |
cd dev
npm run cli -- build --release --toolchain nightly --docker
# take ownership of the build files so they can be cached
npm run cli -- chown
# Do unit testing
- name: Test contract
run: |
cd dev
RUST_BACKTRACE=1 npm run cli -- test --toolchain nightly --docker
result=$?
# take ownership of the build files so they can be cached
npm run cli -- chown
exit $result
- name: Cleanup cargo build caches
if: always() && (${{ steps.build.conclusion }} == "success" || ${{ steps.build.conclusion }} == "failure")
run: |
set +e; gh extension install actions/gh-actions-cache; set -e
REPO=${{ github.repository }}
echo "Fetching list of cache key"
# remove all except the most recent cached build
# we leave the latest cached build to be used by other workflows which may be running in parallel (i.e. there is always at least one cached build at any given time)
cacheKeys=$(gh actions-cache list --sort created-at --order desc --limit 100 -R $REPO --key cargo-build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}- | cut -f 1 | tail -n +3)
echo caches to be removed:
echo ${cacheKeys}
# delete the stale caches
## Setting this to not fail the workflow while deleting cache keys.
set +e
for cacheKey in $cacheKeys
do
gh actions-cache delete $cacheKey -R $REPO --confirm
done
# Save build + test files to cache, use for incremental builds in other runs to speed up future workflows with minor changes
- name: Save cargo build to cache
uses: actions/cache/save@v3
# save cache if build work has been done, independent of whether it failed/succeeded
if: always() && (${{ steps.build.conclusion }} == "success" || ${{ steps.build.conclusion }} == "failure")
with:
path: |
target
# store this version in the cache tagged with the id of this job. This differentiates it from any other caches for the same build without mutating them, as other workflows may be using them
key: cargo-build-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}-${{ github.run_id }}-${{ github.run_attempt }}