Skip to content

Commit

Permalink
feat: melhora o CI
Browse files Browse the repository at this point in the history
- adiciona Earthfile
- publica imagens docker no ghcr
- multistage build and test
  • Loading branch information
Zoey de Souza Pessanha committed Jul 27, 2023
1 parent e078afa commit 80ddf5e
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 333 deletions.
28 changes: 28 additions & 0 deletions .earthlyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Ignore git, but keep git HEAD and refs to access current commit hash if needed
.git
!.git/HEAD
!.git/refs
.github

.elixir_ls
.vscode

# Mix artifacts
/_build/
/deps/
*.ez

# Generated on crash by the VM
erl_crash.dump

# Static artifacts - These should be fetched and built inside the Docker image
/apps/plataforma_digital/assets/node_modules/
/apps/plataforma_digital/priv/static/assets/
/apps/plataforma_digital/priv/static/cache_manifest.json

# Nix artifacts
/.postgres/
/.direnv/
/.nix-*/
result

34 changes: 34 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: docker

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
env:
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run test and build
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} --push +docker
109 changes: 24 additions & 85 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,33 @@ name: lint

on:
push:
branches: ["main"]
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
format:
build:
runs-on: ubuntu-latest
env:
MIX_ENV: test
strategy:
matrix:
elixir: [1.14.2]
otp: [25.1.2.1]
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.sha }}

- name: Setup
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Retrieve Cached Dependencies
uses: actions/cache@v3
id: mix-cache
env:
cache-name: mix-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}
- run: mix deps.get

- name: Run Formater
run: mix format --check-formatted

static_code_analysis:
runs-on: ubuntu-latest
env:
MIX_ENV: test
strategy:
matrix:
elixir: [1.14.2]
otp: [25.1.2.1]
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.sha }}

- name: Setup
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Retrieve Cached Dependencies
uses: actions/cache@v3
id: mix-cache
env:
cache-name: mix-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}
- run: mix deps.get

- name: Run Credo
run: mix credo --strict
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run lint
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +ci
141 changes: 26 additions & 115 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,35 @@ name: test

on:
push:
branches: ["main"]
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
unit_tests:
build:
runs-on: ubuntu-latest
env:
MIX_ENV: test
DATABASE_USER: pescarte
DATABASE_PASSWORD: pescarte
strategy:
matrix:
elixir: [1.14.2]
otp: [25.1.2.1]
services:
db:
env:
POSTGRES_USER: pescarte
POSTGRES_PASSWORD: pescarte
POSTGRES_DB: pescarte_test
image: postgres:13.5
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
GHCR_USERNAME: ${{ github.actor }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
FORCE_COLOR: 1
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.sha }}

- name: Setup
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Retrieve Cached Dependencies
uses: actions/cache@v3
id: mix-cache
env:
cache-name: mix-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}
- run: mix deps.get

- name: Run Unit Tests
run: mix test --only unit

integration_tests:
runs-on: ubuntu-latest
env:
MIX_ENV: test
DATABASE_USER: pescarte
DATABASE_PASSWORD: pescarte
strategy:
matrix:
elixir: [1.14.2]
otp: [25.1.2.1]
services:
db:
env:
POSTGRES_USER: pescarte
POSTGRES_PASSWORD: pescarte
POSTGRES_DB: pescarte_test
image: postgres:13.5
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.sha }}

- name: Setup
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}

- name: Retrieve Cached Dependencies
uses: actions/cache@v3
id: mix-cache
env:
cache-name: mix-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}
- run: mix deps.get

- name: Run Integration Tests
run: mix test --only integration
- uses: actions/checkout@v3
- name: Put back the git branch into git (Earthly uses it for tagging)
run: |
branch=""
if [ -n "$GITHUB_HEAD_REF" ]; then
branch="$GITHUB_HEAD_REF"
else
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Docker Login
run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN"
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run unit tests
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +unit-test
- name: Run integration tests
run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +integration-test
Loading

0 comments on commit 80ddf5e

Please sign in to comment.