Skip to content

Setup gha based ci

Setup gha based ci #3

Workflow file for this run

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
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.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 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.versions.runner-os }}
with:
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/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=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 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.versions.runner-os }}
with:
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 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.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 }}