Update README.md #112
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Multi-project CI/CD | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
setup: | |
name: Set up projects | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set matrix | |
id: set-matrix | |
run: | | |
MATRIX=$(echo $(cat .github/workflows/matrix.json) | sed 's/ //g' ) | |
echo "::set-output name=matrix::$MATRIX" | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
build: | |
name: Build and test "${{ matrix.project.directory }}" | |
needs: [ setup ] | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.setup.outputs.matrix) }} | |
services: | |
db: | |
image: postgres:11 | |
ports: [ '5432:5432' ] | |
env: | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
defaults: | |
run: | |
working-directory: ${{ matrix.project.directory }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Elixir | |
uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24 | |
with: | |
elixir-version: '1.11.3' | |
otp-version: '23.2' | |
- name: Restore dependencies cache | |
uses: actions/cache@v2 | |
with: | |
path: deps | |
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} | |
restore-keys: ${{ runner.os }}-mix- | |
- name: Install dependencies | |
run: mix deps.get | |
- name: Check formatting | |
run: mix format --check-formatted | |
- name: Compile code | |
env: | |
MIX_ENV: test | |
run: mix compile | |
- name: Analyze code | |
if: matrix.project.analyze | |
env: | |
MIX_ENV: test | |
run: mix credo --strict | |
- name: Run tests | |
env: | |
MIX_ENV: test | |
run: mix test | |
- name: Generate coverage report | |
if: matrix.project.cover | |
env: | |
MIX_ENV: test | |
run: mix coveralls.json | |
- name: Upload coverage to Codecov | |
if: matrix.project.cover | |
uses: codecov/codecov-action@v1 | |
with: | |
fail_ci_if_error: true | |
flags: ${{ matrix.project.flag }} | |
token: ${{ secrets.CODECOV_TOKEN }} | |
deploy: | |
name: Deploy release "${{ matrix.project.directory }}" | |
needs: [ setup, build ] | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.setup.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v2 | |
if: matrix.project.deploy | |
with: | |
fetch-depth: 0 | |
ref: main | |
- name: Set up Python | |
if: matrix.project.deploy | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8.1 | |
- name: Deploying to Gigalixir | |
if: matrix.project.deploy | |
uses: mhanberg/gigalixir-action@v0.6.0 | |
with: | |
APP_SUBFOLDER: ${{ matrix.project.directory }} | |
GIGALIXIR_APP: ${{ matrix.project.app }} | |
GIGALIXIR_CLEAN: true | |
GIGALIXIR_USERNAME: ${{ secrets.GIGALIXIR_USERNAME }} | |
GIGALIXIR_PASSWORD: ${{ secrets.GIGALIXIR_PASSWORD }} | |
MIGRATIONS: true | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |