Skip to content

Allow cache_flexible() to use a callback (#834) #115

Allow cache_flexible() to use a callback (#834)

Allow cache_flexible() to use a callback (#834) #115

name: Release from Changelog
on:
push:
paths:
- '.github/workflows/release-from-changelog.yml'
- 'CHANGELOG.md'
branches:
- '*.x'
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ secrets.ALLEY_CI_KEY }}
- name: Extract latest version from CHANGELOG.md
id: get_version
run: |
VERSION=$(grep -oP '(?<=## v)\d+\.\d+\.\d+' CHANGELOG.md | head -1)
echo "Latest version found: $VERSION"
echo "version=v$VERSION" >> $GITHUB_ENV
- name: Get latest GitHub release
id: latest_release
run: |
LATEST_RELEASE=$(gh release list --limit 1 --exclude-drafts --json tagName --jq '.[0].tagName' || echo "")
echo "Latest GitHub release: $LATEST_RELEASE"
echo "latest_release=$LATEST_RELEASE" >> $GITHUB_ENV
- name: Extract release notes
id: extract_notes
run: |
sed -n '/^## '"$version"'/,/^## /p' CHANGELOG.md | sed '1d;$d' > RELEASE_NOTES.md
# Remove line wrapping.
sed -i ':a;N;$!ba;s/\n / /g' RELEASE_NOTES.md
# Trim leading and trailing whitespace.
sed -i 's/^[ \t]*//;s/[ \t]*$//' RELEASE_NOTES.md
echo "Release notes:"
cat RELEASE_NOTES.md
shell: bash
- name: Create new GitHub release if version is new
if: env.version != env.latest_release && env.version != '' && env.latest_release != 'Unreleased'
env:
GH_TOKEN: ${{ github.token }}
run: |
# Check if $version is a semver version (vX.Y.Z)
if [[ ! "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version: $version"
exit 1
fi
if gh release view "$version" > /dev/null 2>&1; then
echo "Release $version already exists. Skipping release creation."
exit 0
fi
RELEASE_URL=$(gh release create "$version" --title "$version" --notes-file RELEASE_NOTES.md --fail-on-no-commits -d)
RELEASE_URL="${RELEASE_URL//\/tag\//\/edit\/}"
echo "Release created: $RELEASE_URL"
echo "release_url=$RELEASE_URL" >> $GITHUB_ENV
- name: Send Slack notification if release created
if: env.release_url != ''
uses: slackapi/[email protected]
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "A new release *${{ env.version }}* has been drafted for mantle-framework: <${{ env.release_url }}|View Release on GitHub>"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}