From a3887b75a122733b43baf8e6c91fd32dace05151 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:35:09 +0900 Subject: [PATCH 01/12] Version up `actions/checkout` --- .github/workflows/demo.yml | 4 ++-- .github/workflows/erlang.yml | 2 +- .github/workflows/run-property-based-tests-periodically.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index f8c2d15..79f9882 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -22,7 +22,7 @@ jobs: working-directory: ./demo steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Demonstrate with polynomial_time_without_correctness run: | mkdir _checkouts @@ -55,7 +55,7 @@ jobs: working-directory: ./demo steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Demonstrate with exp_time_with_correctness run: | mkdir _checkouts diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml index a764ac4..adca74d 100644 --- a/.github/workflows/erlang.yml +++ b/.github/workflows/erlang.yml @@ -18,7 +18,7 @@ jobs: image: erlang:26.2.1 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Compile run: rebar3 compile - name: Check statically diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index 158ecbb..92d7bdb 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -13,6 +13,6 @@ jobs: image: erlang:26.2.1 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Run property-based tests run: rebar3 proper -n 1000 From 4d23feb5c6debf0b01cb9fe2472a4088ee3cced1 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:09:02 +0900 Subject: [PATCH 02/12] Rename the CI file --- .github/workflows/{erlang.yml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{erlang.yml => ci.yml} (100%) diff --git a/.github/workflows/erlang.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/erlang.yml rename to .github/workflows/ci.yml From c26b7a0392b6e21cbf17c90c34d8f9ac1f6fdf1c Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:36:57 +0900 Subject: [PATCH 03/12] Use `erlef/setup-beam@v1` --- .github/workflows/ci.yml | 39 +++++++++++++++---- .github/workflows/demo.yml | 16 ++++---- .../run-property-based-tests-periodically.yml | 7 ++-- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index adca74d..a47e1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,19 +10,44 @@ permissions: contents: read jobs: + #============================================================================ + # Build build: - # NOTE: Run on Ubuntu of Docker in my computer runs-on: ubuntu-22.04 - container: - image: erlang:26.2.1 + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 + - run: rebar3 compile + + #============================================================================ + # Static Analysis + static_analysis: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 + - run: rebar3 xref + - run: rebar3 dialyzer + + #============================================================================ + # Test + test: + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - name: Compile - run: rebar3 compile - - name: Check statically - run: rebar3 check + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 - name: Run sample-based-tests run: rebar3 do eunit, ct - name: Run property-based-tests diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 79f9882..a7a78ad 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -11,18 +11,18 @@ permissions: 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@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 - name: Demonstrate with polynomial_time_without_correctness run: | mkdir _checkouts @@ -44,18 +44,18 @@ 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@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 - name: Demonstrate with exp_time_with_correctness run: | mkdir _checkouts diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index 92d7bdb..263ccf4 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -9,10 +9,11 @@ jobs: test: runs-on: ubuntu-22.04 - container: - image: erlang:26.2.1 - steps: - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: 26.0 + rebar3-version: 3.22.1 - name: Run property-based tests run: rebar3 proper -n 1000 From beb5b99c24b6d96e5a8bb4d5c2be2ab4b6fe8b8c Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Thu, 15 Feb 2024 10:32:17 +0900 Subject: [PATCH 04/12] Use variables --- .github/workflows/ci.yml | 16 ++++++++++------ .github/workflows/demo.yml | 12 ++++++++---- .../run-property-based-tests-periodically.yml | 8 ++++++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a47e1de..07e8f33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,10 @@ on: permissions: contents: read +env: + otp: 26.0 + rebar3: 3.22.1 + jobs: #============================================================================ # Build @@ -19,8 +23,8 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - run: rebar3 compile #============================================================================ @@ -32,8 +36,8 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - run: rebar3 xref - run: rebar3 dialyzer @@ -46,8 +50,8 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - name: Run sample-based-tests run: rebar3 do eunit, ct - name: Run property-based-tests diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index a7a78ad..03e3f33 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -9,6 +9,10 @@ on: permissions: contents: read +env: + otp: 26.0 + rebar3: 3.22.1 + jobs: demo_with_polynomial_time_without_correctness: runs-on: ubuntu-22.04 @@ -21,8 +25,8 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - name: Demonstrate with polynomial_time_without_correctness run: | mkdir _checkouts @@ -54,8 +58,8 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - name: Demonstrate with exp_time_with_correctness run: | mkdir _checkouts diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index 263ccf4..3f4d32e 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -5,6 +5,10 @@ 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 @@ -13,7 +17,7 @@ jobs: - uses: actions/checkout@v4 - uses: erlef/setup-beam@v1 with: - otp-version: 26.0 - rebar3-version: 3.22.1 + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - name: Run property-based tests run: rebar3 proper -n 1000 From 47778ea310d5189485c43344ec9342e191e58252 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:25:21 +0900 Subject: [PATCH 05/12] Use cache --- .github/workflows/ci.yml | 13 +++++++++++++ .github/workflows/demo.yml | 12 ++++++++++++ .../run-property-based-tests-periodically.yml | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07e8f33..f97aed0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: 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 @@ -38,6 +39,12 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} + - uses: actions/cache@v4 + with: + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + path: | + ~/.cache/rebar3 + _build - run: rebar3 xref - run: rebar3 dialyzer @@ -52,6 +59,12 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} + - uses: actions/cache@v4 + with: + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + path: | + ~/.cache/rebar3 + _build - name: Run sample-based-tests run: rebar3 do eunit, ct - name: Run property-based-tests diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 03e3f33..a8b035d 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -27,6 +27,12 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} + - uses: actions/cache@v4 + with: + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + path: | + ~/.cache/rebar3 + _build - name: Demonstrate with polynomial_time_without_correctness run: | mkdir _checkouts @@ -60,6 +66,12 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} + - uses: actions/cache@v4 + with: + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + path: | + ~/.cache/rebar3 + _build - name: Demonstrate with exp_time_with_correctness run: | mkdir _checkouts diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index 3f4d32e..f551f2a 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -19,5 +19,11 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} + - uses: actions/cache@v4 + with: + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + path: | + ~/.cache/rebar3 + _build - name: Run property-based tests run: rebar3 proper -n 1000 From 164de21540d53f3f480f862cb21b0e9dc72b5d70 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Thu, 15 Feb 2024 11:41:16 +0900 Subject: [PATCH 06/12] Fix the path of `rebar.lock` --- .github/workflows/ci.yml | 16 +++-- .github/workflows/create-cache.yml | 70 +++++++++++++++++++ .github/workflows/demo.yml | 6 +- .../run-property-based-tests-periodically.yml | 7 +- 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/create-cache.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f97aed0..cf9feea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,12 +39,17 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 + - uses: actions/cache/restore@v4 with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + key: dummy-${{ github.sha }} path: | ~/.cache/rebar3 _build + restore-keys: | + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + + - run: ls _build/default + - run: ls ~/.cache/rebar3 - run: rebar3 xref - run: rebar3 dialyzer @@ -59,12 +64,15 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 + - uses: actions/cache/restore@v4 with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + key: dummy-${{ github.sha }} path: | ~/.cache/rebar3 _build + restore-keys: | + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + - name: Run sample-based-tests run: rebar3 do eunit, ct - name: Run property-based-tests diff --git a/.github/workflows/create-cache.yml b/.github/workflows/create-cache.yml new file mode 100644 index 0000000..5822fe7 --- /dev/null +++ b/.github/workflows/create-cache.yml @@ -0,0 +1,70 @@ +# 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 + +# dummy comment + +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: + branches: ["main"] + pull_request: + types: ["opened", "synchronize", "reopened"] + workflow_dispatch: + +env: + otp: 26.0 + rebar3: 3.22.1 + +jobs: + create-cache: + 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 diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index a8b035d..1c57af1 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -29,10 +29,11 @@ jobs: rebar3-version: ${{ env.rebar3 }} - uses: actions/cache@v4 with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('./demo/rebar.lock') }} path: | ~/.cache/rebar3 _build + - name: Demonstrate with polynomial_time_without_correctness run: | mkdir _checkouts @@ -68,10 +69,11 @@ jobs: rebar3-version: ${{ env.rebar3 }} - uses: actions/cache@v4 with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('./demo/rebar.lock') }} path: | ~/.cache/rebar3 _build + - name: Demonstrate with exp_time_with_correctness run: | mkdir _checkouts diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index f551f2a..e5002ae 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -19,11 +19,14 @@ jobs: with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 + - uses: actions/cache/restore@v4 with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + key: dummy-${{ github.sha }} path: | ~/.cache/rebar3 _build + restore-keys: | + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + - name: Run property-based tests run: rebar3 proper -n 1000 From 3932c9d8cc74caaa2e3a42b66aa102854f1a1a6a Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sat, 17 Feb 2024 21:08:27 +0900 Subject: [PATCH 07/12] Split workflow by timing of cache generation --- .../workflows/create-cache-periodically.yml | 50 +++++++++++++++++++ .github/workflows/create-cache.yml | 44 ++++------------ 2 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/create-cache-periodically.yml diff --git a/.github/workflows/create-cache-periodically.yml b/.github/workflows/create-cache-periodically.yml new file mode 100644 index 0000000..43dad10 --- /dev/null +++ b/.github/workflows/create-cache-periodically.yml @@ -0,0 +1,50 @@ +# 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 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: + create-cache: + 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@v4 + 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 + run: | + rebar3 compile + rebar3 as test compile + rebar3 dialyzer diff --git a/.github/workflows/create-cache.yml b/.github/workflows/create-cache.yml index 5822fe7..b6e34a3 100644 --- a/.github/workflows/create-cache.yml +++ b/.github/workflows/create-cache.yml @@ -7,23 +7,11 @@ # the absence of a cache does not cause jobs to take longer to run. name: Create cache -# dummy comment - 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: branches: ["main"] pull_request: types: ["opened", "synchronize", "reopened"] - workflow_dispatch: env: otp: 26.0 @@ -35,36 +23,22 @@ jobs: 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 + - uses: actions/cache@v4 + id: cache with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}-${{ github.run_id }}-${{ github.run_attempt }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} 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. + - uses: erlef/setup-beam@v1 + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + with: + otp-version: ${{ env.otp }} + rebar3-version: ${{ env.rebar3 }} - name: Create cache data + if: ${{ steps.cache.outputs.cache-hit != 'true' }} 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 From 64ef6817ca546f77b738ddd53a2fc9efdcc28e11 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sat, 17 Feb 2024 21:20:13 +0900 Subject: [PATCH 08/12] Use the new cache keys --- .github/workflows/ci.yml | 8 ++++---- .../workflows/run-property-based-tests-periodically.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf9feea..0b83d09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,12 +41,12 @@ jobs: rebar3-version: ${{ env.rebar3 }} - uses: actions/cache/restore@v4 with: - key: dummy-${{ github.sha }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} path: | ~/.cache/rebar3 _build restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- - run: ls _build/default - run: ls ~/.cache/rebar3 @@ -66,12 +66,12 @@ jobs: rebar3-version: ${{ env.rebar3 }} - uses: actions/cache/restore@v4 with: - key: dummy-${{ github.sha }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} path: | ~/.cache/rebar3 _build restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- - name: Run sample-based-tests run: rebar3 do eunit, ct diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index e5002ae..dc3a0e9 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -21,12 +21,12 @@ jobs: rebar3-version: ${{ env.rebar3 }} - uses: actions/cache/restore@v4 with: - key: dummy-${{ github.sha }} + key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} path: | ~/.cache/rebar3 _build restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} + ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- - name: Run property-based tests run: rebar3 proper -n 1000 From b6951a1e4f6768c5d6d7da4b1119ab97c73ace4e Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:20:46 +0900 Subject: [PATCH 09/12] Add a composite action to setup beam with cache --- .../actions/setup-beam-with-cache/action.yml | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/actions/setup-beam-with-cache/action.yml diff --git a/.github/actions/setup-beam-with-cache/action.yml b/.github/actions/setup-beam-with-cache/action.yml new file mode 100644 index 0000000..6cee60e --- /dev/null +++ b/.github/actions/setup-beam-with-cache/action.yml @@ -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 + 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.outputs.cache-hit != 'true' }} + run: | + rebar3 compile + rebar3 as test compile + rebar3 dialyzer From 37d6b9609f702f23dfd6ea692ef9addbed8087a9 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:20:59 +0900 Subject: [PATCH 10/12] Use the composite action --- .github/workflows/ci.yml | 22 ++-------- .../workflows/create-cache-periodically.yml | 19 ++------ .github/workflows/create-cache.yml | 44 ------------------- .github/workflows/demo.yml | 18 ++------ .../run-property-based-tests-periodically.yml | 11 +---- 5 files changed, 13 insertions(+), 101 deletions(-) delete mode 100644 .github/workflows/create-cache.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b83d09..a08bce7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,18 +35,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache/restore@v4 - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} - path: | - ~/.cache/rebar3 - _build - restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- + rebar-lock-path: "./rebar.lock" - run: ls _build/default - run: ls ~/.cache/rebar3 @@ -60,18 +53,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache/restore@v4 - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} - path: | - ~/.cache/rebar3 - _build - restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- + rebar-lock-path: "./rebar.lock" - name: Run sample-based-tests run: rebar3 do eunit, ct diff --git a/.github/workflows/create-cache-periodically.yml b/.github/workflows/create-cache-periodically.yml index 43dad10..bdf3ea6 100644 --- a/.github/workflows/create-cache-periodically.yml +++ b/.github/workflows/create-cache-periodically.yml @@ -29,22 +29,9 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 - 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 - run: | - rebar3 compile - rebar3 as test compile - rebar3 dialyzer + rebar-lock-path: "./rebar.lock" + overwrite: "true" diff --git a/.github/workflows/create-cache.yml b/.github/workflows/create-cache.yml deleted file mode 100644 index b6e34a3..0000000 --- a/.github/workflows/create-cache.yml +++ /dev/null @@ -1,44 +0,0 @@ -# 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: - push: - branches: ["main"] - pull_request: - types: ["opened", "synchronize", "reopened"] - -env: - otp: 26.0 - rebar3: 3.22.1 - -jobs: - create-cache: - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 - id: cache - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} - path: | - ~/.cache/rebar3 - _build - - - uses: erlef/setup-beam@v1 - if: ${{ steps.cache.outputs.cache-hit != 'true' }} - with: - otp-version: ${{ env.otp }} - rebar3-version: ${{ env.rebar3 }} - - name: Create cache data - if: ${{ steps.cache.outputs.cache-hit != 'true' }} - run: | - rebar3 compile - rebar3 as test compile - rebar3 dialyzer diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index 1c57af1..6a96624 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -23,16 +23,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('./demo/rebar.lock') }} - path: | - ~/.cache/rebar3 - _build + rebar-lock-path: "./demo/rebar.lock" - name: Demonstrate with polynomial_time_without_correctness run: | @@ -63,16 +58,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('./demo/rebar.lock') }} - path: | - ~/.cache/rebar3 - _build + rebar-lock-path: "./demo/rebar.lock" - name: Demonstrate with exp_time_with_correctness run: | diff --git a/.github/workflows/run-property-based-tests-periodically.yml b/.github/workflows/run-property-based-tests-periodically.yml index dc3a0e9..6083dbd 100644 --- a/.github/workflows/run-property-based-tests-periodically.yml +++ b/.github/workflows/run-property-based-tests-periodically.yml @@ -15,18 +15,11 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 + - uses: ./.github/actions/setup-beam-with-cache/ with: otp-version: ${{ env.otp }} rebar3-version: ${{ env.rebar3 }} - - uses: actions/cache/restore@v4 - with: - key: ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }} - path: | - ~/.cache/rebar3 - _build - restore-keys: | - ${{ runner.os }}-otp-${{ env.otp }}-rebar3-${{ env.rebar3 }}-${{ hashFiles('rebar.lock') }}- + rebar-lock-path: "./rebar.lock" - name: Run property-based tests run: rebar3 proper -n 1000 From affb6329a9768e2cb3dab045c0bd9eef857d42d0 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:38:11 +0900 Subject: [PATCH 11/12] Update comments --- .github/workflows/create-cache-periodically.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/create-cache-periodically.yml b/.github/workflows/create-cache-periodically.yml index bdf3ea6..0043a49 100644 --- a/.github/workflows/create-cache-periodically.yml +++ b/.github/workflows/create-cache-periodically.yml @@ -1,10 +1,7 @@ # 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. +# 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: @@ -24,7 +21,7 @@ env: rebar3: 3.22.1 jobs: - create-cache: + overwrite-cache: runs-on: ubuntu-22.04 steps: From 1f5fa263b9b4724c96c7cd26d94f263128bf5dc3 Mon Sep 17 00:00:00 2001 From: ajfAfg <56056962+ajfAfg@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:05:20 +0900 Subject: [PATCH 12/12] Update a bit --- .github/actions/setup-beam-with-cache/action.yml | 4 ++-- .github/workflows/ci.yml | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-beam-with-cache/action.yml b/.github/actions/setup-beam-with-cache/action.yml index 6cee60e..8fccf09 100644 --- a/.github/actions/setup-beam-with-cache/action.yml +++ b/.github/actions/setup-beam-with-cache/action.yml @@ -25,7 +25,7 @@ runs: rebar3-version: ${{ inputs.rebar3-version }} - uses: actions/cache@v4 - id: cache + 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) }} @@ -48,7 +48,7 @@ runs: - name: Create cache data shell: bash - if: ${{ steps.cache.outputs.cache-hit != 'true' }} + if: ${{ steps.cache-no-overwrite.outputs.cache-hit != 'true' }} run: | rebar3 compile rebar3 as test compile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a08bce7..6ca38e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,8 +41,6 @@ jobs: rebar3-version: ${{ env.rebar3 }} rebar-lock-path: "./rebar.lock" - - run: ls _build/default - - run: ls ~/.cache/rebar3 - run: rebar3 xref - run: rebar3 dialyzer