From ed5c59e495acd3fbfe160075f478665c4dbe1f4a Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 10 Jun 2024 12:40:14 +0100 Subject: [PATCH] CI/bin releases worlfow (#27) * chore: Adds workflow to create releases * chore: Update docker title * fix: Fixes YAML indentation. I'm a n00b * fix: Yaml indentation. Again --- .github/workflows/docker.yml | 2 +- .github/workflows/release.yml | 89 +++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a9cc3aa..554e407 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: ๐Ÿณ Build + Publish Multi-Platform Image +name: ๐Ÿณ Publish Docker on: workflow_dispatch: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b761739..c05bc9a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,55 @@ -name: ๐Ÿ› ๏ธ Compile Release Assets +# Upon a new tag being pushed to git, this workflow will: +# - Get the app version (from tag) +# - Draft a new release with release notes +# - Compile the Go binary for all platforms +# - Attach the compiled binaries to the release +name: ๐Ÿ—๏ธ Release Binaries on: - release: - types: [created] + push: + tags: + - '^[0-9]+\.[0-9]+\.[0-9]+$' + workflow_dispatch: + inputs: + tag: + description: 'Tag to draft a release for (must already exist)' + required: true jobs: - releases-matrix: - name: Release Go Binary + create-draft-release: + name: Create Draft Release 1๏ธโƒฃ + runs-on: ubuntu-latest + outputs: + release_id: ${{ steps.create_release.outputs.id }} + tag_name: ${{ steps.get_tag_name.outputs.tag_name }} + steps: + - name: Checkout code ๐Ÿ›Ž๏ธ + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get Tag Name ๐Ÿท๏ธ + id: get_tag_name + run: echo "::set-output name=tag_name::${GITHUB_REF##*/}" + + - name: Create Draft Release ๐Ÿ“ + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.event.inputs.tag || github.ref_name }} + release_name: Release ${{ github.event.inputs.tag || github.ref_name }} + draft: true + prerelease: false + generate_release_notes: true + + - name: Output new release URL โ†—๏ธ + run: 'echo "Draft release URL: ${{ steps.create_release.outputs.html_url }}"' + + compile-and-attach: + name: Compile and Attach Go Binary 2๏ธโƒฃ + needs: create-draft-release runs-on: ubuntu-latest strategy: matrix: @@ -20,13 +63,31 @@ jobs: steps: - name: Checkout code ๐Ÿ›Ž๏ธ uses: actions/checkout@v3 - - name: Compile Go binaries ๐Ÿ—๏ธ - uses: wangyoucao577/go-release-action@v1.29 + + - name: Set up Go ๐Ÿ—๏ธ + uses: actions/setup-go@v2 + with: + go-version: 1.22.4 + + - name: Compile Go binaries ๐Ÿ”จ + run: | + go build -ldflags "-X main.Version=${{ needs.create-draft-release.outputs.tag_name }}" -o web-check-api . + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + - name: Upload Go binaries โคด๏ธ + uses: actions/upload-artifact@v2 + with: + name: web-check-api-${{ matrix.goos }}-${{ matrix.goarch }} + path: web-check-api + + - name: Attach binaries to release ๐Ÿ“Ž + uses: actions/upload-release-asset@v1 with: - github_token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - goos: ${{ matrix.goos }} - goarch: ${{ matrix.goarch }} - goversion: 1.22.4 - project_path: '.' - binary_name: web-check-api - md5sum: true + upload_url: ${{ needs.create-draft-release.outputs.release_id }} + asset_path: web-check-api + asset_name: web-check-api-${{ matrix.goos }}-${{ matrix.goarch }} + asset_content_type: application/octet-stream + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}