From 5643b69aa747d8b450283c692d8840dc02b08612 Mon Sep 17 00:00:00 2001 From: Krukon Date: Tue, 25 Jun 2024 17:51:00 +0200 Subject: [PATCH 01/11] setup GHA based CI --- .github/workflows/ci.yaml | 134 +++++++++++++++++++++++++++++ .github/workflows/dev-publish.yaml | 39 +++++++++ 2 files changed, 173 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..d7181c1 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,134 @@ +name: Elixir CI Checks + +env: + SHA: ${{ github.sha }} + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + DEBIAN_FRONTEND: noninteractive + REPOSITORY: surgex + ELIXIR_VERSION: 1.11.4 + OTP_VERSION: 23.3.4.7 + RUNNER_OS: ubuntu20 + RELEVANT_FILES: "mix.lock mix.exs lib config test" + DEPENDENCY_FILE: mix.lock + +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.versions.elixir-version }}) + runs-on: runs-on,runner=4cpu-linux-x64 + outputs: + HASH: ${{ steps.prepare.outputs.HASH }} + strategy: + fail-fast: false + matrix: + versions: + - { elixir-version: 1.11.4, otp-version: 23.3.4.7, runner-os: 'ubuntu20' } + steps: + - name: Checkout and compile dependencies + id: prepare + uses: surgeventures/platform-tribe-actions/elixir/precompile@fast-elixir-repo-setup + with: + repository: ${{ env.REPOSITORY }} + dependency-file: ${{ env.DEPENDENCY_FILE }} + sha: ${{ env.SHA }} + token: ${{ secrets.GITHUB_TOKEN }} + hex-token: ${{ secrets.HEX_ORGANIZATION_KEY }} + mix-env: dev + relevant-files: ${{ env.RELEVANT_FILES }} + elixir-version: ${{ matrix.versions.elixir-version }} + otp-version: ${{ matrix.versions.otp-version }} + runner-os: ${{ matrix.versions.runner-os }} + - name: Compile the application + id: compile + uses: surgeventures/platform-tribe-actions/elixir/compile@fast-elixir-repo-setup + with: + build-hash: ${{ steps.prepare.outputs.HASH }} + warnings-as-errors: 'true' + elixir-version: ${{ matrix.versions.elixir-version }} + otp-version: ${{ matrix.versions.otp-version }} + - name: Run Static Checks + uses: surgeventures/platform-tribe-actions/elixir/static-check@fast-elixir-repo-setup + id: static + with: + dialyzer: true + hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + + test: + name: Unit Tests (Elixir ${{ matrix.versions.elixir-version }}) + runs-on: runs-on,runner=1cpu-linux-x64 + strategy: + fail-fast: false + matrix: + versions: + - { elixir-version: 1.11.4, otp-version: 23.3.4.7, runner-os: 'ubuntu20' } + steps: + - name: Checkout and compile dependencies + id: prepare + uses: surgeventures/platform-tribe-actions/elixir/precompile@fast-elixir-repo-setup + with: + repository: ${{ env.REPOSITORY }} + dependency-file: ${{ env.DEPENDENCY_FILE }} + sha: ${{ env.SHA }} + token: ${{ secrets.GITHUB_TOKEN }} + hex-token: ${{ secrets.HEX_ORGANIZATION_KEY }} + mix-env: test + relevant-files: ${{ env.RELEVANT_FILES }} + elixir-version: ${{ matrix.versions.elixir-version }} + otp-version: ${{ matrix.versions.otp-version }} + runner-os: ${{ matrix.versions.runner-os }} + - name: Compile the application + id: compile + uses: surgeventures/platform-tribe-actions/elixir/compile@fast-elixir-repo-setup + with: + build-hash: ${{ steps.prepare.outputs.HASH }} + mix-env: test + elixir-version: ${{ matrix.versions.elixir-version }} + otp-version: ${{ matrix.versions.otp-version }} + - name: Run Unit Tests + uses: surgeventures/platform-tribe-actions/elixir/test@fast-elixir-repo-setup + id: test + + permit: + name: Permit Package Publishing + needs: [static, test] + runs-on: runs-on,runner=1cpu-linux-x64 + outputs: + PUBLISH: ${{ steps.permit.outputs.PUBLISH }} + steps: + - name: Verify elibility for publishing the package + uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup + id: permit + with: + repository: ${{ env.REPOSITORY }} + sha: ${{ env.SHA }} + relevant-files: ${{ env.RELEVANT_FILES}} + + 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: Publish Package + uses: surgeventures/platform-tribe-actions/elixir/publish@fast-elixir-repo-setup + with: + repository: ${{ env.REPOSITORY }} + sha: ${{ env.SHA }} + token: ${{ secrets.GITHUB_TOKEN }} + hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + runner-os: ${{ env.RUNNER_OS }} diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml new file mode 100644 index 0000000..da75ac3 --- /dev/null +++ b/.github/workflows/dev-publish.yaml @@ -0,0 +1,39 @@ +name: Elixir Dev Publish + +env: + DEBIAN_FRONTEND: noninteractive + DEPENDENCY_FILE: mix.lock + ELIXIR_VERSION: 1.11.4 + JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + OTP_VERSION: 23.3.4.7 + RELEVANT_FILES: 'mix.lock mix.exs lib config test' + REPOSITORY: surgex + RUNNER_OS: ubuntu20 + 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: Publish Hex package + uses: surgeventures/platform-tribe-actions/elixir/dev-publish@fast-elixir-repo-setup + with: + repository: ${{ env.REPOSITORY}} + dependency-file: ${{ env.DEPENDENCY_FILE }} + sha: ${{ env.SHA }} + token: ${{ secrets.GITHUB_TOKEN }} + hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + mix-env: dev + elixir-version: ${{ env.ELIXIR_VERSION }} + otp-version: ${{ env.OTP_VERSION }} + runner-os: ${{ env.RUNNER_OS }} + relevant-files: ${{ env.RELEVANT_FILES}} From acc277f630c3b9367f7db8ebd73ccd3388897405 Mon Sep 17 00:00:00 2001 From: Krukon Date: Tue, 25 Jun 2024 17:51:50 +0200 Subject: [PATCH 02/11] correct rel files list --- .github/workflows/ci.yaml | 2 +- .github/workflows/dev-publish.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d7181c1..69de092 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,7 +8,7 @@ env: ELIXIR_VERSION: 1.11.4 OTP_VERSION: 23.3.4.7 RUNNER_OS: ubuntu20 - RELEVANT_FILES: "mix.lock mix.exs lib config test" + RELEVANT_FILES: "mix.lock mix.exs lib priv config test" DEPENDENCY_FILE: mix.lock concurrency: diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index da75ac3..160c039 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -6,7 +6,7 @@ env: ELIXIR_VERSION: 1.11.4 JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} OTP_VERSION: 23.3.4.7 - RELEVANT_FILES: 'mix.lock mix.exs lib config test' + RELEVANT_FILES: 'mix.lock mix.exs lib priv config test' REPOSITORY: surgex RUNNER_OS: ubuntu20 SHA: ${{ github.sha }} From e3a4ae4d641a3206cc9a93fe2ebf686a1598fa6c Mon Sep 17 00:00:00 2001 From: Krukon Date: Tue, 25 Jun 2024 17:53:12 +0200 Subject: [PATCH 03/11] disable dialyzer --- .circleci/config.yml | 37 ------------------------------------- .github/workflows/ci.yaml | 2 +- 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 0485467..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,37 +0,0 @@ -version: 2.1 - -orbs: - elixir-orb: fresha/elixir-orb@0.2 - -workflows: - version: 2 - ci: - jobs: - - elixir-orb/test: - executor: elixir-orb/elixir-postgres - context: Hex - - elixir-orb/static-check: - dialyzer: false - context: Hex - - hold-for-dev-publish: - type: approval - requires: - - elixir-orb/test - - elixir-orb/static-check - filters: - branches: - ignore: - - master - - elixir-orb/dev-publish: - context: Hex - requires: - - hold-for-dev-publish - - elixir-orb/deploy: - context: Hex - requires: - - elixir-orb/test - - elixir-orb/static-check - filters: - branches: - only: - - master diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 69de092..ca31cbe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,7 +63,7 @@ jobs: uses: surgeventures/platform-tribe-actions/elixir/static-check@fast-elixir-repo-setup id: static with: - dialyzer: true + dialyzer: false hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} test: From 1de70eb4cad1a52125cc66cef57d1f70acb5708b Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 13:55:22 +0200 Subject: [PATCH 04/11] use local code only --- .github/workflows/ci.yaml | 224 +++++++++++++++++++++++++------------- 1 file changed, 151 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ca31cbe..ffe16ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,105 +30,183 @@ jobs: name: Static Checks (Elixir ${{ matrix.versions.elixir-version }}) runs-on: runs-on,runner=4cpu-linux-x64 outputs: - HASH: ${{ steps.prepare.outputs.HASH }} + HASH: ${{ steps.hash.outputs.HASH }} strategy: fail-fast: false matrix: versions: - { elixir-version: 1.11.4, otp-version: 23.3.4.7, runner-os: 'ubuntu20' } steps: - - name: Checkout and compile dependencies - id: prepare - uses: surgeventures/platform-tribe-actions/elixir/precompile@fast-elixir-repo-setup + - name: Checkout latest codebase + uses: actions/checkout@v4 with: - repository: ${{ env.REPOSITORY }} - dependency-file: ${{ env.DEPENDENCY_FILE }} - sha: ${{ env.SHA }} - token: ${{ secrets.GITHUB_TOKEN }} - hex-token: ${{ secrets.HEX_ORGANIZATION_KEY }} - mix-env: dev - relevant-files: ${{ env.RELEVANT_FILES }} - elixir-version: ${{ matrix.versions.elixir-version }} - otp-version: ${{ matrix.versions.otp-version }} - runner-os: ${{ matrix.versions.runner-os }} - - name: Compile the application - id: compile - uses: surgeventures/platform-tribe-actions/elixir/compile@fast-elixir-repo-setup + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.versions.runner-os }} with: - build-hash: ${{ steps.prepare.outputs.HASH }} - warnings-as-errors: 'true' elixir-version: ${{ matrix.versions.elixir-version }} otp-version: ${{ matrix.versions.otp-version }} - - name: Run Static Checks - uses: surgeventures/platform-tribe-actions/elixir/static-check@fast-elixir-repo-setup - id: static + 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: - dialyzer: false - hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + path: | + deps + _build/dev + key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-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.versions.elixir-version }}-${{ matrix.versions.otp-version }}-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 credo + run: | + echo "Running credo" + mix credo --strict + - 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.versions.elixir-version }}) - runs-on: runs-on,runner=1cpu-linux-x64 + runs-on: runs-on,runner=2cpu-linux-x64 strategy: fail-fast: false matrix: versions: - { elixir-version: 1.11.4, otp-version: 23.3.4.7, runner-os: 'ubuntu20' } + services: + postgres: + image: postgres:13 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - - name: Checkout and compile dependencies - id: prepare - uses: surgeventures/platform-tribe-actions/elixir/precompile@fast-elixir-repo-setup + - name: Checkout latest codebase + uses: actions/checkout@v4 with: - repository: ${{ env.REPOSITORY }} - dependency-file: ${{ env.DEPENDENCY_FILE }} - sha: ${{ env.SHA }} - token: ${{ secrets.GITHUB_TOKEN }} - hex-token: ${{ secrets.HEX_ORGANIZATION_KEY }} - mix-env: test - relevant-files: ${{ env.RELEVANT_FILES }} - elixir-version: ${{ matrix.versions.elixir-version }} - otp-version: ${{ matrix.versions.otp-version }} - runner-os: ${{ matrix.versions.runner-os }} - - name: Compile the application - id: compile - uses: surgeventures/platform-tribe-actions/elixir/compile@fast-elixir-repo-setup + ref: ${{ env.SHA }} + clean: false + persist-credentials: true + - name: Setup Elixir + uses: erlef/setup-beam@v1 + env: + ImageOS: ${{ matrix.versions.runner-os }} with: - build-hash: ${{ steps.prepare.outputs.HASH }} - mix-env: test elixir-version: ${{ matrix.versions.elixir-version }} otp-version: ${{ matrix.versions.otp-version }} + 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.versions.elixir-version }}-${{ matrix.versions.otp-version }}-precompile-deps-dev-${{ 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.versions.elixir-version }}-${{ matrix.versions.otp-version }}-compile-dev-${{ steps.hash.outputs.HASH }} + - name: Compile with warning as --warnings-as-errors + 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 Unit Tests uses: surgeventures/platform-tribe-actions/elixir/test@fast-elixir-repo-setup id: test - permit: - name: Permit Package Publishing - needs: [static, test] - runs-on: runs-on,runner=1cpu-linux-x64 - outputs: - PUBLISH: ${{ steps.permit.outputs.PUBLISH }} - steps: - - name: Verify elibility for publishing the package - uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup - id: permit - with: - repository: ${{ env.REPOSITORY }} - sha: ${{ env.SHA }} - relevant-files: ${{ env.RELEVANT_FILES}} + # permit: + # name: Permit Package Publishing + # needs: [static, test] + # runs-on: runs-on,runner=1cpu-linux-x64 + # outputs: + # PUBLISH: ${{ steps.permit.outputs.PUBLISH }} + # steps: + # - name: Verify elibility for publishing the package + # uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup + # id: permit + # with: + # repository: ${{ env.REPOSITORY }} + # sha: ${{ env.SHA }} + # relevant-files: ${{ env.RELEVANT_FILES}} - 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: Publish Package - uses: surgeventures/platform-tribe-actions/elixir/publish@fast-elixir-repo-setup - with: - repository: ${{ env.REPOSITORY }} - sha: ${{ env.SHA }} - token: ${{ secrets.GITHUB_TOKEN }} - hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} - elixir-version: ${{ env.ELIXIR_VERSION }} - otp-version: ${{ env.OTP_VERSION }} - runner-os: ${{ env.RUNNER_OS }} + # 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: Publish Package + # uses: surgeventures/platform-tribe-actions/elixir/publish@fast-elixir-repo-setup + # with: + # repository: ${{ env.REPOSITORY }} + # sha: ${{ env.SHA }} + # token: ${{ secrets.GITHUB_TOKEN }} + # hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} + # elixir-version: ${{ env.ELIXIR_VERSION }} + # otp-version: ${{ env.OTP_VERSION }} + # runner-os: ${{ env.RUNNER_OS }} From adfa914ec4214dcd9a6f6c24de0f4c0815c15d8c Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 13:56:09 +0200 Subject: [PATCH 05/11] correct test ref --- .github/workflows/ci.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ffe16ae..16ef6fe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -175,9 +175,10 @@ jobs: run: | echo "Compiling the app with MIX_ENV=test" mix compile --force - - name: Run Unit Tests - uses: surgeventures/platform-tribe-actions/elixir/test@fast-elixir-repo-setup - id: test + - name: Run tests + run: | + echo "Running tests" + mix test --cover # permit: # name: Permit Package Publishing From 9590baa8c15676ea448c8f693193515e7715d0e3 Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 14:02:20 +0200 Subject: [PATCH 06/11] postgress tweaks --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 16ef6fe..f1a9874 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -113,9 +113,10 @@ jobs: postgres: image: postgres:13 env: - POSTGRES_USER: postgres + POSTGRES_USER: root POSTGRES_PASSWORD: postgres POSTGRES_DB: postgres + POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 options: >- From 8dc1bdce4050c2112420a2946d5f4434a332a170 Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 14:09:13 +0200 Subject: [PATCH 07/11] more postgres config --- .github/workflows/ci.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f1a9874..c963cfb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -111,11 +111,12 @@ jobs: - { elixir-version: 1.11.4, otp-version: 23.3.4.7, runner-os: 'ubuntu20' } services: postgres: - image: postgres:13 + image: cimg/postgres:12.9-postgis env: - POSTGRES_USER: root + POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres + POSTGRES_ROLE: root + POSTGRES_DB: root POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 @@ -124,6 +125,11 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + env: + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres steps: - name: Checkout latest codebase uses: actions/checkout@v4 From 9a959eeaabe0b71e6d83cbbf0a18d3296090581f Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 15:27:47 +0200 Subject: [PATCH 08/11] finish copypasting --- .github/workflows/ci.yaml | 137 +++++++++++++++++++++-------- .github/workflows/dev-publish.yaml | 67 ++++++++++---- 2 files changed, 150 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c963cfb..102f40a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,15 +1,15 @@ name: Elixir CI Checks env: - SHA: ${{ github.sha }} - JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} DEBIAN_FRONTEND: noninteractive - REPOSITORY: surgex - ELIXIR_VERSION: 1.11.4 - OTP_VERSION: 23.3.4.7 - RUNNER_OS: ubuntu20 - RELEVANT_FILES: "mix.lock mix.exs lib priv config test" 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: "mix.lock mix.exs lib priv config test" # Important, this controls the caching, make sure to keep this right + REPOSITORY: heartbeats + 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 }} @@ -161,7 +161,7 @@ jobs: path: | deps _build/test - key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-precompile-deps-dev-${{ hashFiles('mix.lock') }} + key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-precompile-deps-test-${{ hashFiles('mix.lock') }} - name: Install dependencies if: steps.deps-cache.outputs.cache-hit != 'true' env: @@ -174,7 +174,7 @@ jobs: id: build-cache with: path: '**/*' - key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-compile-dev-${{ steps.hash.outputs.HASH }} + key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-compile-test-${{ steps.hash.outputs.HASH }} - name: Compile with warning as --warnings-as-errors if: steps.build-cache.outputs.cache-hit != 'true' env: @@ -187,34 +187,93 @@ jobs: 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.permit.outputs.PUBLISH }} - # steps: - # - name: Verify elibility for publishing the package - # uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup - # id: permit - # with: - # repository: ${{ env.REPOSITORY }} - # sha: ${{ env.SHA }} - # relevant-files: ${{ env.RELEVANT_FILES}} + permit: + name: Permit Package Publishing + needs: [static, test] + runs-on: runs-on,runner=1cpu-linux-x64 + outputs: + PUBLISH: ${{ steps.permit.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 "===============================================\n\n" + 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 "\n\n===============================================" + - name: Cache Approval File + uses: runs-on/cache/save@v4 + with: + path: approval.txt + key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ needs.static.outputs.HASH }} + - name: Verify elibility for publishing the package + uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup + id: permit + with: + repository: ${{ env.REPOSITORY }} + sha: ${{ env.SHA }} + relevant-files: ${{ env.RELEVANT_FILES }} - # 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: Publish Package - # uses: surgeventures/platform-tribe-actions/elixir/publish@fast-elixir-repo-setup - # with: - # repository: ${{ env.REPOSITORY }} - # sha: ${{ env.SHA }} - # token: ${{ secrets.GITHUB_TOKEN }} - # hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} - # elixir-version: ${{ env.ELIXIR_VERSION }} - # otp-version: ${{ env.OTP_VERSION }} - # runner-os: ${{ env.RUNNER_OS }} + 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 diff --git a/.github/workflows/dev-publish.yaml b/.github/workflows/dev-publish.yaml index 160c039..a1bb688 100644 --- a/.github/workflows/dev-publish.yaml +++ b/.github/workflows/dev-publish.yaml @@ -3,12 +3,12 @@ name: Elixir Dev Publish env: DEBIAN_FRONTEND: noninteractive DEPENDENCY_FILE: mix.lock - ELIXIR_VERSION: 1.11.4 + 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 - RELEVANT_FILES: 'mix.lock mix.exs lib priv config test' - REPOSITORY: surgex - RUNNER_OS: ubuntu20 + OTP_VERSION: 23.3.4.7 # OTP version used during package publishing + RELEVANT_FILES: "mix.lock mix.exs lib priv config test" # Important, this controls the caching, make sure to keep this right + REPOSITORY: heartbeats + RUNNER_OS: ubuntu20 # Must match Elixir/OTP version in described in action erlef/setup-beam@v1 SHA: ${{ github.sha }} concurrency: @@ -24,16 +24,53 @@ jobs: name: Dev Publish runs-on: runs-on,runner=4cpu-linux-x64 steps: - - name: Publish Hex package - uses: surgeventures/platform-tribe-actions/elixir/dev-publish@fast-elixir-repo-setup + - 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: - repository: ${{ env.REPOSITORY}} - dependency-file: ${{ env.DEPENDENCY_FILE }} - sha: ${{ env.SHA }} - token: ${{ secrets.GITHUB_TOKEN }} - hex-token: ${{ secrets.HEX_ORGANIZATION_WRITE_KEY }} - mix-env: dev elixir-version: ${{ env.ELIXIR_VERSION }} otp-version: ${{ env.OTP_VERSION }} - runner-os: ${{ env.RUNNER_OS }} - relevant-files: ${{ env.RELEVANT_FILES}} + 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 ea501c62d7d115789961a1bfb39a84253a5d88db Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 16:18:36 +0200 Subject: [PATCH 09/11] Cleanup --- .github/workflows/ci.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 102f40a..5e34751 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -234,13 +234,6 @@ jobs: with: path: approval.txt key: ${{ runner.os }}-${{ env.REPOSITORY }}-approval-${{ needs.static.outputs.HASH }} - - name: Verify elibility for publishing the package - uses: surgeventures/platform-tribe-actions/elixir/permit@fast-elixir-repo-setup - id: permit - with: - repository: ${{ env.REPOSITORY }} - sha: ${{ env.SHA }} - relevant-files: ${{ env.RELEVANT_FILES }} publish: name: Publish Hex Package From 18e91d11cf6d5fc5cc7fd8ed9c8f5a792add0ddb Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 16:21:44 +0200 Subject: [PATCH 10/11] correct permit's outputs --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5e34751..a9d2dde 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -175,7 +175,7 @@ jobs: with: path: '**/*' key: ${{ runner.os }}-${{ matrix.versions.elixir-version }}-${{ matrix.versions.otp-version }}-compile-test-${{ steps.hash.outputs.HASH }} - - name: Compile with warning as --warnings-as-errors + - name: Compile with MIX_ENV=test if: steps.build-cache.outputs.cache-hit != 'true' env: MIX_ENV: test @@ -192,7 +192,7 @@ jobs: needs: [static, test] runs-on: runs-on,runner=1cpu-linux-x64 outputs: - PUBLISH: ${{ steps.permit.outputs.PUBLISH }} + PUBLISH: ${{ steps.version.outputs.PUBLISH }} steps: - name: Checkout latest codebase uses: actions/checkout@v4 From a86323e8adf81f27856f02e9093964c2c1b1c2e1 Mon Sep 17 00:00:00 2001 From: Krukon Date: Wed, 26 Jun 2024 16:39:32 +0200 Subject: [PATCH 11/11] nicer echo --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a9d2dde..a441047 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -209,7 +209,8 @@ jobs: shell: bash id: version run: | - echo "===============================================\n\n" + 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) @@ -228,7 +229,8 @@ jobs: echo "PUBLISH=false" >> $GITHUB_OUTPUT echo "Version is unchanged - WONT publish upon merging the PR" fi - echo "\n\n===============================================" + echo "" + echo "===============================================" - name: Cache Approval File uses: runs-on/cache/save@v4 with: