Fetch Latest Release Notes #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Manual Release (Github Package Registry) | |
on: workflow_dispatch | |
jobs: | |
release: | |
permissions: | |
actions: read | |
checks: read | |
contents: write | |
deployments: write | |
packages: write | |
pull-requests: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
# Get the latest release tag | |
- name: Get latest release tag | |
id: get_latest_release | |
run: | | |
LATEST_TAG=$(curl -s \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/latest" \ | |
| jq -r .tag_name) | |
echo "Latest tag: $LATEST_TAG" | |
echo "::set-output name=latest_tag::$LATEST_TAG" | |
# Generate the next version tag | |
- name: Generate new tag version | |
id: generate_new_tag | |
run: | | |
LATEST_TAG=${{ steps.get_latest_release.outputs.latest_tag }} | |
if [[ $LATEST_TAG =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
MAJOR=${BASH_REMATCH[1]} | |
MINOR=${BASH_REMATCH[2]} | |
PATCH=${BASH_REMATCH[3]} | |
NEW_TAG="v$MAJOR.$MINOR.$((PATCH + 1))" | |
else | |
echo "Invalid version format: $LATEST_TAG. Defaulting to v1.0.0" | |
NEW_TAG="v1.0.0" | |
fi | |
echo "New tag: $NEW_TAG" | |
echo "::set-output name=new_tag::$NEW_TAG" | |
# Generate custom release notes | |
- name: Generate Release Notes | |
id: generate_release_notes | |
run: | | |
RELEASE_NOTES=$(curl -s \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/compare/${{ steps.get_latest_release.outputs.latest_tag }}...HEAD" \ | |
| jq -r '.commits[] | "* " + .commit.message' | sed ':a;N;$!ba;s/\n/\\n/g') | |
if [[ -z "$RELEASE_NOTES" ]]; then | |
RELEASE_NOTES="No changes in this release." | |
fi | |
echo "::set-output name=release_notes::$RELEASE_NOTES" | |
# Create Release | |
- name: Create Release with Custom Release Notes | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.generate_new_tag.outputs.new_tag }} | |
release_name: Release ${{ steps.generate_new_tag.outputs.new_tag }} | |
body: ${{ steps.generate_release_notes.outputs.release_notes }} | |
# Send Slack Notification | |
- name: Notify Slack about new release | |
run: | | |
SLACK_MESSAGE="*New Release: ${{ steps.generate_new_tag.outputs.new_tag }}*\n\nRelease Notes:\n${{ steps.generate_release_notes.outputs.release_notes }}" | |
curl -X POST -H 'Content-type: application/json' \ | |
--data '{"text": "'"$SLACK_MESSAGE"'"}' \ | |
${{ secrets.SLACK_WEBHOOK_URL }} |