Skip to content

Commit 028a08c

Browse files
committed
Add release scripts and guide
Signed-off-by: Chris Doherty <[email protected]>
1 parent 2faddf0 commit 028a08c

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

.github/workflows/release.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on:
2+
push:
3+
tags:
4+
- "v*"
5+
name: Create release
6+
env:
7+
REGISTRY: quay.io
8+
IMAGE_NAME: ${{ github.repository }}
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
- name: Generate Release Notes
16+
run: |
17+
release_notes=$(gh api repos/{owner}/{repo}/releases/generate-notes -F tag_name=${{ github.ref }} --jq .body)
18+
echo 'RELEASE_NOTES<<EOF' >> $GITHUB_ENV
19+
echo "${release_notes}" >> $GITHUB_ENV
20+
echo 'EOF' >> $GITHUB_ENV
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
OWNER: ${{ github.repository_owner }}
24+
REPO: ${{ github.event.repository.name }}
25+
26+
- name: Docker manager metadata
27+
id: meta
28+
uses: docker/metadata-action@v3
29+
with:
30+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
31+
flavor: latest=false
32+
tags: type=ref,event=tag
33+
34+
- name: Set the from image tag
35+
run: echo "FROM_TAG=sha-${GITHUB_SHA::8}" >> $GITHUB_ENV
36+
37+
- name: Copy the image using skopeo
38+
run: skopeo copy --all --dest-creds="${DST_REG_USER}":"${DST_REG_PASS}" docker://"${SRC_IMAGE}" docker://"${DST_IMAGE}"
39+
env:
40+
SRC_IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.FROM_TAG }}
41+
DST_IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
42+
DST_REG_USER: ${{ secrets.QUAY_USERNAME }}
43+
DST_REG_PASS: ${{ secrets.QUAY_PASSWORD }}
44+
45+
- name: Create Release
46+
id: create_release
47+
uses: actions/create-release@v1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
with:
51+
tag_name: ${{ github.ref }}
52+
release_name: ${{ github.ref }}
53+
body: ${{ env.RELEASE_NOTES }}
54+
draft: false
55+
prerelease: true

REALEASE.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Releasing
2+
3+
## Process
4+
5+
For version v0.x.y:
6+
7+
1. Create the annotated tag
8+
> NOTE: To use your GPG signature when pushing the tag, use `SIGN_TAG=1 ./contrib/tag-release.sh v0.x.y` instead)
9+
- `./contrib/tag-release.sh v0.x.y`
10+
1. Push the tag to the GitHub repository. This will automatically trigger a [Github Action](https://github.com/tinkerbell/hegel/actions) to create a release.
11+
> NOTE: `origin` should be the name of the remote pointing to `github.com/tinkerbell/hegel`
12+
- `git push origin v0.x.y`
13+
1. Review the release on GitHub.
14+
15+
### Permissions
16+
17+
Releasing requires a particular set of permissions.
18+
19+
- Tag push access to the GitHub repository

contrib/tag-release.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o nounset -o pipefail
4+
5+
if [ -z "${1-}" ]; then
6+
echo "Must specify new tag"
7+
exit 1
8+
fi
9+
10+
new_tag=${1-}
11+
[[ $new_tag =~ ^v[0-9]*\.[0-9]*\.[0-9]*$ ]] || (
12+
echo "Tag must be in the form of vX.Y.Z"
13+
exit 1
14+
)
15+
16+
if [[ $(git symbolic-ref HEAD) != refs/heads/main ]] && [[ -z ${ALLOW_NON_MAIN:-} ]]; then
17+
echo "Must be on main branch" >&2
18+
exit 1
19+
fi
20+
if [[ $(git describe --dirty) != $(git describe) ]]; then
21+
echo "Repo must be in a clean state" >&2
22+
exit 1
23+
fi
24+
25+
git fetch --all
26+
27+
last_tag=$(git describe --abbrev=0)
28+
last_tag_commit=$(git rev-list -n1 "$last_tag")
29+
last_specific_tag=$(git tag --contains="$last_tag_commit" | grep -E "^v[0-9]*\.[0-9]*\.[0-9]*$" | tail -n 1)
30+
last_specific_tag_commit=$(git rev-list -n1 "$last_specific_tag")
31+
if [[ $last_specific_tag_commit == $(git rev-list -n1 HEAD) ]]; then
32+
echo "No commits since last tag" >&2
33+
exit 1
34+
fi
35+
36+
if [[ -n ${SIGN_TAG-} ]]; then
37+
git tag -s -m "${new_tag}" "${new_tag}" &>/dev/null && echo "created signed tag ${new_tag}" >&2 && exit
38+
else
39+
git tag -a -m "${new_tag}" "${new_tag}" &>/dev/null && echo "created annotated tag ${new_tag}" >&2 && exit
40+
fi

0 commit comments

Comments
 (0)