From a0235d24496127f59ab51504e6b6c8e88c28e7ec Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 6 Jan 2025 10:06:27 -0700 Subject: [PATCH] ci: create github release on tag (#212) Adds a GitHub workflow to create a GitHub release (with uploaded artifacts) when a tag is pushed. --- .github/workflows/release.yaml | 46 ++++++++++++++++++++++++++++++++++ build/README.md | 25 ++++++++++++++++++ build/artifacts.sh | 6 ++++- build/release.sh | 29 +++++++++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yaml create mode 100644 build/README.md create mode 100755 build/release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..ce10b45e --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,46 @@ +name: Create release + +on: + push: + tags: + - "v*" + +env: + GH_TAG: ${{github.ref_name}} + +permissions: + contents: write + +jobs: + build-release-binaries: + name: Build Relase Binaries + runs-on: ubuntu-latest + steps: + # https://github.com/actions/checkout + - uses: actions/checkout@v4 + # Build the binaries using the `build/artifacts.sh` script in the repo + - name: Build Artifacts + run: build/artifacts.sh $GH_TAG + # https://github.com/marketplace/actions/upload-a-build-artifact + - uses: actions/upload-artifact@v4 + with: + name: binaries + path: bin/artifacts/ + + release: + name: Release + runs-on: ubuntu-latest + needs: [build-release-binaries] + steps: + # https://github.com/actions/checkout + - uses: actions/checkout@v4 + # https://github.com/actions/download-artifact + - uses: actions/download-artifact@v4 + with: + name: binaries + path: bin/artifacts/ + - name: Create Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: build/release.sh $GH_TAG + diff --git a/build/README.md b/build/README.md new file mode 100644 index 00000000..7bf68ffe --- /dev/null +++ b/build/README.md @@ -0,0 +1,25 @@ +# Building a Release + +## Git Tags + +Github workflows has been configured in such a way that simply pushing a tag will deploy a new version of Piko. + +``` +git tag v +git push origin --tags +``` + +This will kick off the "Release" workflow on Github. + +## Github Releases + +New releases may also be built using the Github GUI. From the releases page: + +1. Draft a new release +1. Create your new tag under "Choose a tag", choosing "Create new tag on publish" +1. Create your release notes or choose "Generate release notes" +1. Give your release a title. +1. Click Publish. + +This will generate a new git tag with the tag you've created. It will run the github action to build the artifacts and will then overwrite the release with a new release which contains the binaries attached. + diff --git a/build/artifacts.sh b/build/artifacts.sh index 217972ad..9fa65eb9 100755 --- a/build/artifacts.sh +++ b/build/artifacts.sh @@ -1,4 +1,9 @@ #!/bin/bash +set -euo pipefail + +# Set the VERSION to $1, otherwise get it from `git describe` +GIT_VERSION=$(git describe || echo "NONE") +VERSION="${1:-$GIT_VERSION}" declare -a arr=( "linux/amd64" @@ -11,7 +16,6 @@ mkdir -p bin/artifacts for i in "${arr[@]}" do - VERSION=$(git describe) GOOSARCH=$i GOOS=${GOOSARCH%/*} GOARCH=${GOOSARCH#*/} diff --git a/build/release.sh b/build/release.sh new file mode 100755 index 00000000..31b4057b --- /dev/null +++ b/build/release.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +if [ $# -ne 1 ]; then + echo "No release tag name given. Failing" + exit 1 +fi + + +if ! command -v gh 2>&1 >/dev/null +then + echo "Github CLI could not be found" + exit 2 +fi + +if gh release edit $1 --verify-tag ; +then + # Release exists, upload binaries + gh release upload \ + $1 \ + bin/artifacts/* +else + gh release create \ + $1 \ + bin/artifacts/* \ + --generate-notes +fi +