Skip to content

Commit

Permalink
Automate the creation of release PR (close #498)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjben committed Jun 8, 2021
1 parent 78bb84a commit ae1b6ac
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Prepare PR for release

on:
create

jobs:
prepare_release_pr:
if: ${{ contains(github.ref, 'refs/heads/release/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout Github
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Extract release version
id: version
run: |
export VERSION=$(basename ${{ github.ref }})
echo "::set-output name=release_version::$VERSION"
- name: Create prepare for release commit
run: |
echo $(git log --pretty=oneline | cut -d" " -f2- | grep -n -m1 "Prepare for .* release"|cut -d':' -f1)
nbNewCommits=$(echo "$(git log --pretty=format:%s | grep -n -m1 "Prepare for .* release" | cut -d':' -f1) - 1" | bc)
newCommits=$(git log --pretty=format:%s|head -$nbNewCommits|sed 's/close #/#/;s/closes #/#/')
newVersion=${{ steps.version.outputs.release_version }}
headLine="Version $newVersion ($(date +%Y-%m-%d))"
nbDashes=$(expr length "$headLine")
dashes=$(printf "%0.s-" $(seq 1 $nbDashes))
{ echo -e "$headLine\n$dashes\n$newCommits\n"; cat CHANGELOG; } > CHANGELOG.new
mv CHANGELOG.new CHANGELOG
sed -i -E "s/([ ]+version[ ]+:= )\"[0-9]+\.[0-9]+\.[0-9]+.*/\1\"$newVersion\"/g" build.sbt
sed -i -E "s/(release-)[0-9]+\.[0-9]+\.[0-9]+/\1$newVersion/g" README.md
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "Prepare for $newVersion release" CHANGELOG build.sbt README.md
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

- name: Create PR
uses: repo-sync/pull-request@v2
with:
destination_branch: "master"
pr_title: "Release ${{ steps.version.outputs.release_version }}"
pr_body: "Created by Github Actions"
github_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit ae1b6ac

Please sign in to comment.