|
| 1 | +# Copyright 2023 Giuseppe De Palma, Matteo Trentin |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Worker Release |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + tags: ["v*"] |
| 20 | + workflow_dispatch: |
| 21 | + pull_request: |
| 22 | + branches: [main] |
| 23 | +env: |
| 24 | + otp-version: 25 |
| 25 | + elixir-version: 1.14 |
| 26 | + |
| 27 | +# Run on tag push or on manual dispatch. Release will not be created for manual dispatch |
| 28 | +jobs: |
| 29 | + create-mix-releases: |
| 30 | + if: ${{ startswith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} |
| 31 | + name: Mix release |
| 32 | + strategy: |
| 33 | + fail-fast: false |
| 34 | + matrix: |
| 35 | + os: [ubuntu-20.04, windows-2019, macos-11] |
| 36 | + include: |
| 37 | + - os: ubuntu-20.04 |
| 38 | + rust-target: x86_64-unknown-linux-gnu |
| 39 | + release-tarball: worker-x86_64-linux.tar.gz |
| 40 | + release-name: worker |
| 41 | + - os: windows-2019 |
| 42 | + rust-target: x86_64-pc-windows-gnu |
| 43 | + release-tarball: worker-x86_64-windows.tar.gz |
| 44 | + release-name: worker |
| 45 | + - os: macos-11 |
| 46 | + rust-target: x86_64-apple-darwin |
| 47 | + release-tarball: worker-x86_64-macos.tar.gz |
| 48 | + release-name: worker |
| 49 | + |
| 50 | + runs-on: ${{ matrix.os }} |
| 51 | + env: |
| 52 | + MIX_ENV: prod |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v3 |
| 56 | + |
| 57 | + - name: Setup Elixir/OTP |
| 58 | + if: ${{ startswith(matrix.os, 'ubuntu') || startswith(matrix.os, 'windows') }} |
| 59 | + uses: erlef/setup-beam@v1 |
| 60 | + with: |
| 61 | + otp-version: "=${{ env.otp-version }}" |
| 62 | + elixir-version: "${{ env.elixir-version }}" |
| 63 | + install-hex: true |
| 64 | + install-rebar: true |
| 65 | + - name: Setup Elixir/OTP |
| 66 | + if: ${{ startswith(matrix.os, 'macos') }} |
| 67 | + run: | |
| 68 | + brew install erlang |
| 69 | + brew install elixir |
| 70 | +
|
| 71 | + - name: Retrieve Mix Dependencies Cache |
| 72 | + uses: actions/cache@v1 |
| 73 | + id: mix-cache |
| 74 | + with: |
| 75 | + path: deps |
| 76 | + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} |
| 77 | + |
| 78 | + - name: Install Rebar and Hex |
| 79 | + run: | |
| 80 | + mix local.rebar --force |
| 81 | + mix local.hex --force |
| 82 | + - name: Install Mix Dependencies (if deps cache miss) |
| 83 | + if: steps.mix-cache.outputs.cache-hit != 'true' |
| 84 | + run: | |
| 85 | + mix do deps.get, deps.compile |
| 86 | +
|
| 87 | + - name: Compile Elixir |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + mix compile |
| 91 | +
|
| 92 | + - name: Create Mix Release |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + mix release ${{ matrix.release-name }} |
| 96 | + cd _build/${{ env.MIX_ENV }}/rel/${{ matrix.release-name }} |
| 97 | + tar -czvf ${{ matrix.release-tarball }} bin erts-* lib releases |
| 98 | + mv ${{ matrix.release-tarball }} ../../../../ |
| 99 | +
|
| 100 | + - name: Upload artifact |
| 101 | + uses: actions/upload-artifact@v2 |
| 102 | + with: |
| 103 | + name: ${{ matrix.release-tarball }} |
| 104 | + path: ${{ matrix.release-tarball }} |
| 105 | + |
| 106 | + github-release: |
| 107 | + if: startswith(github.ref, 'refs/tags/') # Only run on tag push |
| 108 | + needs: [create-mix-releases] |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - name: Download Release Tarballs |
| 112 | + uses: actions/download-artifact@v3 |
| 113 | + with: |
| 114 | + path: release |
| 115 | + |
| 116 | + - name: Release |
| 117 | + uses: softprops/action-gh-release@v1 |
| 118 | + with: |
| 119 | + files: release/**/*.tar.gz |
| 120 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 121 | + prerelease: false |
| 122 | + draft: false |
0 commit comments