Skip to content

Commit d27bc47

Browse files
committed
Add a composite action to handle toolchain, tools & cache in ci
1 parent b2a2301 commit d27bc47

File tree

4 files changed

+52
-61
lines changed

4 files changed

+52
-61
lines changed

.github/workflows/actions/build-upload-mithril-artifact/action.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,9 @@ inputs:
55
description: Arguments to pass to 'cargo build'
66
required: false
77
default: ''
8-
cache-version:
9-
description: Version of the current cache
10-
required: false
11-
default: ''
128
runs:
139
using: "composite"
1410
steps:
15-
- name: Install stable toolchain
16-
uses: actions-rs/toolchain@v1
17-
with:
18-
profile: minimal
19-
toolchain: stable
20-
override: true
21-
22-
- name: Rust Cache
23-
uses: Swatinem/rust-cache@v2
24-
with:
25-
key: ${{ runner.os }}-cache-v${{ inputs.cache-version }}
26-
2711
- name: Add commit short sha to Cargo.tomls version
2812
shell: bash
2913
run: |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: toolchain-and-cache
2+
description: Install the stable cargo toolchain, the given cargo tools, and try to restore cache
3+
inputs:
4+
cache-version:
5+
description: Version of the current cache
6+
required: false
7+
default: ''
8+
cargo-tools:
9+
description: Space seperated list of cargo tools to install
10+
required: false
11+
default: ''
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Install stable toolchain
16+
uses: actions-rs/toolchain@v1
17+
with:
18+
profile: minimal
19+
toolchain: stable
20+
override: true
21+
22+
- name: Rust Cache
23+
uses: Swatinem/rust-cache@v2
24+
with:
25+
key: ${{ runner.os }}-cache-v${{ inputs.cache-version }}
26+
27+
- name: Install cargo tools
28+
if: inputs.cargo-tools != ''
29+
shell: bash
30+
run: |
31+
cargo install ${{ inputs.cargo-tools }} 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error

.github/workflows/ci.yml

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ jobs:
1515
- name: Checkout sources
1616
uses: actions/checkout@v3
1717

18-
- name: Build Mithril workspace & publish artifacts
19-
uses: ./.github/workflows/actions/build-upload-mithril-artifact
18+
- name: Install stable toolchain and restore cache
19+
uses: ./.github/workflows/actions/toolchain-and-cache
2020
with:
2121
cache-version: ${{ secrets.CACHE_VERSION }}
2222

23+
- name: Build Mithril workspace & publish artifacts
24+
uses: ./.github/workflows/actions/build-upload-mithril-artifact
25+
2326
- name: Publish End-to-end runner (${{ runner.os }}-${{ runner.arch }})
2427
uses: actions/upload-artifact@v3
2528
with:
@@ -44,11 +47,15 @@ jobs:
4447
steps:
4548
- name: Checkout sources
4649
uses: actions/checkout@v3
50+
51+
- name: Install stable toolchain and restore cache
52+
uses: ./.github/workflows/actions/toolchain-and-cache
53+
with:
54+
cache-version: ${{ secrets.CACHE_VERSION }}
4755

4856
- name: Build Mithril workspace & publish artifacts
4957
uses: ./.github/workflows/actions/build-upload-mithril-artifact
5058
with:
51-
cache-version: ${{ secrets.CACHE_VERSION }}
5259
build-args: ${{ matrix.build-args }}
5360

5461
test:
@@ -75,22 +82,11 @@ jobs:
7582
- name: Checkout sources
7683
uses: actions/checkout@v3
7784

78-
- name: Install stable toolchain
79-
uses: actions-rs/toolchain@v1
80-
with:
81-
profile: minimal
82-
toolchain: stable
83-
override: true
84-
85-
- name: Rust Cache
86-
uses: Swatinem/rust-cache@v2
85+
- name: Install stable toolchain, tools, and restore cache
86+
uses: ./.github/workflows/actions/toolchain-and-cache
8787
with:
88-
key: ${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}
89-
90-
- name: Install cargo tools
91-
shell: bash
92-
run: |
93-
cargo install cargo2junit 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error
88+
cache-version: ${{ secrets.CACHE_VERSION }}
89+
cargo-tools: cargo2junit
9490

9591
- name: Run tests
9692
shell: bash
@@ -114,24 +110,11 @@ jobs:
114110
- name: Checkout sources
115111
uses: actions/checkout@v3
116112

117-
- name: Install stable toolchain
118-
uses: actions-rs/toolchain@v1
119-
with:
120-
profile: minimal
121-
toolchain: stable
122-
components: clippy, rustfmt
123-
override: true
124-
125-
- name: Rust Cache
126-
uses: Swatinem/rust-cache@v2
113+
- name: Install stable toolchain, tools, and restore cache
114+
uses: ./.github/workflows/actions/toolchain-and-cache
127115
with:
128-
key: ${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}
129-
130-
- name: Install cargo tools
131-
if: steps.cargo-cache.outputs.cache-hit == false
132-
shell: bash
133-
run: |
134-
cargo install cargo-sort 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error
116+
cache-version: ${{ secrets.CACHE_VERSION }}
117+
cargo-tools: cargo-sort
135118

136119
- name: Cargo check
137120
uses: actions-rs/cargo@v1

.github/workflows/docs.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ jobs:
1212
- name: Checkout sources
1313
uses: actions/checkout@v3
1414

15-
- name: Install stable toolchain
16-
uses: actions-rs/toolchain@v1
15+
- name: Install stable toolchain and restore cache
16+
uses: ./.github/workflows/actions/toolchain-and-cache
1717
with:
18-
profile: minimal
19-
toolchain: stable
20-
override: true
21-
22-
- name: Rust Cache
23-
uses: Swatinem/rust-cache@v2
24-
with:
25-
key: ${{ runner.os }}-cache-v${{ secrets.CACHE_VERSION }}
18+
cache-version: ${{ secrets.CACHE_VERSION }}
2619

2720
- name: Generate cargo doc
2821
uses: actions-rs/cargo@v1

0 commit comments

Comments
 (0)