From ae1b6ace577612ddb850926cfb4957ac10c2dc15 Mon Sep 17 00:00:00 2001 From: Benjamin Benoist Date: Tue, 8 Jun 2021 10:29:03 +0200 Subject: [PATCH] Automate the creation of release PR (close #498) --- .github/workflows/release.yml | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..150323238 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} \ No newline at end of file