Automated Release #14
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: Automated Release | |
on: | |
schedule: | |
- cron: "0 12 1 * *" # At 12:00 on day-of-month 1 | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
# Check if the event is not triggered by a fork | |
# if: ${{ github.repository == 'p4lang/p4c' && github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# Fetch all history for all branches and tags | |
fetch-depth: 0 | |
- name: Increment version number | |
run: perl -i -pe 's/\b(\d+)(?=\D*$)/$1+1/e' Version.txt | |
- name: Get changelog | |
id: changelog | |
run: | | |
TAG="$(git describe --tags --abbrev=0)" | |
GIT_LOG="$(git log $TAG..HEAD --oneline --pretty=format:"- %s [%an]")" | |
CHANGELOG=$(cat << EOF | |
Changelog: | |
$GIT_LOG | |
EOF | |
) | |
CHANGELOG="${CHANGELOG//'%'/'%25'}" | |
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" | |
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" | |
CHANGELOG="${CHANGELOG//'#'/''}" | |
echo "::set-output name=content::$CHANGELOG" | |
- name: Display changelog | |
run: echo "${{ steps.changelog.outputs.content }}" | |
- name: Get version | |
run: | | |
VERSION="$(cat Version.txt)" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Update changelog.md | |
run: | | |
# Define the new changelog content | |
NEW_CHANGELOG="## Version v${{ env.VERSION }}\n\n${{ steps.changelog.outputs.content }}\n" | |
# Insert new changelog before the first release section | |
awk -v new_changelog="$NEW_CHANGELOG" '/^## Release /{print new_changelog; new_changelog="";} 1' changelog.md > temp && mv temp changelog.md | |
- name: Commit and push changelog | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add changelog.md Version.txt | |
git commit -m "Update changelog and bump version to v${{ env.VERSION }}" | |
git push origin main | |
- name: Get commit message | |
id: message | |
run: | | |
COMMIT_MSG=$(cat << EOF | |
Release v${{ env.VERSION }} | |
${{ steps.changelog.outputs.content }} | |
EOF | |
) | |
COMMIT_MSG="${COMMIT_MSG//'%'/'%25'}" | |
COMMIT_MSG="${COMMIT_MSG//$'\n'/'%0A'}" | |
COMMIT_MSG="${COMMIT_MSG//$'\r'/'%0D'}" | |
echo "::set-output name=content::$COMMIT_MSG" | |
- name: Get pull request body message | |
id: body | |
run: | | |
MSG=$(cat << EOF | |
Auto-generated pull request for version ${{ env.VERSION }}. | |
Please use **Squash and merge** to include the changelog in the release message. | |
${{ steps.changelog.outputs.content }} | |
EOF | |
) | |
MSG="${MSG//'%'/'%25'}" | |
MSG="${MSG//$'\n'/'%0A'}" | |
MSG="${MSG//$'\r'/'%0D'}" | |
echo "::set-output name=content::$MSG" | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
base: main | |
add-paths: Version.txt changelog.md | |
reviewers: mbudiu-vmw | |
commit-message: ${{ steps.message.outputs.content }} | |
signoff: false | |
branch: v${{ env.VERSION }} | |
delete-branch: true | |
title: Automated Release v${{ env.VERSION }} | |
body: ${{ steps.body.outputs.content }} |