Skip to content

Commit a90f4d4

Browse files
authored
[ci] Add GitHub Action to backport PR (backports #2017 and #2018) (#2391)
* [ci] Add GitHub Action to backport PR (#2017) Closes #2014 gherrit-pr-id: I70bf2382d041da61ff8d85be9fc593cacc08e215 * [ci][backport-pr] Fetch all commits, configure git author (#2018) gherrit-pr-id: I8c3db36d20b511c31ec774db68896f2fe4b539bb
1 parent 15a2cf5 commit a90f4d4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.github/workflows/backport-pr.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2024 The Fuchsia Authors
2+
#
3+
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4+
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5+
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6+
# This file may not be copied, modified, or distributed except according to
7+
# those terms.
8+
9+
name: Backport PR
10+
on:
11+
workflow_dispatch:
12+
inputs:
13+
commit:
14+
description: "Commit to backport"
15+
required: true
16+
target_branch:
17+
description: "Target branch for the new PR"
18+
required: true
19+
default: 'main'
20+
21+
permissions: read-all
22+
23+
jobs:
24+
release:
25+
runs-on: ubuntu-latest
26+
name: Backport PR
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
with:
31+
ref: ${{ github.event.inputs.target_branch }}
32+
# Check out the entire repository so that the target commit is checked
33+
# out (by default, only fetches the single commit identified by the
34+
# `ref` argument).
35+
fetch-depth: 0
36+
persist-credentials: false
37+
- name: Cherry-pick commit
38+
run: |
39+
set -eo pipefail
40+
41+
AUTHOR_NAME="$(git log -1 --pretty='%an' ${{ github.event.inputs.commit }})"
42+
AUTHOR_EMAIL="$(git log -1 --pretty='%ae' ${{ github.event.inputs.commit }})"
43+
44+
git config --global user.name "$AUTHOR_NAME"
45+
git config --global user.email "$AUTHOR_EMAIL"
46+
47+
git cherry-pick ${{ github.event.inputs.commit }}
48+
49+
PR_TITLE="$(git log -1 --pretty=%s)"
50+
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
51+
52+
AUTHOR="$AUTHOR_NAME <$AUTHOR_EMAIL>"
53+
echo "AUTHOR=$AUTHOR" >> $GITHUB_ENV
54+
55+
- name: Submit PR
56+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
57+
with:
58+
author: "${{ env.AUTHOR }}"
59+
committer: "${{ env.AUTHOR }}"
60+
title: "${{ env.PR_TITLE }}"
61+
branch: backport-${{ github.event.inputs.commit }}
62+
push-to-fork: google-pr-creation-bot/zerocopy
63+
token: ${{ secrets.GOOGLE_PR_CREATION_BOT_TOKEN }}

0 commit comments

Comments
 (0)