Fetch Latest Release Notes #9
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" | |
# Create Release with Release Notes | |
- name: Create Release with Release Notes | |
id: create_release | |
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 }} | |
generate_release_notes: true # Automatically generate release notes | |
# Fetch the release notes | |
- name: Fetch Release Notes | |
id: fetch_release_notes | |
run: | | |
RELEASE_NOTES=$(curl -s \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.generate_new_tag.outputs.new_tag }}" \ | |
| jq -r .body) | |
echo "::set-output name=release_notes::$RELEASE_NOTES" | |
# Format and send the Slack message with release notes | |
- name: Notify Slack about new release | |
run: | | |
SLACK_MESSAGE="*New Release: ${{ steps.generate_new_tag.outputs.new_tag }}*\n\nRelease Notes:\n${{ steps.fetch_release_notes.outputs.release_notes }}" | |
curl -X POST -H 'Content-type: application/json' \ | |
--data '{"text": "'"$SLACK_MESSAGE"'"}' \ | |
${{ secrets.SLACK_WEBHOOK_URL }} |