Created
June 27, 2021 16:20
-
-
Save bhoggard/6d90a801de75426cd9e73acbc13d84fc to your computer and use it in GitHub Desktop.
GitHub actions to test an Elixir Phoenix application and deploy to Gigalixir
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: CI/CD | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
env: | |
MIX_ENV: test | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
db: | |
image: postgres:12 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: quark_test | |
ports: ['5432:5432'] | |
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup elixir | |
uses: erlef/setup-beam@v1 | |
with: | |
elixir-version: 1.12.1 | |
otp-version: 24.0.2 | |
- name: Setup node | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 14.17.1 | |
- name: Retrieve mix dependencies cache | |
uses: actions/cache@v1 | |
id: mix-cache # id to use in retrieve action | |
with: | |
path: deps | |
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} | |
- name: Install mix dependencies | |
if: steps.mix-cache.outputs.cache-hit != 'true' | |
run: | | |
mix local.rebar --force | |
mix local.hex --force | |
mix deps.get | |
- name: Retrieve npm dependencies cache | |
uses: actions/cache@v2 | |
id: npm-cache # id to use in retrieve action | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install npm dependencies | |
if: steps.npm-cache.outputs.cache-hit != 'true' | |
run: (cd assets && npm install) | |
- name: Test | |
run: | | |
mix format --check-formatted | |
mix credo | |
mix test | |
deploy: | |
needs: test | |
# only run this job if the workflow is running on the main branch | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
# actions/checkout@v2 only checks out the latest commit, | |
# so we need to tell it to check out the entire main branch | |
with: | |
ref: main | |
fetch-depth: 0 | |
# configure the gigalixir-actions with our credentials and app name | |
- uses: mhanberg/gigalixir-action@v0.1.0 | |
with: | |
GIGALIXIR_USERNAME: ${{ secrets.GIGALIXIR_USERNAME }} | |
GIGALIXIR_PASSWORD: ${{ secrets.GIGALIXIR_PASSWORD }} | |
GIGALIXIR_APP: <my-app> | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment