Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Create Github Release on Tag #212

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading