Accelerate GitHub Actions workflow #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: | |
# Workflow for creating a cache. | |
# Currently, all jobs can share the cache, | |
# but the data to be cached is not necessarily created by all jobs (e.g. plt files). | |
# For this reason, this workflow is used to create the cache in batches. | |
# Another advantage of this method is that | |
# the absence of a cache does not cause jobs to take longer to run. | |
name: Create cache | |
on: | |
schedule: | |
# NOTE: | |
# The validity period of the cache is virtually unlimited. | |
# Originally, a cache is valid for 7 days | |
# (c.f. https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy), | |
# but if a new cache is created before the cache becomes invalid, | |
# the validity period can be extended for another 7 days. | |
- cron: "0 0 */6 * *" | |
push: | |
pull_request: | |
workflow_dispatch: | |
env: | |
otp: 26.0 | |
rebar3: 3.22.1 | |
jobs: | |
test: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: erlef/setup-beam@v1 | |
with: | |
otp-version: ${{ env.otp }} | |
rebar3-version: ${{ env.rebar3 }} | |
- uses: actions/cache/restore@v4 | |
id: cache-restore | |
with: | |
key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}-${{ github.run_id }}-${{ github.run_attempt }} | |
path: | | |
~/.cache/rebar3 | |
_build | |
restore-keys: | | |
${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} | |
# NOTE: | |
# We always execute the following commands, | |
# as the presence of a cache will drastically reduce execution time. | |
# The above cache will always match the keys in `restore-keys`, | |
# so one of the outputs of the Restore action, `cache-hit`, will always be `false`, | |
# and the cost of conditional branching due to the presence of the cache will be high. | |
- name: Create cache data | |
run: | | |
rebar3 compile | |
rebar3 as test compile | |
rebar3 dialyzer | |
- uses: actions/cache/save@v4 | |
if: always() | |
with: | |
key: ${{ steps.cache-restore.outputs.cache-primary-key }} | |
path: | | |
~/.cache/rebar3 | |
_build |