|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release-version: |
| 7 | + required: true |
| 8 | + description: 'The version of the release' |
| 9 | + default: '0.1.0' |
| 10 | + git-ref: |
| 11 | + required: true |
| 12 | + description: 'The git revison of repo, branch, tag or commit' |
| 13 | + default: 'main' |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + tests: |
| 20 | + name: Run tests (Elixir ${{matrix.elixir}}, OTP ${{matrix.otp}}) |
| 21 | + |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - elixir: 1.18 |
| 26 | + otp: 27 |
| 27 | + lint: lint |
| 28 | + |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + env: |
| 32 | + MIX_ENV: test |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + ref: ${{ github.event.inputs.git-ref }} |
| 39 | + |
| 40 | + - name: Set up Elixir |
| 41 | + uses: erlef/setup-beam@v1 |
| 42 | + with: |
| 43 | + otp-version: ${{ matrix.otp }} |
| 44 | + elixir-version: ${{ matrix.elixir }} |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + run: mix deps.get |
| 48 | + |
| 49 | + - name: Check source code format |
| 50 | + run: mix format --check-formatted |
| 51 | + |
| 52 | + - name: Remove compiled application files |
| 53 | + run: mix clean |
| 54 | + |
| 55 | + - name: Compile & lint dependencies |
| 56 | + run: mix compile --warnings-as-errors |
| 57 | + |
| 58 | + - name: Run tests |
| 59 | + run: mix test |
| 60 | + |
| 61 | + release: |
| 62 | + name: Publish release to hex.pm |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [ tests ] |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} |
| 68 | + steps: |
| 69 | + - name: 🛑 Cancel Previous Runs |
| 70 | + |
| 71 | + with: |
| 72 | + access_token: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: ⬇️ Checkout repo |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + ref: ${{ github.event.inputs.git-ref }} |
| 78 | + |
| 79 | + - name: Set up Elixir |
| 80 | + uses: erlef/setup-beam@v1 |
| 81 | + with: |
| 82 | + otp-version: 27 |
| 83 | + elixir-version: 1.18 |
| 84 | + |
| 85 | + - name: Install Deps |
| 86 | + run: | |
| 87 | + mix deps.get |
| 88 | + sed -i 's%@version "[0-9\.]\+"%@version "${{ github.event.inputs.release-version }}"%' mix.exs |
| 89 | + sed -i 's%{:phoenix_session_process, "~> [0-9\.]\+"}%{:phoenix_session_process, "~> ${{ github.event.inputs.release-version }}"}%' README.md |
| 90 | +
|
| 91 | + - name: Publish to hex.pm |
| 92 | + run: | |
| 93 | + mix hex.publish --yes |
| 94 | +
|
| 95 | + - name: Create Git Tag |
| 96 | + uses: actions/github-script@v7 |
| 97 | + with: |
| 98 | + script: | |
| 99 | + github.rest.git.createRef({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + ref: 'refs/tags/${{ github.event.inputs.release-version }}', |
| 103 | + sha: context.sha |
| 104 | + }) |
0 commit comments