Skip to content

Commit

Permalink
Automate changelog [Part 2] (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored May 25, 2023
1 parent 0fb5fb6 commit e50637c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:
description: "Specify the new version (e.g. v9.0.0)"

jobs:
increment-stride-version:
changelog:
runs-on: ubuntu-latest

steps:
- name: Get versions
run: |
old_version=${{ github.event.inputs.old_version }}
new_version=${{ github.event.inputs.new_version }}
new_major_version=v$(echo $new_version | cut -d '.' -f 1)
new_major_version=$(echo $new_version | cut -d '.' -f 1)
branch_name=actions/changelog-version-${new_major_version}
echo "OLD_VERSION=$old_version" >> $GITHUB_ENV
Expand All @@ -40,12 +40,16 @@ jobs:
- name: Create branch
run: git checkout -b ${{ env.branch_name }}

- name: Fetch main
run: git fetch origin main:main

- name: Update changelogs
run: ./scripts/changelog.sh

- name: Commit changes
run: git add .
git commit -m 'updated changelogs'
run: |
git add .
git commit -m 'updated changelog'
- name: Push changes
id: push
Expand Down Expand Up @@ -73,9 +77,9 @@ jobs:
-H "Authorization: token ${{ secrets.GH_ACTIONS_PAT }}" \
https://api.github.com/repos/${{ github.repository }}/pulls \
-d '{
"title":"${{ env.NEW_VERSION }} Changelog",
"title":"${{ env.NEW_MAJOR_VERSION }} Changelog",
"head":"${{ env.branch_name }}",
"base":"main",
"body":"This is an automatically generated pull request.\n\nPlease review and merge the changes. **Remember to split the On-Chain vs Off-Chain commits!**\n\n## Context\n\nUpdates changelog for ${{ env.NEW_MAJOR_VERSION }} release\n\n## Brief Changelog\n\n* Updates main changelog with on-chain and off-chain changes\n* Updates upgrade-specific changelog with on-chain changes only\n",
"body":"This is an automatically generated pull request.\n\nPlease review and merge the changes. **Remember to split the On-Chain vs Off-Chain commits!**\n\n## Context\n\nUpdated changelog for ${{ env.NEW_MAJOR_VERSION }} release\n\n## Brief Changelog\n\n* Updated main changelog with on-chain and off-chain changes\n* Updated upgrade-specific changelog with on-chain changes only\n",
"maintainer_can_modify": true
}'
2 changes: 1 addition & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
description: "Specify the new version (e.g. 9.0.0)"

jobs:
increment-stride-version:
version:
runs-on: ubuntu-latest

steps:
Expand Down
27 changes: 22 additions & 5 deletions scripts/changelog.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -eu

VERSION_REGEX='v[0-9]{1,2}\.[0-9]{1}\.[0-9]{1}$'

# Validate script parameters
Expand All @@ -13,7 +15,18 @@ if [ -z "$NEW_VERSION" ]; then
exit 1
fi

GITHUB_URL="https://github.com/Stride-Labs/stride/commit"
if ! echo $OLD_VERSION | grep -Eq $VERSION_REGEX; then
echo "OLD_VERSION must be of form {major}.{minor}.{patch} (e.g. 8.0.0). Exiting..."
exit 1
fi

if ! echo $NEW_VERSION | grep -Eq $VERSION_REGEX; then
echo "NEW_VERSION must be of form {major}.{minor}.{patch} (e.g. 8.0.0). Exiting..."
exit 1
fi

GITHUB_COMMIT_URL="https://github.com/Stride-Labs/stride/commit"
GITHUB_PR_URL="https://github.com/org/repo/pull"
ON_CHAIN_FILES='"x/**/*.go" "app/**/*.go" ":(exclude)**/*_test.go"'
CURRENT_DATE=$(date +'%Y-%m-%d')
NEW_MAJOR_VERSION=$(echo "$NEW_VERSION" | cut -d '.' -f 1)
Expand All @@ -35,8 +48,10 @@ i=1
git log --pretty=format:"%h %H %s" ${OLD_VERSION}..main | while read LINE; do
SHORT_COMMIT_HASH=$(echo $LINE | cut -d' ' -f1)
LONG_COMMIT_HASH=$(echo $LINE | cut -d' ' -f2)
COMMIT_DESCRIPTION=$(echo $LINE | cut -d' ' -f3-)
echo "$i. $COMMIT_DESCRIPTION ([${SHORT_COMMIT_HASH}]($GITHUB_URL/${LONG_COMMIT_HASH}))" >> $TEMP_CHANGELOG
COMMIT_TITLE=$(echo $LINE | cut -d' ' -f3-)
PR_NUMBER=$(echo $COMMIT_TITLE | grep -oP '#\K\w+')
COMMIT_DESCRIPTION=$(echo $COMMIT_TITLE | sed "s|#$PR_NUMBER|[#$PR_NUMBER]($GITHUB_PR_URL/$PR_NUMBER)|")
echo "$i. $COMMIT_DESCRIPTION [[${SHORT_COMMIT_HASH}]($GITHUB_COMMIT_URL/${LONG_COMMIT_HASH})]" >> $TEMP_CHANGELOG
i=$((i+1))
done

Expand All @@ -55,7 +70,9 @@ git log --pretty=format:"%h %H %s" ${OLD_VERSION}..main -- "x/**/*.go" "app/**/*
fi
SHORT_COMMIT_HASH=$(echo $LINE | cut -d' ' -f1)
LONG_COMMIT_HASH=$(echo $LINE | cut -d' ' -f2)
COMMIT_DESCRIPTION=$(echo $LINE | cut -d' ' -f3-)
echo "$i. $COMMIT_DESCRIPTION ([${SHORT_COMMIT_HASH}]($GITHUB_URL/${LONG_COMMIT_HASH}))" >> $UPGRADE_CHANGELOG
COMMIT_TITLE=$(echo $LINE | cut -d' ' -f3-)
PR_NUMBER=$(echo $COMMIT_TITLE | grep -oP '#\K\w+')
COMMIT_DESCRIPTION=$(echo $COMMIT_TITLE | sed "s|#$PR_NUMBER|[#$PR_NUMBER]($GITHUB_PR_URL/$PR_NUMBER)|")
echo "$i. $COMMIT_DESCRIPTION [[${SHORT_COMMIT_HASH}]($GITHUB_COMMIT_URL/${LONG_COMMIT_HASH})]" >> $UPGRADE_CHANGELOG
i=$((i+1))
done

0 comments on commit e50637c

Please sign in to comment.