diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a841d5f0..ec94605c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,9 +2,16 @@ name: Release on: - push: - tags: - - 'v*' + workflow_dispatch: + inputs: + version: + description: 'Version that should be released, format: v0.0.0' + required: true + type: string + tagMessage: + description: 'Message that will be added to the version tag' + required: true + type: string permissions: contents: write @@ -25,50 +32,52 @@ jobs: 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 + - name: Update kustomization.yaml 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" + # Fail if tag already exists + if [ -n "$(git tag --list "${{ inputs.version }}")" ]; then + echo "Tag "${{ inputs.version }}" already exists. Exit." + exit 1 + else + echo "Tag "${{ inputs.version }}" does not exist. Continue." 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 + # Update image tag + cd config/manager + kustomize edit set image controller="netbox-operator:${{inputs.version}}" + cd ../.. - - name: Create GitHub Release + - name: Generate release notes for changelog env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_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" + # Get the previous tag to determine commit range + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") + + # Generate release notes using GitHub API without creating a release + if [ -n "$PREVIOUS_TAG" ]; then + RELEASE_NOTES=$(gh api repos/:owner/:repo/releases/generate-notes \ + -f tag_name="${{ inputs.version }}" \ + -f target_commitish="$(git rev-parse HEAD)" \ + -f previous_tag_name="$PREVIOUS_TAG" \ + --jq '.body') + else + # If no previous tag, generate notes from all commits + RELEASE_NOTES=$(gh api repos/:owner/:repo/releases/generate-notes \ + -f tag_name="${{ inputs.version }}" \ + -f target_commitish="$(git rev-parse HEAD)" \ + --jq '.body') 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 }}" + # Save release notes to a file for use in changelog + echo "$RELEASE_NOTES" > /tmp/release_notes.md - name: Update CHANGELOG.md env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - ./scripts/update-changelog-from-release.sh "${{ steps.tag_data.outputs.TAG_NAME }}" + # Update changelog with the generated notes + ./scripts/update-changelog-from-release.sh "${{ inputs.version }}" - name: Commit and push changes env: @@ -81,17 +90,17 @@ jobs: fi # Create a new branch for the changes - BRANCH_NAME="release-updates-${{ steps.tag_data.outputs.TAG_NAME }}" + BRANCH_NAME="release-updates-${{ inputs.version }}" git checkout -b "$BRANCH_NAME" git add config/manager/kustomization.yaml CHANGELOG.md - git commit -m "[skip ci] chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog" - + git commit -m "[skip ci] chore: bump version to ${{ inputs.version }} and update changelog" # Push the branch and create PR + git push origin "$BRANCH_NAME" PR_URL=$(gh pr create \ - --title "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog" \ - --body "Automated version bump and changelog update for release ${{ steps.tag_data.outputs.TAG_NAME }}" \ + --title "chore: bump version to ${{ inputs.version }} and update changelog" \ + --body "Automated version bump and changelog update for release ${{ inputs.version }}" \ --head "$BRANCH_NAME" \ --base main) @@ -99,5 +108,15 @@ jobs: PR_NUMBER=$(echo "$PR_URL" | sed 's/.*\/pull\///') echo "Created PR #$PR_NUMBER: $PR_URL" - # Enable auto-merge and merge the PR - gh pr merge "$PR_NUMBER" --auto --squash --delete-branch + # Merge the PR + gh pr merge "$PR_NUMBER" --squash --delete-branch + + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Create release with auto-generated notes + gh release create "${{ inputs.version }}" \ + --title "${{ inputs.version }}" \ + --notes "${{ inputs.tagMessage }}" \ + --generate-notes diff --git a/kind/deploy-netbox.sh b/kind/deploy-netbox.sh index 5757f1e7..7bdd2c17 100755 --- a/kind/deploy-netbox.sh +++ b/kind/deploy-netbox.sh @@ -44,7 +44,7 @@ if [[ "${VERSION}" == "3.7.8" ]] ;then # need to align with netbox-chart otherwise the creation of the cluster will hang declare -a Remote_Images=( \ "busybox:1.36.1" \ - "docker.io/bitnami/redis:7.2.4-debian-12-r9" \ + "docker.io/bitnamilegacy/redis:7.2.4-debian-12-r9" \ "docker.io/netboxcommunity/netbox:v3.7.8" \ "ghcr.io/zalando/postgres-operator:v1.12.2" \ "ghcr.io/zalando/spilo-16:3.2-p3" \ @@ -61,7 +61,7 @@ elif [[ "${VERSION}" == "4.0.11" ]] ;then # need to align with netbox-chart otherwise the creation of the cluster will hang declare -a Remote_Images=( \ "busybox:1.36.1" \ - "docker.io/bitnami/redis:7.4.0-debian-12-r2" \ + "docker.io/bitnamilegacy/redis:7.4.0-debian-12-r2" \ "ghcr.io/netbox-community/netbox:v4.0.11" \ "ghcr.io/zalando/postgres-operator:v1.12.2" \ "ghcr.io/zalando/spilo-16:3.2-p3" \ @@ -77,7 +77,7 @@ elif [[ "${VERSION}" == "4.1.11" ]] ;then # need to align with netbox-chart otherwise the creation of the cluster will hang declare -a Remote_Images=( \ "busybox:1.37.0" \ - "docker.io/bitnami/redis:7.4.1-debian-12-r2" \ + "docker.io/bitnamilegacy/redis:7.4.1-debian-12-r2" \ "ghcr.io/netbox-community/netbox:v4.1.11" \ "ghcr.io/zalando/postgres-operator:v1.12.2" \ "ghcr.io/zalando/spilo-16:3.2-p3" \ @@ -202,7 +202,9 @@ ${HELM} upgrade --install netbox ${NETBOX_HELM_CHART} \ --set resources.requests.memory="512Mi" \ --set resources.limits.cpu="2000m" \ --set resources.limits.memory="2Gi" \ - $REGISTRY_ARG + --set redis.image.repository="bitnamilegacy/redis" \ + --set global.security.allowInsecureImages=true + $REGISTRY_ARG if [[ "$FORCE_NETBOX_NGINX_IPV4" == "true" ]]; then echo "Creating nginx-unit ConfigMap and patching deployment" diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh deleted file mode 100755 index 298eb861..00000000 --- a/scripts/bump-version.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/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!" diff --git a/scripts/update-changelog-from-release.sh b/scripts/update-changelog-from-release.sh index 9b21f8d7..14889007 100755 --- a/scripts/update-changelog-from-release.sh +++ b/scripts/update-changelog-from-release.sh @@ -13,14 +13,14 @@ fi echo "Updating CHANGELOG.md for release $TAG_NAME..." -# Get release data from GitHub -RELEASE_DATA=$(gh release view "$TAG_NAME" --json tagName,publishedAt,body,url) +# Get release data from file +RELEASE_NOTES=$(cat /tmp/release_notes.md) -# Extract fields -TAG=$(echo "$RELEASE_DATA" | jq -r '.tagName') -DATE=$(echo "$RELEASE_DATA" | jq -r '.publishedAt' | cut -d'T' -f1) -BODY=$(echo "$RELEASE_DATA" | jq -r '.body') -URL=$(echo "$RELEASE_DATA" | jq -r '.url') +# Use current date and tag name from parameter +TAG="$TAG_NAME" +DATE=$(date +%Y-%m-%d) +BODY="$RELEASE_NOTES" +URL="https://github.com/netbox-community/netbox-operator/releases/tag/$TAG_NAME" # Validate extracted fields if [ -z "$TAG" ] || [ -z "$DATE" ] || [ -z "$URL" ]; then @@ -67,4 +67,4 @@ awk '/^## \[/ {found=1} found {print}' CHANGELOG.md >> "$TEMP_FILE" # Replace the original file mv "$TEMP_FILE" CHANGELOG.md -echo "CHANGELOG.md updated successfully!" \ No newline at end of file +echo "CHANGELOG.md updated successfully!"