From a59ed433dd4bc5133cf9895024488e94d10c1d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Mon, 25 Sep 2023 12:45:41 +0200 Subject: [PATCH] Setup GitHub Actions Package Publish --- .github/workflows/branch_main.yml | 11 +++ .github/workflows/part_publish.yml | 108 +++++++++++++++++++++++++++++ .github/workflows/pr.yml | 11 +++ .github/workflows/tag-beta.yml | 14 ++++ .github/workflows/tag-stable.yml | 14 ++++ 5 files changed, 158 insertions(+) create mode 100644 .github/workflows/part_publish.yml diff --git a/.github/workflows/branch_main.yml b/.github/workflows/branch_main.yml index a95fda2..6807e58 100644 --- a/.github/workflows/branch_main.yml +++ b/.github/workflows/branch_main.yml @@ -32,3 +32,14 @@ jobs: otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" + + publish: + name: "Publish" + + needs: ["detectToolVersions"] + + uses: ./.github/workflows/part_publish.yml + with: + otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" + rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" + elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" diff --git a/.github/workflows/part_publish.yml b/.github/workflows/part_publish.yml new file mode 100644 index 0000000..bf6ead6 --- /dev/null +++ b/.github/workflows/part_publish.yml @@ -0,0 +1,108 @@ +on: + workflow_call: + inputs: + otpVersion: + required: true + type: string + rebarVersion: + required: true + type: string + elixirVersion: + required: true + type: string + releaseName: + required: false + type: string + secrets: + HEX_API_KEY: + required: false + +name: "Publish" + +jobs: + hex_publish: + name: mix hex.publish + + runs-on: ubuntu-latest + + if: "${{ inputs.releaseName }}" + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + id: setupBEAM + with: + otp-version: ${{ inputs.otpVersion }} + rebar3-version: ${{ inputs.rebarVersion }} + elixir-version: ${{ inputs.elixirVersion }} + - uses: actions/cache@v3 + with: + path: _build + key: mix_hex_publish-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('mix.exs') }} + restore-keys: | + mix_hex_publish-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}- + - uses: actions/cache@v3 + with: + path: deps + key: mix_hex_publish-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('mix.exs') }} + restore-keys: | + mix_hex_publish-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}- + - run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} + + hex_build: + name: mix hex.build + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + id: setupBEAM + with: + otp-version: ${{ inputs.otpVersion }} + rebar3-version: ${{ inputs.rebarVersion }} + elixir-version: ${{ inputs.elixirVersion }} + - uses: actions/cache@v3 + with: + path: _build + key: mix_hex_build-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('mix.exs') }} + restore-keys: | + mix_hex_build-build-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}- + - uses: actions/cache@v3 + with: + path: deps + key: mix_hex_build-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}-${{ hashFiles('mix.exs') }} + restore-keys: | + mix_hex_build-deps-${{ runner.os }}-${{ steps.setupBEAM.outputs.otp-version }}- + - run: mix hex.build --output package.tar + - uses: actions/upload-artifact@v3 + with: + name: package + path: package.tar + + upload: + name: "Upload" + + runs-on: ubuntu-latest + + if: ${{ inputs.releaseName }} + + needs: ["hex_build"] + + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v3 + with: + name: package + path: package.tar + - name: Upload + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + gh release upload --clobber "${{ inputs.releaseName }}" \ + package.tar diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a3bad32..b4a47da 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -33,3 +33,14 @@ jobs: otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" + + publish: + name: "Publish" + + needs: ["detectToolVersions"] + + uses: ./.github/workflows/part_publish.yml + with: + otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" + rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" + elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" diff --git a/.github/workflows/tag-beta.yml b/.github/workflows/tag-beta.yml index 4232394..c4a0f32 100644 --- a/.github/workflows/tag-beta.yml +++ b/.github/workflows/tag-beta.yml @@ -31,3 +31,17 @@ jobs: rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" releaseName: "${{ github.ref_name }}" + + publish: + name: "Publish" + + needs: ["detectToolVersions"] + + uses: ./.github/workflows/part_publish.yml + with: + otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" + rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" + elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" + releaseName: "${{ github.ref_name }}" + secrets: + HEX_API_KEY: "${{ secrets.HEX_API_KEY }}" diff --git a/.github/workflows/tag-stable.yml b/.github/workflows/tag-stable.yml index f4beb93..b96288c 100644 --- a/.github/workflows/tag-stable.yml +++ b/.github/workflows/tag-stable.yml @@ -30,3 +30,17 @@ jobs: rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" releaseName: "${{ github.ref_name }}" + + publish: + name: "Publish" + + needs: ["detectToolVersions"] + + uses: ./.github/workflows/part_publish.yml + with: + otpVersion: "${{ needs.detectToolVersions.outputs.otpVersion }}" + rebarVersion: "${{ needs.detectToolVersions.outputs.rebarVersion }}" + elixirVersion: "${{ needs.detectToolVersions.outputs.elixirVersion }}" + releaseName: "${{ github.ref_name }}" + secrets: + HEX_API_KEY: "${{ secrets.HEX_API_KEY }}"