From 46f8423b58a14de9aa5281a36059db7050bdce88 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 5 Dec 2023 18:02:54 +0100 Subject: [PATCH 1/3] Rename workflow file Signed-off-by: Christian Wolf --- .../workflows/{approve-on-comment.yaml => slack-commands.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{approve-on-comment.yaml => slack-commands.yaml} (100%) diff --git a/.github/workflows/approve-on-comment.yaml b/.github/workflows/slack-commands.yaml similarity index 100% rename from .github/workflows/approve-on-comment.yaml rename to .github/workflows/slack-commands.yaml From ec6f548e84e2e3af337d8268b508fbf3c185aec6 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 5 Dec 2023 19:09:16 +0100 Subject: [PATCH 2/3] Create basic backport script Signed-off-by: Christian Wolf --- .github/actions/backport/backport.sh | 39 ++++++++++++++++++++++++ .github/workflows/slack-commands.yaml | 43 +++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100755 .github/actions/backport/backport.sh diff --git a/.github/actions/backport/backport.sh b/.github/actions/backport/backport.sh new file mode 100755 index 000000000..7a9cbc18e --- /dev/null +++ b/.github/actions/backport/backport.sh @@ -0,0 +1,39 @@ +#!/bin/bash -e + +echo "::notice::Fetching PR information" +curl -L -H "Accept: application/vnd.github+json" "https://api.github.com/repos/nextcloud/cookbook/pulls/$number" > /tmp/pr-data + +baseSha=$(cat /tmp/pr-data | jq -r '.base.sha') +echo "::debug::Base SHA is $baseSha" +baseRef=$(cat /tmp/pr-data | jq -r '.base.ref') +echo "::debug::Base reference is $baseRef" +headSha=$(cat /tmp/pr-data | jq -r '.base.sha') +echo "::debug::Head SHA of rebase is $headSha" + +IFS=' ' read tmp branchName < /tmp/comment +echo "::debug::Branch name of destination branch is $branchName" + +git config user.name "Cookbook bot" +git config user.email "bot@noreply.github.com" + +backportBranch() { + backportBranchName="backport-$branchName/$headSha" + echo "::debug::Backport branch name to create is $backportBranchName" + echo "branchName=$backportBranchName" >> "$GITHUB_OUTPUT" + echo "targetBranch=$baseRef" >> "$GITHUB_OUTPUT" + + git branch "$backportBranchName" "$headSha" + + echo "::debug::Switching to backport branch" + git checkout "$backportBranchName" + + echo "Branch was created, ready for porting to other branch" + + git rebase --onto "$branchName" "$baseSha" "$backportBranchName" + + echo "Rebasing was successful" + + git push origin "$backportBranchName" +} + +backportBranch diff --git a/.github/workflows/slack-commands.yaml b/.github/workflows/slack-commands.yaml index 43a7a248c..07dada610 100644 --- a/.github/workflows/slack-commands.yaml +++ b/.github/workflows/slack-commands.yaml @@ -30,3 +30,46 @@ jobs: pull-request-number: ${{ github.event.issue.number }} review-message: "Automatically approved by GitHub action on behalf of `/approve`" + backport: + name: Backport PR + runs-on: ubuntu-latest + if: github.event.issue.pull_request + env: + admins: '["seyfeb", "christianlupus"]' + steps: + - name: Collect data + run: |- + echo "Admins: $admins" + echo "User is permitted: ${{ contains(fromJSON(env.admins), github.event.comment.user.login) }}" + echo "permitted_user=${{ contains(fromJSON(env.admins), github.event.comment.user.login) }}" >> "$GITHUB_OUTPUT" + echo "Comment body matches /approve: ${{ startsWith(github.event.comment.body, '/backport')}}" + echo "use_backport=${{ startsWith(github.event.comment.body, '/backport')}}" >> "$GITHUB_OUTPUT" + echo "number=${{ github.event.issue.number }}" >> "$GITHUB_ENV" + echo "${{ github.event.comment.body }}" > /tmp/comment + id: config + - name: Add reaction unon start + if: steps.config.outputs.permitted_user && steps.config.outputs.use_backport + uses: peter-evans/create-or-update-comment@v3.0.1 + with: + token: ${{ secrets.COOKBOOK_BOT_TOKEN }} + repository: ${{ github.event.repository.full_name }} + comment-id: ${{ github.event.comment.id }} + reaction-type: "+1" + - name: Carry out the backport + if: steps.config.outputs.permitted_user && steps.config.outputs.use_backport + run: .github/actions/backport/backport.sh + id: backport + - name: Create a pull request + if: steps.config.outputs.permitted_user && steps.config.outputs.use_backport + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.COOKBOOK_BOT_TOKEN }} + branch: ${{ steps.backport.outputs.branchName }} + base: ${{ steps.backport.outputs.targetBranch }} + title: Backport of ${{ github.event.pull_request.title }} + body: |- + Backport of #${{ github.event.issue.number }} + + ${{ github.event.body }} + + From 4ee19d139c0f9fb7a5e4da6bff1587fbc869d330 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 5 Dec 2023 19:11:32 +0100 Subject: [PATCH 3/3] Update Changelog Signed-off-by: Christian Wolf --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d97cf00e0..6986db305 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ ### Maintenance - Add PHP lint checker to ensure valid (legacy) PHP syntax [#1931](https://github.com/nextcloud/cookbook/pull/1931) @christianlupus +- Add backport script to simplify development + [#1935](https://github.com/nextcloud/cookbook/pull/1935) @christianlupus ## 0.10.3 - 2023-12-04