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

feat(ci): add helper workflow, scripts for release #160

Merged
merged 16 commits into from
Oct 29, 2022
32 changes: 32 additions & 0 deletions .github/workflows/tag_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: tag-release

on:
push:
branches:
- main
paths:
- "config/version.txt"

jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
with:
fetch-depth: 0
- name: Get current version from file
id: tag
run: |
export VERSION="$(cat config/version.txt)"
echo "tag=$VERSION" >> $GITHUB_OUTPUT
- name: Create tag
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # tag=v6.3.3
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/v${{ steps.tag.outputs.tag }}",
sha: context.sha
})
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ To get an overview of all options that can be set for the template you can take
## Contribution

If you want to contribute to `go/template` please have a look at our [contribution guidelines](CONTRIBUTING.md).

## Releasing

The release process is described in the [release docs](docs/release.md).
18 changes: 18 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Releasing a new version of go-template

Since we want to support that even users that install `go-template` with `go install` get the right version output of `go version`
we currently embed a version file in this repo at [`config/version.txt`](../config/version.txt).
This file has to be updated on every release.

To keep the process as easy as possible some helper scripts and workflows have been created to ensure the correct release process.

To create a new release please do the following:

- Checkout the main branch
- `git pull` to update it
- Execute `hack/release.sh` to create a new release PR (if you don't have the GitHub CLI installed you need to create the PR yourself from the branch that was created by the script)
- Get someone else to approve your PR. This also ensures that all maintainers agree that a new version should be released
- After the PR is merged, the workflow `tag-release` should be executed automatically
- This workflow listens to all changes on the `config/version.txt` file
- It creates a new tag on the main branch using the version defined in the file
- The newly created tag will then trigger the `release` workflow automatically which creates a new release
40 changes: 40 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

linuxluigi marked this conversation as resolved.
Show resolved Hide resolved
# This script is meant to be used by go/template's maintainers
# to trigger the creation of a new release branch and PR according
# to the release flow described in the docs (../docs/release.md).

# The script sets the defined new version in the version.txt file
# and automatically opens a new PR on GitHub.

set -e

SVU="go run github.com/caarlos0/svu@latest"

echo "Current version is $($SVU current)"
read -p "Enter your intended release version: " VERSION

echo ""
echo "Preparing release $VERSION"
TRIMMED_VERSION="${VERSION#"v"}"
if [[ "$TRIMMED_VERSION" = "$VERSION" ]]; then
echo "Version tags should start with a 'v'"
exit 1
fi

BRANCH_NAME=release-"$TRIMMED_VERSION"
git checkout -b "$BRANCH_NAME"

echo "$TRIMMED_VERSION" >config/version.txt
git add config/version.txt
git commit -m "chore: prepare release $TRIMMED_VERSION"
git push --set-upstream origin "$BRANCH_NAME"

if command -v gh >/dev/null; then
gh pr create --fill
else
echo "GitHub CLI is not installed."
echo "Pls open a PR for $BRANCH_NAME into main"
fi

git checkout main