1818 description : ' Environment to run in'
1919 type : environment
2020 required : true
21- process_all_releases :
22- description : ' Process all releases (including past ones)'
23- required : false
24- default : false
25- type : boolean
2621 branch :
2722 description : ' Branch to use'
2823 required : true
2924 default : ' gh-pages'
3025 release_tag :
31- description : ' Input release tag'
26+ description : ' Manually run for a specific release tag'
3227 required : true
3328 type : text
3429
@@ -37,236 +32,118 @@ jobs:
3732 permissions :
3833 contents : write
3934 pull-requests : write
40- id-token : write
4135 runs-on : ubuntu-latest
42- if : |
43- (github.event_name == 'release' && github.event.release.published == 'true') ||
44- (github.event_name == 'workflow_dispatch')
4536
4637 steps :
4738 - name : Checkout code
4839 uses : actions/checkout@v4
4940 with :
5041 ref : gh-pages
51-
42+ fetch-depth : 0
43+
5244 - name : Install GitHub CLI and jq
5345 run : |
5446 sudo apt-get update
5547 sudo apt-get install -y gh jq
5648
57- - name : Set release tag for release_event
58- if : github.event_name == 'release' && github.event.release.published == 'true'
49+ - name : Set Tag for Release Event
50+ if : github.event_name == 'release'
5951 id : set_release_tag
60- run : |
61- # Extract version from branch name (e.g., release-v1.2.3 -> v1.2.3)
62- RELEASE_TAG="${GITHUB_HEAD_REF}"
63- echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT
64- env :
65- GITHUB_HEAD_REF : ${{ github.head_ref }}
52+ run : echo "tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
6653
67- - name : Set release tag for Wrokflow Event
68- if : github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag != ''
69- id : set_workflow_release_tag
70- run : |
71- # Extract version from branch name (e.g., release-v1.2.3 -> v1.2.3)
72- RELEASE_TAG="${{github.event.inputs.release_tag}}"
73- echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT
74-
75- - name : Get latest release info
76- id : latest_release
77- run : |
78- RELEASE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
79- "https://api.github.com/repos/${{ github.repository }}/releases/latest")
80- LATEST_RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.tag_name')
81- IS_LATEST=$(echo "$RELEASE_JSON" | jq -r '.prerelease')
82- echo "Latest release name: $LATEST_RELEASE_NAME"
83- echo "Is latest release: $IS_LATEST"
84- echo "LATEST_RELEASE_NAME=$LATEST_RELEASE_NAME" >> $GITHUB_OUTPUT
85- echo "IS_LATEST=$IS_LATEST" >> $GITHUB_OUTPUT
86- env :
87- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88- GITHUB_REPOSITORY : ${{ github.repository }}
54+ - name : Set Tag for Manual Trigger
55+ if : github.event_name == 'workflow_dispatch'
56+ id : set_manual_tag
57+ run : echo "tag=${{ github.event.inputs.release_tag }}" >> $GITHUB_OUTPUT
8958
90- - name : Process releases
91- id : process_releases
59+ - name : Generate Notes for New Release
60+ id : process_release
9261 run : |
93- # Function to process a single release
94- process_release() {
95- local RELEASE_TAG=$1
96- local IS_MANUAL_TRIGGER=$2
97-
98- # Skip if this is a manual trigger and the file already exists
99- if [[ "$IS_MANUAL_TRIGGER" == "true" ]]; then
100- if [ -f "docs/src/content/docs/release_docs/$RELEASE_TAG.md" ]; then
101- echo "Documentation already exists for $RELEASE_TAG, skipping."
102- return 0
103- fi
104- fi
105-
106- # Get release notes
107- RELEASE_NOTES=$(gh release view $RELEASE_TAG --json body --template '{{.body}}')
108-
109- if [ -z "$RELEASE_NOTES" ]; then
110- echo "No release notes found for $RELEASE_TAG"
111- return 0
112- fi
113-
114- # Get the latest tag before this release
115- git fetch --tags
116- LAST_TAG=$(git describe --tags --abbrev=0 --match "v*" "$RELEASE_TAG^" 2>/dev/null || echo "")
117-
118- # Update version references in documentation files
119- if [ -n "$LAST_TAG" ]; then
120- echo "Updating version references from $LAST_TAG to $RELEASE_TAG"
121- if [ -f "docs/src/content/docs/introduction/getting_started.mdx" ]; then
122- sed -i "s|$LAST_TAG|$RELEASE_TAG|g" "docs/src/content/docs/introduction/getting_started.mdx" || true
123- fi
124- if [ -f "docs/src/components/githubRelease.astro" ]; then
125- sed -i "s|$LAST_TAG|$RELEASE_TAG|g" "docs/src/components/githubRelease.astro" || true
126- fi
127- if [ -f "docs/src/content/docs/index.mdx" ]; then
128- sed -i "s|$LAST_TAG|$RELEASE_TAG|g" "docs/src/content/docs/index.mdx" || true
129- fi
130- fi
131-
132- # Create release notes file
133-
134- FILE_NAME="docs/src/content/docs/release_docs/$RELEASE_TAG.md"
135- mkdir -p "$(dirname "$FILE_NAME")"
136-
137- echo "---" > "$FILE_NAME"
138- echo "title: $RELEASE_TAG" >> "$FILE_NAME"
139- echo "description: Release Notes for $RELEASE_TAG for vJailbreak" >> "$FILE_NAME"
140- echo "---" >> "$FILE_NAME"
141- echo "" >> "$FILE_NAME"
142- echo "$RELEASE_NOTES" >> "$FILE_NAME"
143-
144- echo "Created documentation for $RELEASE_TAG"
145- echo "PROCESSED_RELEASES=${PROCESSED_RELEASES:+$PROCESSED_RELEASES,}$RELEASE_TAG" >> $GITHUB_OUTPUT
146- }
147-
148- # Export the function so it's available in subshells
149- export -f process_release
150-
151- # Calculate date 3 months ago in ISO 8601 format
152- THREE_MONTHS_AGO=$(date -d "3 months ago" -u +"%Y-%m-%dT%H:%M:%SZ")
153- echo "Fetching releases since $THREE_MONTHS_AGO"
62+ RELEASE_TAG="${{ steps.set_release_tag.outputs.tag || steps.set_manual_tag.outputs.tag }}"
63+
64+ echo ">>> Processing new release: $RELEASE_TAG"
15465
155- # Get recent releases (last 3 months)
156- ALL_RELEASES=$(gh api -X GET "repos/$GITHUB_REPOSITORY/releases" --jq '.[] | select(.published_at > "'$THREE_MONTHS_AGO'") | .tag_name' | sort -V)
157- echo "Found recent releases (oldest to newest): $ALL_RELEASES"
158- if [ -z "$ALL_RELEASES" ]; then
159- echo "No recent releases found in the last 3 months"
66+ RELEASE_NOTES=$(gh release view "$RELEASE_TAG" --json body --template '{{.body}}' || echo "")
67+ if [ -z "$RELEASE_NOTES" ]; then
68+ echo "No release notes found for $RELEASE_TAG, skipping."
69+ echo "processed_release=false" >> $GITHUB_OUTPUT
16070 exit 0
16171 fi
162-
163- echo "Found recent releases: $ALL_RELEASES"
164-
165- # Initialize output
166- echo "PROCESSED_RELEASES=" >> $GITHUB_OUTPUT
167-
168- # For manual trigger with process_all_releases=true
169- if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.process_all_releases }}" == "true" ]]; then
17072
171- echo "Processing recent releases (last 3 months)..."
73+ # find the previous tag
74+ ALL_TAGS_SORTED=$(git tag --sort=version:refname)
75+ LAST_TAG=$(echo "$ALL_TAGS_SORTED" | grep -B 1 -x "$RELEASE_TAG" | head -n 1)
17276
173- for TAG in $ALL_RELEASES; do
174- process_release "$TAG" "true"
175- done
176- # For release events
177- elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.release.published }}" == "true" ]]; then
178- echo "Processing new release..."
179- process_release "${{ github.event.release.tag_name }}" "false"
180- # For PR merges (legacy)
181- elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
182- echo "Processing PR merge..."
183- process_release "${{ steps.set_pr_tag.outputs.RELEASE_TAG }}" "false"
77+ if [[ -n "$LAST_TAG" && "$LAST_TAG" != "$RELEASE_TAG" ]]; then
78+ echo "Found previous version: $LAST_TAG. Updating version numbers in docs..."
79+ sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/introduction/getting_started.mdx
80+ sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/components/githubRelease.astro
81+ sed -i "s|$LAST_TAG|$RELEASE_TAG|g" docs/src/content/docs/index.mdx
18482 fi
83+
84+ # Create the new release note file
85+ FILE_NAME="docs/src/content/docs/release_docs/$RELEASE_TAG.md"
86+ mkdir -p "$(dirname "$FILE_NAME")"
87+ {
88+ echo "---"
89+ echo "title: $RELEASE_TAG"
90+ echo "description: Release Notes for $RELEASE_TAG"
91+ echo "---"
92+ echo ""
93+ echo "$RELEASE_NOTES"
94+ } > "$FILE_NAME"
95+
96+ echo "processed_release=true" >> $GITHUB_OUTPUT
97+ echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
18598 env :
18699 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
187- GITHUB_REPOSITORY : ${{ github.repository }}
188100
189- - name : archive old release notes
101+ - name : Archive and Delete Old Release Notes
102+ if : steps.process_release.outputs.processed_release == 'true'
190103 run : |
191- echo "Checking for older release notes"
192- # strip leading 'v', sort semantically, pick top-5, then subtract
193- mapfile -t ALL < <(ls docs/src/content/docs/release_docs/v* 2>/dev/null | sed 's/^v//' | sort -V)
194- mapfile -t TOP5 < <(printf '%s\n' "${ALL[@]}" | tail -n 5)
104+ echo "Archiving and cleaning old release notes..."
105+ mapfile -t ALL_VERSIONS < <(find docs/src/content/docs/release_docs -name "v*.md" -printf "%f\n" | sed -e 's/^v//' -e 's/\.md$//' | sort -V)
106+ mapfile -t TOP_5_ARRAY < <(printf '%s\n' "${ALL_VERSIONS[@]}" | tail -n 5)
195107
196- # build a lookup for TOP5
197- declare -A is_top5
198- for v in "${TOP5[@]}"; do
199- is_top5["$v"]=1
200- done
201-
202- echo "Top 5 versions"
203- for v in "${TOP5[@]}"; do
204- echo "v$v"
205- done
108+ if [ ${#TOP_5_ARRAY[@]} -eq 0 ]; then exit 0; fi
206109
207- echo "Archived versions"
208- for v in "${ALL[@]}"; do
209- if [[ -z "${is_top5[$v]}" ]]; then
210- echo "trying to archive v$v"
211- awk '
212- BEGIN { in_yaml=0 }
213- # Toggle YAML block
214- /^---$/ {
215- in_yaml = !in_yaml
216- next
217- }
110+ echo "Keeping Top 5 versions:"
111+ printf 'v%s\n' "${TOP_5_ARRAY[@]}"
218112
219- # While inside YAML block
220- in_yaml {
221- if ($1 == "title:") {
222- sub(/^title:[[:space:]]*v/, "## v")
223- print
224- }
225- next
226- }
227-
228- # Outside YAML: convert all ## to ###
229- {
230- sub(/^##/, "###")
231- print
232- }
233- ' docs/src/content/docs/release_docs/v$v.md >> docs/src/content/docs/archives/release_notes.md
234- fi
113+ for v in "${ALL_VERSIONS[@]}"; do
114+ IS_IN_TOP_5=false
115+ for top_v in "${TOP_5_ARRAY[@]}"; do
116+ if [[ "$v" == "$top_v" ]]; then IS_IN_TOP_5=true; break; fi
117+ done
118+ if ! $IS_IN_TOP_5; then
119+ FILE_TO_PROCESS="docs/src/content/docs/release_docs/v${v}.md"
120+ if [ -f "$FILE_TO_PROCESS" ]; then
121+ echo "Archiving and deleting: v${v}.md"
122+ awk 'BEGIN { in_yaml=0 } /^---$/ { in_yaml = !in_yaml; next } in_yaml { if ($1 == "title:") { sub(/^title:[[:space:]]*v/, "## v"); print; }; next; } { sub(/^##/, "###"); print }' "$FILE_TO_PROCESS" >> docs/src/content/docs/archives/release_notes.md
123+ rm "$FILE_TO_PROCESS"
124+ fi
125+ fi
235126 done
236- env :
237- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
238- GITHUB_REPOSITORY : ${{ github.repository }}
239127
240128 - name : Create PR with changes
241- if : steps.process_releases .outputs.PROCESSED_RELEASES != ' '
129+ if : steps.process_release .outputs.processed_release == 'true '
242130 run : |
243- # Configure Git
244131 git config --global user.email "github-actions[bot]@users.noreply.github.com"
245132 git config --global user.name "GitHub Actions Bot"
246133
247- # Create branch name with timestamp
248- TIMESTAMP=$(date +%Y%m%d%H%M%S)
249- NEW_BRANCH="update-release-notes-$TIMESTAMP"
250- git checkout -b $NEW_BRANCH
251-
252- # Add and commit changes
253-
254- git add docs/src/content/docs/* docs/src/components/githubRelease.astro
134+ TIMESTAMP=$(date +%s)
135+ NEW_BRANCH="update-release-docs-$TIMESTAMP"
136+ RELEASE_TAG="${{ steps.process_release.outputs.release_tag }}"
137+
138+ git checkout -b "$NEW_BRANCH"
139+ git add docs/
140+
255141 if ! git diff --cached --quiet; then
256- git commit -m "docs: update release notes and version references for ${{ steps.process_releases.outputs.PROCESSED_RELEASES }}"
257-
258- git push origin $NEW_BRANCH
259-
260- # Create PR
261- gh pr create \
262- --base gh-pages \
263- --head $NEW_BRANCH \
264-
265- --title "Update release notes for ${{ steps.process_releases.outputs.PROCESSED_RELEASES }}" \
266- --body "Automatically generated PR to update release notes and version references"
267-
142+ git commit -m "docs: Update for release $RELEASE_TAG"
143+ git push origin "$NEW_BRANCH"
144+ gh pr create --base gh-pages --head "$NEW_BRANCH" --title "docs: Update for release $RELEASE_TAG" --body "This PR was automatically generated."
268145 else
269- echo "No changes to commit "
146+ echo "No changes were detected to create a pull request. "
270147 fi
271148 env :
272- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
149+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments