From 11834e0e0f7c410b7424981b80ddc17d2a8dd6c8 Mon Sep 17 00:00:00 2001 From: Krukon Date: Fri, 15 Nov 2024 13:52:39 +0100 Subject: [PATCH 1/4] gha CI for jabbax --- .github/workflows/ci.yaml | 284 +++++++++++++++++++++++++++++ .github/workflows/dev-publish.yaml | 76 ++++++++ 2 files changed, 360 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/dev-publish.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..c140549 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,284 @@ +name: Elixir CI Checks + +env: + DEBIAN_FRONTEND: noninteractive + DEPENDENCY_FILE: mix.lock + ELIXIR_VERSION: 1.10.4 # Elixir version used during package publishing + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + OTP_VERSION: 22.3.4.7 # OTP version used during package publishing + RELEVANT_FILES: "benchmark config examples interop lib priv src test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + REPOSITORY: jabbax + RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 + SHA: ${{ github.sha }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - master + pull_request: + types: + - synchronize + - opened + - reopened + +jobs: + static: + name: Static Checks (Elixir ${{ matrix.elixir }} & OTP ${{ matrix.otp }}) + runs-on: runs-on,runner=2cpu-linux-x64 + outputs: + HASH: ${{ steps.hash.outputs.HASH }} + strategy: + fail-fast: false + matrix: + otp: [21.3.8.24, 22.3.4.7] + elixir: [1.10.4] + runner-os: [ubuntu20] + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.runner-os }} + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + version-type: strict + - name: Get SHA sum (HASH) of relevant files + id: hash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + - uses: runs-on/cache@v4 + id: deps-cache + with: + path: | + deps + _build/dev + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-precompile-deps-dev-${{ hashFiles('mix.lock') }} + - name: Install dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: dev + run: | + echo "Installing dependencies" + mix deps.get + mix deps.compile + - uses: runs-on/cache@v4 + id: build-cache + with: + path: '**/*' + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-compile-dev-${{ steps.hash.outputs.HASH }} + - name: Compile with warning as --warnings-as-errors + if: steps.build-cache.outputs.cache-hit != 'true' + run: | + echo "Compiling the app with --warnings-as-errors" + mix compile --warnings-as-errors --force + - name: Run format + run: | + echo "Running format" + mix format --check-formatted --dry-run + - name: Run publish --dry-run + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Running publish --dry-run" + mix hex.publish --dry-run + test: + name: Unit Tests (Elixir ${{ matrix.elixir }} & OTP ${{ matrix.otp }}) + runs-on: runs-on,runner=2cpu-linux-x64 + strategy: + fail-fast: false + matrix: + otp: [21.3.8.24, 22.3.4.7] + elixir: [1.10.4] + runner-os: [ubuntu20] + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.runner-os }} + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + version-type: strict + - name: Get SHA sum (HASH) of relevant files + id: hash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + - uses: runs-on/cache@v4 + id: deps-cache + with: + path: | + deps + _build/test + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-precompile-deps-test-${{ hashFiles('mix.lock') }} + - name: Install dependencies + if: steps.deps-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: test + run: | + echo "Installing dependencies" + mix deps.get + mix deps.compile + - uses: runs-on/cache@v4 + id: build-cache + with: + path: '**/*' + key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-compile-test-${{ steps.hash.outputs.HASH }} + - name: Compile with MIX_ENV=test + if: steps.build-cache.outputs.cache-hit != 'true' + env: + MIX_ENV: test + run: | + echo "Compiling the app with MIX_ENV=test" + mix compile --force + - name: Run tests + run: | + echo "Running tests" + mix test --cover + permit: + name: Permit Package Publishing + needs: [static, test] + runs-on: runs-on,runner=1cpu-linux-x64 + outputs: + PUBLISH: ${{ steps.version.outputs.PUBLISH }} + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + fetch-depth: 2 + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Create Approval File + shell: bash + run: | + echo "CI Checks Passed for SHA ${{ env.SHA }} and HASH ${{ needs.static.outputs.HASH }}" > approval.txt + - name: Process Package Version + shell: bash + id: version + run: | + echo "===============================================" + echo "" + git show HEAD~1:mix.exs > mix.old.exs + diff mix.old.exs mix.exs > diff.txt || true + old_version=$(grep -oP 'version: "\K[^"]+' mix.old.exs) + new_version=$(grep -oP 'version: "\K[^"]+' mix.exs) + echo "Old Version: $old_version | New Version: $new_version" + if [ "$new_version" != "$old_version" ]; then + if [ "$new_version" \> "$old_version" ]; then + echo "Version is upped - WILL publish upon merging the PR" + echo "PUBLISH=true" >> $GITHUB_OUTPUT + else + echo "Version is lower than the original version - blocking publication" + echo "PUBLISH=false" >> $GITHUB_OUTPUT + exit 1 + fi + else + echo "PUBLISH=false" >> $GITHUB_OUTPUT + echo "Version is unchanged - WONT publish upon merging the PR" + fi + echo "" + echo "===============================================" + - name: Cache Approval File + uses: runs-on/cache/save@v4 + with: + path: approval.txt + key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ needs.static.outputs.HASH }} + + publish: + name: Publish Hex Package + needs: [permit] + runs-on: runs-on,runner=2cpu-linux-x64 + if: needs.permit.outputs.PUBLISH == 'true' && github.event_name == 'push' + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ env.RUNNER_OS }} + with: + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + version-type: strict + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + shell: bash + - name: Get dependencies + shell: bash + run: | + echo "Getting dependencies" + mix deps.get + - name: Publish dev package + shell: bash + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Publishing package" + mix hex.publish --yes + + + interop-tests: + runs-on: runs-on,runner=2cpu-linux-x64 + name: Interop tests + container: + image: elixir:1.10-slim + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + working-directory: ./interop + - name: Run interop tests + run: mix run script/run.exs + working-directory: ./interop + + check_release: + runs-on: runs-on,runner=2cpu-linux-x64 + name: Check release + container: + image: elixir:1.10-slim + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + - name: Build hex + run: mix hex.build + - name: Generate docs + run: mix docs \ No newline at end of file diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml new file mode 100644 index 0000000..315a4bb --- /dev/null +++ b/.github/workflows/dev-publish.yaml @@ -0,0 +1,76 @@ +name: Elixir Dev Publish + +env: + DEBIAN_FRONTEND: noninteractive + DEPENDENCY_FILE: mix.lock + ELIXIR_VERSION: 1.11.4 # Elixir version used during package publishing + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + OTP_VERSION: 23.3.4.7 # OTP version used during package publishing + RELEVANT_FILES: "benchmark config examples interop lib priv src test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + REPOSITORY: jabbax + RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 + SHA: ${{ github.sha }} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_dispatch: + inputs: {} + +jobs: + dev-publish: + name: Dev Publish + runs-on: runs-on,runner=4cpu-linux-x64 + steps: + - name: Checkout latest codebase + uses: actions/checkout@v4 + with: + ref: ${{ env.sha }} + clean: false + persist-credentials: true + - name: Get SHA sum (HASH) of relevant files + id: hash + shell: bash + run: | + git config --global --add safe.directory /__w/${{ env.REPOSITORY }}/${{ env.REPOSITORY }} + echo "Get SHA sum (HASH) of relevant files" + HASH="$(git ls-tree ${{ env.SHA }} -- ${{ env.RELEVANT_FILES }} | sha1sum | cut -d' ' -f1)" + echo "BUILD HASH FOR THE CODEBASE IS: $HASH" + echo "IT WILL BE USED TO DETERMINE ELIGIBILITY OF THE CODEBASE FOR THE RELEASE" + echo "APPROVAL PRODUCED BY SUCCESSFULL CHECKS EXECUTION WILL LAND IN CACHE" + echo "HASH=$HASH" >> $GITHUB_OUTPUT + - name: Check for CI successes + uses: runs-on/cache/restore@v4 + with: + key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ steps.hash.outputs.HASH }} + path: approval.txt + fail-on-cache-miss: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ env.RUNNER_OS }} + with: + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + version-type: strict + - name: Hex auth + run: mix hex.organization auth fresha --key ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + shell: bash + - name: Get dependencies + shell: bash + run: | + echo "Getting dependencies" + mix deps.get + - name: Mark package version with dev suffix + shell: bash + run: | + sed -i "s/version: \"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/&-git-$(git rev-parse --verify --short=4 HEAD)/" mix.exs + - name: Publish dev package + shell: bash + env: + HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + run: | + echo "Publishing dev package" + mix hex.publish --yes \ No newline at end of file From 31a281694423317e06cf0b4c9e9c2da181f305e2 Mon Sep 17 00:00:00 2001 From: Krukon Date: Fri, 15 Nov 2024 13:55:44 +0100 Subject: [PATCH 2/4] used OTP versions tweaks --- .github/workflows/ci.yaml | 23 +++-------------------- .github/workflows/dev-publish.yaml | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c140549..64aa7df 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ env: ELIXIR_VERSION: 1.10.4 # Elixir version used during package publishing JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 22.3.4.7 # OTP version used during package publishing - RELEVANT_FILES: "benchmark config examples interop lib priv src test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right REPOSITORY: jabbax RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 SHA: ${{ github.sha }} @@ -34,7 +34,7 @@ jobs: strategy: fail-fast: false matrix: - otp: [21.3.8.24, 22.3.4.7] + otp: [22.3.4.7] elixir: [1.10.4] runner-os: [ubuntu20] steps: @@ -103,7 +103,7 @@ jobs: strategy: fail-fast: false matrix: - otp: [21.3.8.24, 22.3.4.7] + otp: [22.3.4.7] elixir: [1.10.4] runner-os: [ubuntu20] steps: @@ -249,23 +249,6 @@ jobs: mix hex.publish --yes - interop-tests: - runs-on: runs-on,runner=2cpu-linux-x64 - name: Interop tests - container: - image: elixir:1.10-slim - steps: - - uses: actions/checkout@v4 - - name: Install Dependencies - run: | - mix local.rebar --force - mix local.hex --force - mix deps.get - working-directory: ./interop - - name: Run interop tests - run: mix run script/run.exs - working-directory: ./interop - check_release: runs-on: runs-on,runner=2cpu-linux-x64 name: Check release diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index 315a4bb..3173558 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -6,7 +6,7 @@ env: ELIXIR_VERSION: 1.11.4 # Elixir version used during package publishing JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 23.3.4.7 # OTP version used during package publishing - RELEVANT_FILES: "benchmark config examples interop lib priv src test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right + RELEVANT_FILES: "config lib test mix.exs mix.lock" # Important, this controls the caching, make sure to keep this right REPOSITORY: jabbax RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 SHA: ${{ github.sha }} From d49380b2e240c5389af4ca872fda61ea6c605ce6 Mon Sep 17 00:00:00 2001 From: Krukon Date: Fri, 15 Nov 2024 14:05:54 +0100 Subject: [PATCH 3/4] plug the plug --- .github/workflows/ci.yaml | 2 +- .github/workflows/dev-publish.yaml | 2 +- mix.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 64aa7df..587133c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -264,4 +264,4 @@ jobs: - name: Build hex run: mix hex.build - name: Generate docs - run: mix docs \ No newline at end of file + run: mix docs diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index 3173558..4e22bb7 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -73,4 +73,4 @@ jobs: HEX_API_KEY: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} run: | echo "Publishing dev package" - mix hex.publish --yes \ No newline at end of file + mix hex.publish --yes diff --git a/mix.exs b/mix.exs index 8ffa9f4..258b150 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule Jabbax.Mixfile do end def application do - [extra_applications: [:logger], env: [json_encoder: Poison, json_decoder: Poison]] + [extra_applications: [:logger, :plug], env: [json_encoder: Poison, json_decoder: Poison]] end defp deps do From 4b01eb778fa49b3fb5b0a2695af8103602091dfe Mon Sep 17 00:00:00 2001 From: Krukon Date: Fri, 15 Nov 2024 14:10:20 +0100 Subject: [PATCH 4/4] replug the plug --- mix.exs | 2 +- test/test_helper.exs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 258b150..8ffa9f4 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,7 @@ defmodule Jabbax.Mixfile do end def application do - [extra_applications: [:logger, :plug], env: [json_encoder: Poison, json_decoder: Poison]] + [extra_applications: [:logger], env: [json_encoder: Poison, json_decoder: Poison]] end defp deps do diff --git a/test/test_helper.exs b/test/test_helper.exs index 869559e..0d8ab2e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1 +1,2 @@ ExUnit.start() +{:ok, _} = Application.ensure_all_started(:plug)