Skip to content

Commit

Permalink
ci: create github release on tag (#212)
Browse files Browse the repository at this point in the history
Adds a GitHub workflow to create a GitHub release (with uploaded artifacts) when a tag is pushed.
  • Loading branch information
mindovermiles262 authored Jan 6, 2025
1 parent 64285be commit a0235d2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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

25 changes: 25 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -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<TAG>
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 <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.

6 changes: 5 additions & 1 deletion build/artifacts.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,7 +16,6 @@ mkdir -p bin/artifacts

for i in "${arr[@]}"
do
VERSION=$(git describe)
GOOSARCH=$i
GOOS=${GOOSARCH%/*}
GOARCH=${GOOSARCH#*/}
Expand Down
29 changes: 29 additions & 0 deletions build/release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a0235d2

Please sign in to comment.