diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ad9abbc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,128 @@ +--- +# based on: +# 1. https://dev.to/mnishiguchi/basic-github-actions-setup-for-phoenix-apps-m3g +# 2. https://www.jonathanyeong.com/garden/how-to-setup-ci-with-phoenix-github-actions/ +name: CI + +on: + push: + branches: [main] + pull_request: + brances: [main] + +env: + MIX_ENV: test + +jobs: + dependencies: + runs-on: ubuntu-20.04 + strategy: + matrix: + elixir: ['1.12.1'] + otp: ['24.0.2'] + steps: + - name: cancel previous execution + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: checkout repo + uses: actions/checkout@v2 + - name: setup erlang/elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + - name: fecth cached dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + priv/plts + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + - name: install dependencies + if: steps.mix-cache.outputs.cache-hit != 'true' + run: | + mkdir -p priv/plts + mix local.rebar --force + mix local.hex --force + mix deps.get + mix deps.compile + mix dialyzer --plt + static-code-analysis: + needs: dependencies + runs-on: ubuntu-20.04 + strategy: + matrix: + elixir: ['1.12.1'] + otp: ['24.0.2'] + steps: + - name: cancel previous execution + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: checkout repo + uses: actions/checkout@v2 + - name: setup erlang/elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + - name: fecth cached dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + priv/plts + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + - run: mix format --check-formatted + - run: mix credo --strict --format flycheck + - run: mix dialyzer --no-check --quiet --ignore-exit-status --format short + test: + needs: dependencies + runs-on: ubuntu-20.04 + strategy: + matrix: + elixir: ['1.12.1'] + otp: ['24.0.2'] + services: + db: + image: 'postgres:13.3-alpine' + ports: + - '5432:5432' + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - name: cancel previous execution + uses: styfle/cancel-workflow-action@0.9.0 + with: + access_token: ${{ github.token }} + - name: checkout repo + uses: actions/checkout@v2 + - name: setup erlang/elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir }} + otp-version: ${{ matrix.otp }} + - name: fecth cached dependencies + uses: actions/cache@v2 + id: mix-cache + with: + path: | + deps + _build + priv/plts + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }} + - run: mix test --cover --trace --slowest 10 + env: + POSTGRES_USER: postgres + POSTGRES_PASS: postgres