Skip to content

Commit d4db430

Browse files
chrissetoRafalKorepta
authored andcommitted
Add "Release On Tag" GHA
This commit adds the new "Release On Tag" GitHub Action. It does exactly what the name would imply. When a tag is pushed, the action will generate a github release using the changie log as the release body. If the pushed tag has a helm chart associated with it, the chart will be built and uploaded to the release.
1 parent d7ad813 commit d4db430

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Release On Tag
2+
3+
on:
4+
push:
5+
tags:
6+
# Only match tags that look like go module tags.
7+
# This way we explicitly ignore our legacy tagging of the operator.
8+
- '*/v*'
9+
workflow_dispatch:
10+
inputs:
11+
ref_name:
12+
description: "The ref name to process (e.g., 'operator/v1.2.3')"
13+
required: false
14+
default: ""
15+
16+
jobs:
17+
release:
18+
name: Create Release on GitHub
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
# for testing purposes and to allow updating of pre-existing releases,
23+
# this workflow can be triggered by a tag being pushed or directly. This
24+
# step normalized the possible inputs into a single variable.
25+
- name: get ref
26+
id: get_ref
27+
run: |
28+
if [[ -n "${{ inputs.ref_name }}" ]]; then
29+
tag="${{ inputs.ref_name }}"
30+
else
31+
tag="${{ github.ref_name }}"
32+
fi
33+
echo "using ref name: $tag"
34+
echo "ref_name=$tag" >> "$github_output"
35+
36+
- name: checkout code
37+
uses: actions/checkout@v4
38+
with:
39+
ref: ${{ steps.get_ref.outputs.ref_name }}
40+
41+
- uses: nixbuild/nix-quick-install-action@v30
42+
with:
43+
github_access_token: ${{ secrets.github_token }}
44+
45+
# cache the nix store.
46+
- uses: nix-community/cache-nix-action@v6
47+
with:
48+
primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashfiles('**/*.nix', '**/flake.lock') }}
49+
restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }}
50+
51+
- name: build release name
52+
id: release_name
53+
run: |
54+
# turn refs into slightly friendlier names. e.g. operator/v1.2.3 -> operator: v1.2.3
55+
release_name="$(echo "${{ steps.get_ref.outputs.ref_name }}" | sed 's|/v|: v|')"
56+
echo "release_name=$release_name" >> "$github_output"
57+
58+
- name: package helm chart
59+
run: |
60+
tag="${{ steps.get_ref.outputs.ref_name }}"
61+
# extract the directory from the tag (e.g., "operator" from "operator/v1.2.3")
62+
dir="$(dirname "$tag")"
63+
# search for chart.yaml in $dir or one directory deep (e.g., operator/chart)
64+
chart_path=$(find "$dir" -maxdepth 2 -type f -name "chart.yaml" | head -n 1)
65+
# exit early if no chart.yaml file is found
66+
if [[ -z "$chart_path" ]]; then
67+
echo "no chart.yaml found for $tag. skipping step."
68+
exit 0
69+
fi
70+
71+
echo "packaging chart at $chart_path"
72+
helm package -u "$(dirname "$chart_path")"
73+
74+
# create github release and upload file
75+
- name: create github release
76+
if: github.ref_type == 'tag'
77+
uses: softprops/action-gh-release@v2
78+
with:
79+
name: steps.release_name.outputs.release_name
80+
tag_name: steps.get_ref.outputs.ref_name
81+
draft: false
82+
make_latest: false
83+
prerelease: ${{ contains(steps.get_ref.outputs.ref_name, '-alpha') || contains(steps.get_ref.outputs.ref_name, '-beta') }}
84+
body_path: ".changes/${{ steps.get_ref.outputs.ref_name }}.md" # pull the release body from changie.
85+
# if a chart was packaged, we'll upload it to this release preserving helm's naming convention.
86+
files: |
87+
./*.tgz
88+
89+
# todo(chrisseto) trigger an action in the charts repo that updates index.yaml

CONTRIBUTING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ To release any project in this repository:
101101
4. Commit the resultant diff with the commit message `<project>: cut release <version>` and rebase it into master via a Pull Request.
102102
5. Tag the above commit with as `<project>/v<version>` with `git tag $(changie latest -j <project>) <commit-sha>`.
103103
6. Push the tags.
104-
7. Create a [Release on GitHub](https://github.com/redpanda-data/redpanda-operator/releases)
105-
- Associate it with the tag pushed in the previous step.
106-
- Paste the contents of `.changes/<project>/<version>.md`, excluding the header, into the release notes field.
107-
- Name the release `<project>: <version>`
104+
7. Verify that the Release Workflow ran successfully.
105+
8. If applicable, mark the newly minted release as the "latest".
108106

109107
## Nightly build
110108

0 commit comments

Comments
 (0)