Skip to content

Commit

Permalink
Merge pull request #37 from ajfAfg/accelerate-github-actions-workflow
Browse files Browse the repository at this point in the history
Accelerate GitHub Actions workflow
  • Loading branch information
ajfAfg authored Feb 17, 2024
2 parents c4e2eee + 1f5fa26 commit 7ba60c6
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 43 deletions.
55 changes: 55 additions & 0 deletions .github/actions/setup-beam-with-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Setup beam with Rebar3 cache
description: Action that combines `erlef/setup-beam@v1` and `action/cache@v4`

inputs:
otp-version:
description: Erlang/OTP version (string)
required: true
rebar3-version:
description: Rebar3 version (string)
required: true
rebar-lock-path:
description: Path of `rebar.lock` (string)
required: true
overwrite:
description: Whether to overwrite the cache (bool string)
required: false
default: "false"

runs:
using: composite
steps:
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ inputs.otp-version }}
rebar3-version: ${{ inputs.rebar3-version }}

- uses: actions/cache@v4
id: cache-no-overwrite
if: ${{ inputs.overwrite != 'true' }}
with:
key: ${{ runner.os }}-otp-${{ inputs.otp-version }}-rebar3-${{ inputs.rebar3-version }}-${{ hashFiles(inputs.rebar-lock-path) }}
path: |
~/.cache/rebar3
_build
restore-keys: |
${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}-
- uses: actions/cache@v4
if: ${{ inputs.overwrite == 'true' }}
with:
# NOTE: No duplicate key to overwrite the cache.
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') }}
- name: Create cache data
shell: bash
if: ${{ steps.cache-no-overwrite.outputs.cache-hit != 'true' }}
run: |
rebar3 compile
rebar3 as test compile
rebar3 dialyzer
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Erlang CI

on:
push:
branches: ["main"]
pull_request:
types: ["opened", "synchronize", "reopened"]

permissions:
contents: read

env:
otp: 26.0
rebar3: 3.22.1

jobs:
#============================================================================
# Build
build:
runs-on: ubuntu-22.04

# NOTE: To check if the first build is possible, do not use the cache.
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
- run: rebar3 compile

#============================================================================
# Static Analysis
static_analysis:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./rebar.lock"

- run: rebar3 xref
- run: rebar3 dialyzer

#============================================================================
# Test
test:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./rebar.lock"

- name: Run sample-based-tests
run: rebar3 do eunit, ct
- name: Run property-based-tests
run: rebar3 proper -n 500
34 changes: 34 additions & 0 deletions .github/workflows/create-cache-periodically.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# NOTE:
# Workflow for creating a cache periodically.
# Eliminating the period during which the cache is invalid
# prevents the increase in execution time due to the absence of the cache.
name: Create cache periodically

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 * *"

workflow_dispatch:

env:
otp: 26.0
rebar3: 3.22.1

jobs:
overwrite-cache:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./rebar.lock"
overwrite: "true"
28 changes: 18 additions & 10 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@ on:
permissions:
contents: read

env:
otp: 26.0
rebar3: 3.22.1

jobs:
demo_with_polynomial_time_without_correctness:
# NOTE: Run on Ubuntu of Docker in my computer
runs-on: ubuntu-22.04

container:
image: erlang:26.2.1

defaults:
run:
working-directory: ./demo

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./demo/rebar.lock"

- name: Demonstrate with polynomial_time_without_correctness
run: |
mkdir _checkouts
Expand All @@ -44,18 +50,20 @@ jobs:
[ $(erl -pa _build/default/lib/demo/ebin -run run main -noshell | grep 'Result: 55' | wc -l) -eq 2 ]
demo_with_exp_time_with_correctness:
# NOTE: Run on Ubuntu of Docker in my computer
runs-on: ubuntu-22.04

container:
image: erlang:26.2.1

defaults:
run:
working-directory: ./demo

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./demo/rebar.lock"

- name: Demonstrate with exp_time_with_correctness
run: |
mkdir _checkouts
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/erlang.yml

This file was deleted.

15 changes: 11 additions & 4 deletions .github/workflows/run-property-based-tests-periodically.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ on:
# NOTE: Every day at 00:00 (JST)
- cron: "0 15 * * *"

env:
otp: 26.0
rebar3: 3.22.1

jobs:
test:
runs-on: ubuntu-22.04

container:
image: erlang:26.2.1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-beam-with-cache/
with:
otp-version: ${{ env.otp }}
rebar3-version: ${{ env.rebar3 }}
rebar-lock-path: "./rebar.lock"

- name: Run property-based tests
run: rebar3 proper -n 1000

0 comments on commit 7ba60c6

Please sign in to comment.