From 80e6bbb7e9ada95254c13e251cc27881a11980c0 Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Thu, 6 Jul 2023 17:57:30 +0200 Subject: [PATCH 1/8] [add] gha test file --- .github/workflows/ci.yml | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5d9c24e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,88 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + elixir: + uses: primait/shared-github-actions/.github/workflows/elixir-ci.yml@elixir-ci-v2 + with: + elixir-version: "1.13.4-otp-25" + otp-version: "25.3" + enable-tests: false + + redact_ex: + runs-on: [self-hosted, k8s-medium] + env: + MIX_ENV: test + strategy: + # Specify the OTP and Elixir versions to use when building + # and running the workflow steps. + matrix: + otp: ['25.0.4'] # Define the OTP version [required] + elixir: ['1.14.3'] # Define the elixir version [required] + steps: + # Check out the code. + - name: Checkout + uses: actions/checkout@v3 + # Define how to cache deps. Restores existing cache if present. + - name: Cache deps + id: cache-deps + uses: actions/cache@v3 + env: + cache-name: cache-elixir-deps + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + # Define how to cache the `_build` directory. After the first run, + # this speeds up tests runs a lot. This includes not re-compiling our + # project's downloaded deps every run. + - name: Cache compiled build + id: cache-build + uses: actions/cache@v3 + env: + cache-name: cache-compiled-build + with: + path: _build + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + ${{ runner.os }}-mix- + # Get dependencies + - name: Deps get + run: mix deps.get + # Experimental: compile without warnings (throw it away if macro magic creates problems) + - name: Compiles without warnings + run: mix compile --warnings-as-errors + # Check Format + - name: Check Formatting + run: mix format --check-formatted + - name: Test + run: mix test + + alls-green: + if: always() + + needs: + - redact_ex + - elixir + runs-on: [self-hosted, k8s-small] + container: + image: public.ecr.aws/prima/python:3.9.10-3 + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} From c431a662675f03a9019c7872df31bd476ce194e7 Mon Sep 17 00:00:00 2001 From: Eugenio Laghi Date: Thu, 31 Aug 2023 14:26:58 +0200 Subject: [PATCH 2/8] dummy From cb592d0e5e513a86af475eea454a3ea15b9df78f Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Fri, 15 Sep 2023 15:45:10 +0200 Subject: [PATCH 3/8] [add] playing with elixir tests --- .github/workflows/ci.yml | 144 ++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 76 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d9c24e..618e187 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,80 +9,72 @@ on: - master jobs: - elixir: - uses: primait/shared-github-actions/.github/workflows/elixir-ci.yml@elixir-ci-v2 - with: - elixir-version: "1.13.4-otp-25" - otp-version: "25.3" - enable-tests: false - - redact_ex: - runs-on: [self-hosted, k8s-medium] - env: - MIX_ENV: test - strategy: - # Specify the OTP and Elixir versions to use when building - # and running the workflow steps. - matrix: - otp: ['25.0.4'] # Define the OTP version [required] - elixir: ['1.14.3'] # Define the elixir version [required] - steps: - # Check out the code. - - name: Checkout - uses: actions/checkout@v3 - # Define how to cache deps. Restores existing cache if present. - - name: Cache deps - id: cache-deps - uses: actions/cache@v3 - env: - cache-name: cache-elixir-deps - with: - path: deps - key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - - name: Setup Elixir - uses: erlef/setup-beam@v1 - with: - otp-version: ${{matrix.otp}} - elixir-version: ${{matrix.elixir}} - # Define how to cache the `_build` directory. After the first run, - # this speeds up tests runs a lot. This includes not re-compiling our - # project's downloaded deps every run. - - name: Cache compiled build - id: cache-build - uses: actions/cache@v3 - env: - cache-name: cache-compiled-build + redact_ex: + runs-on: [self-hosted, k8s-medium] + env: + MIX_ENV: test + strategy: + # Specify the OTP and Elixir versions to use when building + # and running the workflow steps. + matrix: + otp: ['25.0.4'] # Define the OTP version [required] + elixir: ['1.14.3'] # Define the elixir version [required] + steps: + # Check out the code. + - name: Checkout + uses: actions/checkout@v3 + # Define how to cache deps. Restores existing cache if present. + - name: Cache deps + id: cache-deps + uses: actions/cache@v3 + env: + cache-name: cache-elixir-deps + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + # Define how to cache the `_build` directory. After the first run, + # this speeds up tests runs a lot. This includes not re-compiling our + # project's downloaded deps every run. + - name: Cache compiled build + id: cache-build + uses: actions/cache@v3 + env: + cache-name: cache-compiled-build + with: + path: _build + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + ${{ runner.os }}-mix- + # Get dependencies + - name: Deps get + run: mix deps.get + # Experimental: compile without warnings (throw it away if macro magic creates problems) + - name: Compiles without warnings + run: mix compile --warnings-as-errors + # Check Format + - name: Check Formatting + run: mix format --check-formatted + - name: Test + run: mix test + + alls-green: + if: always() + + needs: + - redact_ex + runs-on: [self-hosted, k8s-small] + container: + image: public.ecr.aws/prima/python:3.9.10-3 + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 with: - path: _build - key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix-${{ env.cache-name }}- - ${{ runner.os }}-mix- - # Get dependencies - - name: Deps get - run: mix deps.get - # Experimental: compile without warnings (throw it away if macro magic creates problems) - - name: Compiles without warnings - run: mix compile --warnings-as-errors - # Check Format - - name: Check Formatting - run: mix format --check-formatted - - name: Test - run: mix test - - alls-green: - if: always() - - needs: - - redact_ex - - elixir - runs-on: [self-hosted, k8s-small] - container: - image: public.ecr.aws/prima/python:3.9.10-3 - steps: - - name: Decide whether the needed jobs succeeded or failed - uses: re-actors/alls-green@release/v1 - with: - jobs: ${{ toJSON(needs) }} + jobs: ${{ toJSON(needs) }} From ebbeadf42a25b641c1ceb153ff67e30af627c8b1 Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Fri, 15 Sep 2023 16:02:15 +0200 Subject: [PATCH 4/8] [change] do we really need self hosted here? --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 618e187..8ce5d45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,8 @@ on: jobs: redact_ex: - runs-on: [self-hosted, k8s-medium] + # runs-on: [self-hosted, k8s-medium] + runs-on: ubuntu-latest env: MIX_ENV: test strategy: From 25b14e9696bc8d2958502506bb9774d9e1637f35 Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Fri, 15 Sep 2023 16:17:09 +0200 Subject: [PATCH 5/8] [add] more check steps --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ce5d45..1d8f7e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,21 +57,28 @@ jobs: # Get dependencies - name: Deps get run: mix deps.get + - name: Dependencies Check + run: mix deps.unlock --check-unused # Experimental: compile without warnings (throw it away if macro magic creates problems) - name: Compiles without warnings run: mix compile --warnings-as-errors # Check Format - name: Check Formatting run: mix format --check-formatted + - name: Credo + run: mix credo -a --strict - name: Test run: mix test + - name: Dialyzer + run: mix dialyzer alls-green: if: always() needs: - redact_ex - runs-on: [self-hosted, k8s-small] + # runs-on: [self-hosted, k8s-small] + runs-on: ubuntu-latest container: image: public.ecr.aws/prima/python:3.9.10-3 steps: From 7fc1de00947258f04790f3d78537bfd541e9b2aa Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Fri, 15 Sep 2023 17:07:42 +0200 Subject: [PATCH 6/8] [add] publish step --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d8f7e1..8d0e604 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: - master jobs: - redact_ex: + test: # runs-on: [self-hosted, k8s-medium] runs-on: ubuntu-latest env: @@ -71,12 +71,49 @@ jobs: run: mix test - name: Dialyzer run: mix dialyzer - + + publish: + name: Publish to hex.pm + needs: test + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + steps: + - name: Setup Elixir + uses: erlef/setup-beam@v1 + # TODO optimize here to be in sync with the matrix above? + with: + otp-version: 25.0.4 + elixir-version: 1.14.3 + - name: Checkout + uses: actions/checkout@v3 + - name: setup hex + run: | + mix mix local.hex --force + mix local.rebar --force + - name: get deps + run: mix deps.get + - name: get tag + run: | + REDACT_EX_VERSION_REPO=$(grep -m1 version mix.exs | cut -d'"' -f2) + echo "REDACT_EX_VERSION_REPO=$REDACT_EX_VERSION_REPO" >> $GITHUB_ENV + - name: check tags + if: github.ref_tag != ${{ env.REDACT_EX_VERSION_REPO }} + run: | + echo "Github ref tag [${{ github.ref_tag }}] is different from mix.exs version [${{ env.REDACT_EX_VERSION_REPO }}]" + exit 1 + - name: Login to hex.pm + run: | + mix hex.config api_key "$HEX_AUTH_KEY" + env: + HEX_AUTH_KEY: ${{ secrets.HEX_AUTH_KEY }} + - name: Publish + run: mix hex.publish --yes + alls-green: if: always() - needs: - - redact_ex + - test + - publish # runs-on: [self-hosted, k8s-small] runs-on: ubuntu-latest container: From 9a8303a7e72052c1cd07cbc5d2878dcd6872da0e Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Fri, 15 Sep 2023 17:26:18 +0200 Subject: [PATCH 7/8] [change] separate CI and CD workflows --- .github/workflows/cd.yml | 39 +++++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 40 ---------------------------------------- 2 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/cd.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..d0acf96 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,39 @@ +name: CD + +on: + release: + types: [published] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: 25.0.4 + elixir-version: 1.14.3 + - name: Checkout + uses: actions/checkout@v3 + - name: setup hex + run: | + mix mix local.hex --force + mix local.rebar --force + - name: get deps + run: mix deps.get + - name: get tag + run: | + REDACT_EX_VERSION_REPO=$(grep -m1 version mix.exs | cut -d'"' -f2) + echo "REDACT_EX_VERSION_REPO=$REDACT_EX_VERSION_REPO" >> $GITHUB_ENV + - name: check tags + if: github.ref_tag != ${{ env.REDACT_EX_VERSION_REPO }} + run: | + echo "Github ref tag [${{ github.ref_tag }}] is different from mix.exs version [${{ env.REDACT_EX_VERSION_REPO }}]" + exit 1 + - name: Login to hex.pm + run: | + mix hex.config api_key "$HEX_AUTH_KEY" + env: + HEX_AUTH_KEY: ${{ secrets.HEX_AUTH_KEY }} + - name: Publish + run: mix hex.publish --yes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d0e604..9af9563 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,6 @@ on: jobs: test: - # runs-on: [self-hosted, k8s-medium] runs-on: ubuntu-latest env: MIX_ENV: test @@ -72,49 +71,10 @@ jobs: - name: Dialyzer run: mix dialyzer - publish: - name: Publish to hex.pm - needs: test - if: github.ref_type == 'tag' - runs-on: ubuntu-latest - steps: - - name: Setup Elixir - uses: erlef/setup-beam@v1 - # TODO optimize here to be in sync with the matrix above? - with: - otp-version: 25.0.4 - elixir-version: 1.14.3 - - name: Checkout - uses: actions/checkout@v3 - - name: setup hex - run: | - mix mix local.hex --force - mix local.rebar --force - - name: get deps - run: mix deps.get - - name: get tag - run: | - REDACT_EX_VERSION_REPO=$(grep -m1 version mix.exs | cut -d'"' -f2) - echo "REDACT_EX_VERSION_REPO=$REDACT_EX_VERSION_REPO" >> $GITHUB_ENV - - name: check tags - if: github.ref_tag != ${{ env.REDACT_EX_VERSION_REPO }} - run: | - echo "Github ref tag [${{ github.ref_tag }}] is different from mix.exs version [${{ env.REDACT_EX_VERSION_REPO }}]" - exit 1 - - name: Login to hex.pm - run: | - mix hex.config api_key "$HEX_AUTH_KEY" - env: - HEX_AUTH_KEY: ${{ secrets.HEX_AUTH_KEY }} - - name: Publish - run: mix hex.publish --yes - alls-green: if: always() needs: - test - - publish - # runs-on: [self-hosted, k8s-small] runs-on: ubuntu-latest container: image: public.ecr.aws/prima/python:3.9.10-3 From b18c676743b07611654153b9b81cf32ad236101e Mon Sep 17 00:00:00 2001 From: Luca Dei Zotti Date: Mon, 18 Sep 2023 15:42:43 +0200 Subject: [PATCH 8/8] [add] wipe cache on failed builds Thanks @MaeIsBad --- .github/workflows/ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9af9563..ad4fd54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,6 +53,18 @@ jobs: restore-keys: | ${{ runner.os }}-mix-${{ env.cache-name }}- ${{ runner.os }}-mix- + # Conditionally bust the cache when job is re-run. + # Sometimes, we may have issues with incremental builds that are fixed by + # doing a full recompile. In order to not waste dev time on such trivial + # issues (while also reaping the time savings of incremental builds for + # *most* day-to-day development), force a full recompile only on builds + # that are retried. + # https://fly.io/docs/elixir/advanced-guides/github-actions-elixir-ci-cd/ + - name: Clean to rule out incremental build as a source of flakiness + if: github.run_attempt != '1' + run: | + mix deps.clean --all + mix clean # Get dependencies - name: Deps get run: mix deps.get