Skip to content

Commit

Permalink
Added bot update readme release notes
Browse files Browse the repository at this point in the history
Signed-off-by: tao.yang <[email protected]>
  • Loading branch information
ty-dc committed Apr 16, 2024
1 parent 9125833 commit c5bfc80
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/auto-version-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ jobs:
dest_tag: ${{ needs.get-tag.outputs.tag }}
secrets: inherit

release-notes:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-notes.yaml
with:
dest_tag: ${{ needs.get-tag.outputs.tag }}
branch: ${{ needs.get-tag.outputs.tag }}
secrets: inherit

create-release:
needs: [release-chart, release-changelog, get-tag]
name: create release
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/call-release-notes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Call Release Notes

on:
workflow_call:
inputs:
ref:
required: true
type: string
# --- call by manual
workflow_dispatch:
inputs:
ref:
description: 'branch, tag, sha'
required: true
default: main

permissions: write-all

env:
PR_LABEL: pr/release/doc
PR_REVIWER: ty-dc

jobs:
release_notes:
runs-on: ubuntu-latest
outputs:
ref: ${{ env.REF }}
steps:
- name: Get Ref
id: get_ref
run: |
pwd
ls
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "call by workflow_dispatch"
echo "REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
elif ${{ inputs.ref != '' }}; then
echo "call by workflow_call"
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
# update the release-note of the main branch after the release.
ref: main

- name: update release notes
run: |
echo "update release notes"
branchName=` grep -Eo "v[0-9]+\.[0-9]+" <<< ${{ env.REF }} `
FILE_NAME_LIST=$(grep -Rl '\[Release Notes\]' --exclude-dir ./.github)
if ! grep -r '\[Release Notes\]' * | grep release-${branchName} ; then
echo "release notes for this version: release-${branchName} do not exist"
for FILE_NAME in ${FILE_NAME_LIST}
do
BEGIN_LINE =$(grep -r '\[Release Notes\]' $FILE_NAME -n | awk -F ':' '{print $2}' | head -n 1)
END_LINE=$(grep -r '\[Release Notes\]' $FILE_NAME -n | awk -F ':' '{print $2}' | tail -n 1)
echo "delete line $END_LINE"
sed -i '$END_LINE d' $FILE
echo "Add line before $BEGIN_LINE"
ASSERT_LINE=$((BEGIN_LINE-1))
lineText="| [release-$branchName](https://github.com/spidernet-io/spiderpool/tree/release-$branchName) | [Release Notes](https://github.com/spidernet-io/spiderpool/releases/tag/${{ env.REF }}) |"
sed -i $ASSERT_LINE' a \$lineText' $FILE
done
else
for FILE_NAME in ${FILE_NAME_LIST}
do
LINE=$(grep -r '\[Release Notes\]' $FILE_NAME -n | grep release-$branchName | awk -F ':' '{print $2}')
echo "delete line $END_LINE"
sed -i '$LINE d' $FILE
echo "Add line before $LINE"
ASSERT_LINE=$(($LINE-1))
lineText="| [release-$branchName](https://github.com/spidernet-io/spiderpool/tree/release-$branchName) | [Release Notes](https://github.com/spidernet-io/spiderpool/releases/tag/${{ env.REF }}) |"
done
sed -i "s/### Release Notes/### Release Notes\n\n### ${branchName} Release Notes/" docs/release-notes.md
fi
- name: Create PR
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/[email protected]
with:
title: "robot updates the release notes of the README file based on the release branch: ${{ env.REF }} "
commit-message: "robot updates the release notes of the README file based on the release branch: ${{ env.REF }}"
branch-suffix: timestamp
committer: ty-dc <[email protected]>
branch: robot/update_doc
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}

0 comments on commit c5bfc80

Please sign in to comment.