Skip to content

Commit 6dec63b

Browse files
Adding automatic release workflow (#390)
* Adding automatic release workflow * test: add temporary branch trigger for testing release workflow * Adding gh release notes configuration * Fix linting * Fix linting * fix: organize release notes sections without duplication * fix: prevent duplicate What's Changed section in release notes * fix: use simpler release notes configuration * Simplifying bump-version.sh and release.yaml by having already a section for the image in the kustomization.yaml * Adding new line to the end of the file * feat: add release note categories for better organization * Simplify use only Version Bumps category for release notes * test: add test file to verify release notes categories * fix: remove emoji from Version Bumps title for consistency * remove test file and prepare for merge * Update config/manager/kustomization.yaml Co-authored-by: Fabian <[email protected]> --------- Co-authored-by: Pablo Garcia Miranda <[email protected]> Co-authored-by: Fabian <[email protected]>
1 parent c73796d commit 6dec63b

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

.github/release.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# GitHub Release Notes Configuration
3+
# This file configures how GitHub auto-generates release notes
4+
# It separates dependency updates into a "Version Bumps" section
5+
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
6+
7+
changelog:
8+
categories:
9+
- title: Version Bumps
10+
labels:
11+
- dependencies

.github/workflows/release.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
name: Release
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v*'
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
fetch-depth: 0
22+
23+
- name: Configure git
24+
run: |
25+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
26+
git config --global user.name "github-actions[bot]"
27+
28+
- name: Get tag information
29+
id: tag_data
30+
run: |
31+
# Get tag name and message
32+
TAG_NAME=${GITHUB_REF#refs/tags/}
33+
TAG_MESSAGE=$(git tag -n1 "$TAG_NAME" | sed "s/^$TAG_NAME[[:space:]]*//")
34+
35+
# If tag message is empty, use a default
36+
if [ -z "$TAG_MESSAGE" ]; then
37+
TAG_MESSAGE="Release $TAG_NAME"
38+
fi
39+
40+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
41+
echo "TAG_MESSAGE<<EOF" >> $GITHUB_OUTPUT
42+
echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
43+
echo "EOF" >> $GITHUB_OUTPUT
44+
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
45+
46+
- name: Create GitHub Release
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
# Determine if this is a prerelease
51+
PRERELEASE=""
52+
if [[ "${{ steps.tag_data.outputs.TAG_NAME }}" =~ (alpha|beta|rc) ]]; then
53+
PRERELEASE="--prerelease"
54+
fi
55+
56+
# Create release with auto-generated notes
57+
gh release create "${{ steps.tag_data.outputs.TAG_NAME }}" \
58+
--title "${{ steps.tag_data.outputs.TAG_NAME }}" \
59+
--notes "${{ steps.tag_data.outputs.TAG_MESSAGE }}" \
60+
--generate-notes \
61+
$PRERELEASE
62+
63+
- name: Update kustomization.yaml
64+
run: |
65+
./scripts/bump-version.sh "${{ steps.tag_data.outputs.TAG_NAME }}"
66+
67+
- name: Commit and push changes
68+
run: |
69+
# Check if there are changes to commit
70+
if git diff --quiet; then
71+
echo "No changes to commit"
72+
exit 0
73+
fi
74+
75+
git add config/manager/kustomization.yaml
76+
git commit -m "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} [skip ci]"
77+
78+
# Push to main branch
79+
git push origin HEAD:main

config/manager/kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
resources:
22
- manager.yaml
3+
4+
images:
5+
- name: controller
6+
newName: ghcr.io/netbox-community/netbox-operator
7+
newTag: v0.2.8

scripts/bump-version.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Script to bump version in kustomization.yaml
5+
# Usage: ./bump-version.sh <new_version>
6+
7+
NEW_VERSION=$1
8+
9+
if [ -z "$NEW_VERSION" ]; then
10+
echo "Usage: $0 <new_version>"
11+
exit 1
12+
fi
13+
14+
KUSTOMIZATION_FILE="config/manager/kustomization.yaml"
15+
16+
if [ ! -f "$KUSTOMIZATION_FILE" ]; then
17+
echo "Error: $KUSTOMIZATION_FILE not found!"
18+
exit 1
19+
fi
20+
21+
echo "Updating version to $NEW_VERSION in $KUSTOMIZATION_FILE..."
22+
23+
# Update the newTag
24+
sed -i.bak "s/newTag: .*/newTag: $NEW_VERSION/" "$KUSTOMIZATION_FILE"
25+
rm -f "$KUSTOMIZATION_FILE.bak"
26+
27+
echo "Version bumped to $NEW_VERSION successfully!"

0 commit comments

Comments
 (0)