Skip to content

Commit

Permalink
Add composite action to CI (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass authored Sep 16, 2021
1 parent 3ee45d6 commit e2648ed
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 160 deletions.
72 changes: 72 additions & 0 deletions .github/actions/rust/rust-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: 'rust-setup'
description: 'Prepares a rust environment and relevant caches.'
inputs:
sccache-path:
description: 'Path of the sccache.'
required: true
os:
description: 'OS of the runner, used for cache key construction.'
required: true
job:
description: 'Name of the job, used for cache key construction.'
required: true
current-date:
description: 'Current date, used for cache key construction.'
required: true
target-cache-path:
description: 'Path of the target cache.'
required: false
default: target
runs:
using: "composite"
steps:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- 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: ${{ inputs.os }}-cargo-${{ inputs.job }}-${{ hashFiles('**/Cargo.toml') }}-${{ inputs.current-date }}
# Restore from outdated cache for speed
restore-keys: |
${{ inputs.os }}-cargo-${{ inputs.job }}-${{ hashFiles('**/Cargo.toml') }}-
${{ inputs.os }}-cargo-${{ inputs.job }}-
${{ inputs.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: ${{ inputs.target-cache-path }}
# Add date to the cache to keep it up to date
key: ${{ inputs.os }}-target-${{ inputs.job }}-${{ hashFiles('**/Cargo.lock') }}
# Restore from outdated cache for speed
restore-keys: |
${{ inputs.os }}-target-${{ inputs.job }}-
${{ inputs.os }}-target-
- name: Cache sccache
uses: actions/cache@v2.1.6
with:
path: ${{ inputs.sccache-path }}
key: ${{ inputs.os }}-sccache-${{ inputs.job }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ inputs.os }}-sccache-${{ inputs.job }}-
${{ inputs.os }}-sccache-
16 changes: 16 additions & 0 deletions .github/actions/rust/sccache/setup-sccache-macos/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'setup-sccache-macos'
description: 'Setup sccache for macos.'
runs:
using: "composite"
steps:
- name: Install sccache (macos-latest)
shell: sh
run: |
brew update --preinstall
brew install sccache
- name: Start sccache
shell: sh
run: |
sccache --start-server
sccache -s
27 changes: 27 additions & 0 deletions .github/actions/rust/sccache/setup-sccache-ubuntu/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'setup-sccache-ubuntu'
description: 'Setup sccache for ubuntu.'
runs:
using: "composite"
steps:
- name: Install sccache (macos-latest)
shell: sh
run: |
SCCACHE_DOWNLOAD_LINK=https://github.com/mozilla/sccache/releases/download
SCCACHE_VERSION=v0.2.15
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
shell: sh
run: |
sccache --start-server
sccache -s
17 changes: 17 additions & 0 deletions .github/actions/rust/sccache/setup-sccache-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'setup-sccache-windows'
description: 'Setup sccache for windows.'
runs:
using: "composite"
steps:
- name: Install sccache (windows-latest)
shell: pwsh
run: |
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install sccache
echo "${HOME}/scoop/apps/sccache/current" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Start sccache
shell: pwsh
run: |
sccache --start-server
sccache -s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: 'stop-sccache-ubuntu-macos'
description: 'Stop sccache on ubuntu and macos.'
runs:
using: "composite"
steps:
- name: Stop sccache server
shell: sh
run: sccache --stop-server || true
8 changes: 8 additions & 0 deletions .github/actions/rust/sccache/stop-sccache-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: 'stop-sccache-windows'
description: 'Stop sccache on windows.'
runs:
using: "composite"
steps:
- name: Stop sccache server
shell: pwsh
run: sccache --stop-server || true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: 'get-current-date-ubuntu-macos'
description: 'Script for getting the current date on ubuntu and macos.'
runs:
using: "composite"
steps:
- name: Get current date
shell: sh
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
8 changes: 8 additions & 0 deletions .github/actions/utils/get-current-date-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: 'get-current-date-windows'
description: 'Script for getting the current date on windows.'
runs:
using: "composite"
steps:
- name: Get current date
shell: pwsh
run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Loading

0 comments on commit e2648ed

Please sign in to comment.