22name : Release
33
44on :
5- push :
6- tags :
7- - ' v*'
5+ workflow_dispatch :
6+ inputs :
7+ version :
8+ description : ' Version that should be released, format: v0.0.0'
9+ required : true
10+ type : string
11+ tagMessage :
12+ description : ' Message that will be added to the version tag'
13+ required : true
14+ type : string
815
916permissions :
1017 contents : write
@@ -25,50 +32,52 @@ jobs:
2532 git config --global user.email "github-actions[bot]@users.noreply.github.com"
2633 git config --global user.name "github-actions[bot]"
2734
28- - name : Get tag information
29- id : tag_data
35+ - name : Update kustomization.yaml
3036 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"
37+ # Fail if tag already exists
38+ if [ -n "$(git tag --list "${{ inputs.version }}")" ]; then
39+ echo "Tag "${{ inputs.version }}" already exists. Exit."
40+ exit 1
41+ else
42+ echo "Tag "${{ inputs.version }}" does not exist. Continue."
3843 fi
3944
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+ # Update image tag
46+ cd config/manager
47+ kustomize edit set image controller="netbox-operator:${{inputs.version}}"
48+ cd ../..
4549
46- - name : Create GitHub Release
50+ - name : Generate release notes for changelog
4751 env :
48- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
52+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4953 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+ # Get the previous tag to determine commit range
55+ PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
56+
57+ # Generate release notes using GitHub API without creating a release
58+ if [ -n "$PREVIOUS_TAG" ]; then
59+ RELEASE_NOTES=$(gh api repos/:owner/:repo/releases/generate-notes \
60+ -f tag_name="${{ inputs.version }}" \
61+ -f target_commitish="$(git rev-parse HEAD)" \
62+ -f previous_tag_name="$PREVIOUS_TAG" \
63+ --jq '.body')
64+ else
65+ # If no previous tag, generate notes from all commits
66+ RELEASE_NOTES=$(gh api repos/:owner/:repo/releases/generate-notes \
67+ -f tag_name="${{ inputs.version }}" \
68+ -f target_commitish="$(git rev-parse HEAD)" \
69+ --jq '.body')
5470 fi
5571
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 }}"
72+ # Save release notes to a file for use in changelog
73+ echo "$RELEASE_NOTES" > /tmp/release_notes.md
6674
6775 - name : Update CHANGELOG.md
6876 env :
6977 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7078 run : |
71- ./scripts/update-changelog-from-release.sh "${{ steps.tag_data.outputs.TAG_NAME }}"
79+ # Update changelog with the generated notes
80+ ./scripts/update-changelog-from-release.sh "${{ inputs.version }}"
7281
7382 - name : Commit and push changes
7483 env :
@@ -81,23 +90,33 @@ jobs:
8190 fi
8291
8392 # Create a new branch for the changes
84- BRANCH_NAME="release-updates-${{ steps.tag_data.outputs.TAG_NAME }}"
93+ BRANCH_NAME="release-updates-${{ inputs.version }}"
8594 git checkout -b "$BRANCH_NAME"
8695
8796 git add config/manager/kustomization.yaml CHANGELOG.md
88- git commit -m "[skip ci] chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog"
89-
97+ git commit -m "[skip ci] chore: bump version to ${{ inputs.version }} and update changelog"
9098 # Push the branch and create PR
99+
91100 git push origin "$BRANCH_NAME"
92101 PR_URL=$(gh pr create \
93- --title "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog" \
94- --body "Automated version bump and changelog update for release ${{ steps.tag_data.outputs.TAG_NAME }}" \
102+ --title "chore: bump version to ${{ inputs.version }} and update changelog" \
103+ --body "Automated version bump and changelog update for release ${{ inputs.version }}" \
95104 --head "$BRANCH_NAME" \
96105 --base main)
97106
98107 # Extract PR number from URL
99108 PR_NUMBER=$(echo "$PR_URL" | sed 's/.*\/pull\///')
100109 echo "Created PR #$PR_NUMBER: $PR_URL"
101110
102- # Enable auto-merge and merge the PR
103- gh pr merge "$PR_NUMBER" --auto --squash --delete-branch
111+ # Merge the PR
112+ gh pr merge "$PR_NUMBER" --squash --delete-branch
113+
114+ - name : Create GitHub Release
115+ env :
116+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ run : |
118+ # Create release with auto-generated notes
119+ gh release create "${{ inputs.version }}" \
120+ --title "${{ inputs.version }}" \
121+ --notes "${{ inputs.tagMessage }}" \
122+ --generate-notes
0 commit comments