diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000..d31eafeb --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,11 @@ +--- +# 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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..6c36943d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,79 @@ +--- +name: Release + +on: + push: + tags: + - 'v*' + +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<> $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: | + ./scripts/bump-version.sh "${{ steps.tag_data.outputs.TAG_NAME }}" + + - 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 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84..efa3b2c2 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,7 @@ resources: - manager.yaml + +images: +- name: controller + newName: ghcr.io/netbox-community/netbox-operator + newTag: v0.2.8 diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100755 index 00000000..298eb861 --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +# Script to bump version in kustomization.yaml +# Usage: ./bump-version.sh + +NEW_VERSION=$1 + +if [ -z "$NEW_VERSION" ]; then + echo "Usage: $0 " + 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..." + +# Update the newTag +sed -i.bak "s/newTag: .*/newTag: $NEW_VERSION/" "$KUSTOMIZATION_FILE" +rm -f "$KUSTOMIZATION_FILE.bak" + +echo "Version bumped to $NEW_VERSION successfully!"