Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 14 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# GitHub Release Notes Configuration
# This file configures how GitHub auto-generates release notes
# It separates dependency updates into a "Version Bumps" section
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

changelog:
categories:
- title: Version Bumps
labels:
- dependencies
- title: What's Changed
labels:
- "*"
97 changes: 97 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
name: Release

on:
push:
tags:
- 'v*'
branches:
- 'feature/automatic-releases' # TODO - Remove before merging!
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Configure git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"

- name: Get tag information
id: tag_data
run: |
# Get tag name and message
TAG_NAME=${GITHUB_REF#refs/tags/}
TAG_MESSAGE=$(git tag -n1 "$TAG_NAME" | sed "s/^$TAG_NAME[[:space:]]*//")

# If tag message is empty, use a default
if [ -z "$TAG_MESSAGE" ]; then
TAG_MESSAGE="Release $TAG_NAME"
fi

echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
echo "TAG_MESSAGE<<EOF" >> $GITHUB_OUTPUT
echo "$TAG_MESSAGE" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT

- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Determine if this is a prerelease
PRERELEASE=""
if [[ "${{ steps.tag_data.outputs.TAG_NAME }}" =~ (alpha|beta|rc) ]]; then
PRERELEASE="--prerelease"
fi

# Create release with auto-generated notes
gh release create "${{ steps.tag_data.outputs.TAG_NAME }}" \
--title "${{ steps.tag_data.outputs.TAG_NAME }}" \
--notes "${{ steps.tag_data.outputs.TAG_MESSAGE }}" \
--generate-notes \
$PRERELEASE

- name: Update kustomization.yaml
run: |
# Use the bump-version.sh script if it exists, otherwise use inline version
if [ -f "scripts/bump-version.sh" ]; then
./scripts/bump-version.sh "${{ steps.tag_data.outputs.TAG_NAME }}"
else
# Inline version
cd config/manager
if ! grep -q "^images:" kustomization.yaml; then
echo "" >> kustomization.yaml
echo "images:" >> kustomization.yaml
echo "- name: controller" >> kustomization.yaml
echo " newName: ghcr.io/netbox-community/netbox-operator" >> kustomization.yaml
echo " newTag: ${{ steps.tag_data.outputs.TAG_NAME }}" >> kustomization.yaml
else
sed -i "s/newTag: .*/newTag: ${{ steps.tag_data.outputs.TAG_NAME }}/" kustomization.yaml
fi
fi

- name: Commit and push changes
run: |
# Check if there are changes to commit
if git diff --quiet; then
echo "No changes to commit"
exit 0
fi

git add config/manager/kustomization.yaml
git commit -m "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} [skip ci]"

# Push to main branch
git push origin HEAD:main
37 changes: 37 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e

# Script to bump version in kustomization.yaml
# Usage: ./bump-version.sh <new_version>

NEW_VERSION=$1

if [ -z "$NEW_VERSION" ]; then
echo "Usage: $0 <new_version>"
exit 1
fi

KUSTOMIZATION_FILE="config/manager/kustomization.yaml"

if [ ! -f "$KUSTOMIZATION_FILE" ]; then
echo "Error: $KUSTOMIZATION_FILE not found!"
exit 1
fi

echo "Updating version to $NEW_VERSION in $KUSTOMIZATION_FILE..."

# Check if images section exists
if ! grep -q "^images:" "$KUSTOMIZATION_FILE"; then
# Add images section
echo "" >> "$KUSTOMIZATION_FILE"
echo "images:" >> "$KUSTOMIZATION_FILE"
echo "- name: controller" >> "$KUSTOMIZATION_FILE"
echo " newName: ghcr.io/netbox-community/netbox-operator" >> "$KUSTOMIZATION_FILE"
echo " newTag: $NEW_VERSION" >> "$KUSTOMIZATION_FILE"
else
# Update existing newTag
sed -i.bak "s/newTag: .*/newTag: $NEW_VERSION/" "$KUSTOMIZATION_FILE"
rm -f "$KUSTOMIZATION_FILE.bak"
fi

echo "Version bumped to $NEW_VERSION successfully!"
Loading