This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
133 lines (133 loc) · 4.98 KB
/
action.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: rust sccache
description: Shared Compilation Cache for Rust
branding:
icon: award
color: green
inputs:
version:
description: The version of sccache to use
required: true
default: 'v0.3.1'
key:
description: An additional key for the cache
required: false
shared-key:
description: An additional key that is stable over multiple jobs
required: false
skip-save:
description: Skip saving the cache
required: false
default: 'false'
autoclean:
description: Automatically clean the cache
required: false
default: 'false'
outputs:
cache-hit:
description: A boolean value to indicate an exact match was found for the key.
value: ${{ steps.restore.outputs.cache-hit == 'true' || steps.restore-save.outputs.cache-hit == 'true' }}
cache-primary-key:
description: Cache primary key passed in the input to use in subsequent steps of the workflow.
value: ${{ steps.restore.outputs.cache-primary-key == 'true' || steps.restore-save.outputs.cache-primary-key == 'true' }}
cache-matched-key:
description: Key of the cache that was restored, it could either be the primary key on cache-hit or a partial/complete match of one of the restore keys.
value: ${{ steps.restore.outputs.cache-matched-key == 'true' || steps.restore-save.outputs.cache-matched-key == 'true' }}
runs:
using: composite
steps:
- id: rust
name: Checking Rust version
run: |
version="$(rustc -vV)"
echo "release=$(sed -En 's/^release: (.+)/\1/p' <<< "$version")" >> $GITHUB_OUTPUT
echo "host=$(sed -En 's/^host: (.+)/\1/p' <<< "$version")" >> $GITHUB_OUTPUT
echo "commit-hash=$(sed -En 's/^commit-hash: (.{0,12}).*/\1/p' <<< "$version")" >> $GITHUB_OUTPUT
shell: bash
- id: platform
name: Defining Platform to download
env:
OS: ${{ runner.os }}
run: |
platform='unknown-linux-musl'
if [[ "$OS" == "macOS" ]]; then
platform='apple-darwin'
fi
echo "platform=${platform}" >> $GITHUB_OUTPUT
shell: bash
- id: cache
name: Computing cache key
run: |
key='v0-sccache'
if [[ ! -z '${{ inputs.shared-key }}' ]]; then
key="$key-${{ inputs.shared-key }}"
else
if [[ ! -z '${{ inputs.key }}' ]]; then
key="$key-${{ inputs.key }}"
fi
key="$key-${{ github.job }}"
fi
key="$key-${{ steps.rust.outputs.release }}-${{ steps.rust.outputs.host }}-${{ steps.rust.outputs.commit-hash }}"
hash='${{ hashFiles('**/Cargo.toml', '**/Cargo.lock', 'rust-toolchain', 'rust-toolchain.toml') }}'
echo "key=$key-${hash:0:20}" >> $GITHUB_OUTPUT
echo "restore-key=$key-" >> $GITHUB_OUTPUT
shell: bash
- name: Installing sccache
run: |
asset_name='sccache-${{ inputs.version }}-x86_64-${{ steps.platform.outputs.platform }}'
curl --retry 5 --no-progress-meter --location --output "$asset_name.tar.gz" "https://github.com/mozilla/sccache/releases/download/${{ inputs.version }}/$asset_name.tar.gz"
tar -zxf "$asset_name.tar.gz"
cp "$asset_name/sccache" '/usr/local/bin/sccache'
chmod +x '/usr/local/bin/sccache'
rm -r "$asset_name"
rm "$asset_name.tar.gz"
shell: bash
- name: Configuring sccache environment
run: |
if [ -z '${{ env.RUSTC_WRAPPER }}' ]; then
echo 'RUSTC_WRAPPER=sccache' >> $GITHUB_ENV
fi
if [ -z '${{ env.SCCACHE_DIR }}' ]; then
echo "SCCACHE_DIR=$HOME/.cache/sccache" >> $GITHUB_ENV
fi
# Disable incremental builds as they break sccache.
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
shell: bash
- name: Restore cache
id: restore
if: env.CACHE_SKIP_SAVE == 'true' || inputs.skip-save == 'true'
uses: actions/cache/restore@v3
with:
path: |
${{ env.SCCACHE_DIR }}
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
!target/**/bundle.car
key: ${{ steps.cache.outputs.key }}
restore-keys: |
${{ steps.cache.outputs.restore-key }}
- name: Restore and save cache
id: restore-save
if: env.CACHE_SKIP_SAVE != 'true' && inputs.skip-save != 'true'
uses: actions/cache@v3
with:
path: |
${{ env.SCCACHE_DIR }}
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
!target/**/bundle.car
key: ${{ steps.cache.outputs.key }}
restore-keys: |
${{ steps.cache.outputs.restore-key }}
- name: Installing cargo-cache
if: inputs.autoclean == 'true' && inputs.skip-save == 'false'
run: cargo install cargo-cache
shell: bash
- name: Cleaning cache
if: inputs.autoclean == 'true' && inputs.skip-save == 'false'
uses: gacts/run-and-post-run@fe4132a675276bbabaeea80a61dba37cdb98d2e4 # v1.3.0
with:
post: cargo cache --autoclean