Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create backport action #1935

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/actions/backport/backport.sh
Original file line number Diff line number Diff line change
@@ -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
32 changes: 0 additions & 32 deletions .github/workflows/approve-on-comment.yaml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/slack-commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Slack-like comments
on:
issue_comment:
types:
- "created"
- "edited"

defaults:
run:
shell: bash

jobs:
approve-pr:
name: Approve PR
runs-on: ubuntu-latest
if: github.event.issue.pull_request
env:
admins: '["seyfeb", "christianlupus"]'
steps:
- run: |-
echo "Admins: $admins"
echo "User is permitted: ${{ contains(fromJSON(env.admins), github.event.comment.user.login) }}"
echo "Comment body matches /approve: ${{github.event.comment.body == '/approve'}}"
- uses: hmarr/auto-approve-action@v3
if: >-
github.event.comment.body == '/approve' &&
contains(fromJSON(env.admins), github.event.comment.user.login)
with:
github-token: ${{ secrets.COOKBOOK_BOT_TOKEN }}
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 }}


2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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
Expand Down
Loading