Skip to content

test-and-release

test-and-release #9

name: test-and-release
on:
workflow_dispatch:
inputs:
release-version:
required: true
description: 'The version of the release'
default: '0.1.0'
git-ref:
required: true
description: 'The git revison of repo, branch, tag or commit'
default: 'main'
jobs:
tests:
name: Run tests (Elixir ${{matrix.elixir}}, OTP ${{matrix.otp}})
strategy:
matrix:
include:
- elixir: 1.18
otp: 27
lint: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.git-ref }}
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- name: Install dependencies
env:
MIX_ENV: test
run: |
mix deps.get
bun install
- name: Check source code format
run: mix format --check-formatted
if: ${{ matrix.lint }}
- name: Remove compiled application files
run: mix clean
- name: Compile dependencies
run: mix compile
if: ${{ !matrix.lint }}
env:
MIX_ENV: test
- name: Compile & lint dependencies
run: mix compile --warnings-as-errors
if: ${{ matrix.lint }}
env:
MIX_ENV: test
- name: Run tests
run: mix test
release:
name: Publish release to hex.pm
runs-on: ubuntu-latest
needs: [ tests ]
steps:
- name: 🛑 Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.git-ref }}
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: 27
elixir-version: 1.18
- name: Install Deps
env:
MIX_ENV: prod
run: |
mix deps.get
sed -i 's%@version "[0-9\.]\+"%@version "${{ github.event.inputs.release-version }}"%' mix.exs
sed -i 's%{:phoenix_react_server, "~> [0-9\.]\+"}%{:phoenix_react_server, "~> ${{ github.event.inputs.release-version }}"}%' README.md
- name: Publish to hex.pm
env:
MIX_ENV: prod
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
run: |
mix hex.publish --yes
- uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ github.event.inputs.release-version }}',
sha: context.sha
})