Skip to content

Commit a4b75ac

Browse files
committed
add workflow for creating backport PRs
1 parent d5bf052 commit a4b75ac

3 files changed

Lines changed: 125 additions & 1 deletion

File tree

.github/workflows/on_label.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Heavily inspired by https://github.com/NixOS/nixpkgs/blob/a698ac1214cd924d4394ca9cd2691618765aa03c/.github/workflows/backport.yml
2+
3+
name: "On Backport Label"
4+
5+
permissions:
6+
pull-requests: write
7+
contents: write
8+
9+
on:
10+
pull_request:
11+
types:
12+
- closed
13+
- labeled
14+
15+
jobs:
16+
backport:
17+
if: github.event.pull_request.labels && contains(join(github.event.pull_request.labels.*.name, ', '), 'backport ')
18+
name: Backport PR 🔙
19+
runs-on: ubuntu-latest
20+
outputs:
21+
created_pull_numbers: ${{ steps.backport.outputs.created_pull_numbers }}
22+
steps:
23+
- name: Check actor permissions
24+
id: check-permissions
25+
uses: prince-chrismc/check-actor-permissions-action@v3.0.2
26+
with:
27+
permission: write
28+
29+
- name: Checkout
30+
uses: actions/checkout@v4.2.2
31+
32+
- name: Create backport PR
33+
id: backport
34+
uses: korthout/backport-action@v3.2.1
35+
with:
36+
merge_commits: "skip"
37+
add_author_as_assignee: true
38+
copy_requested_reviewers: true
39+
40+
trigger-ci:
41+
name: Trigger CI on created branches 🚀
42+
needs: backport
43+
strategy:
44+
matrix:
45+
pr: fromJSON("[${{ needs.backport.outputs.created_branches }}]")
46+
uses: ./.github/workflows/run_trigger_backport_ci.yml
47+
with:
48+
pr: ${{ matrix.pr }}

.github/workflows/on_push.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1-
name: "Push"
1+
name: "On Push"
22

33
on:
44
push:
55
branches:
66
- main
77
- "release-*"
88
pull_request: {}
9+
workflow_dispatch:
10+
inputs:
11+
pr_number:
12+
description: "Pull Request Number"
13+
required: false
14+
default: ""
15+
post_result:
16+
description: "Post the result of the pipeline to the PR"
17+
required: false
18+
default: false
919

1020
jobs:
21+
start-comment:
22+
name: Post Start Comment 💬
23+
if: ${{ inputs.post_result }}
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: thollander/actions-comment-pull-request@v3.0.1
27+
with:
28+
pr-number: ${{ inputs.pr_number || github.event.pull_request.number }}
29+
comment-tag: ci-status
30+
message: |
31+
CI is currently running
32+
[See the logs here](https://${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
33+
1134
build:
1235
name: Build 🛠️
1336
uses: ./.github/workflows/run_build.yml
@@ -55,3 +78,28 @@ jobs:
5578
}
5679
5780
exit $exit
81+
82+
finish-comment:
83+
name: Post Finish Comment 💬
84+
if: ${{ inputs.post_result }}
85+
needs:
86+
- start-comment
87+
- build
88+
- checks
89+
- tests
90+
- docs
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: thollander/actions-comment-pull-request@v3.0.1
94+
with:
95+
pr-number: ${{ inputs.pr_number || github.event.pull_request.number }}
96+
comment-tag: ci-status
97+
mode: update
98+
message: |
99+
CI has finished:
100+
- 📋 Checks: ${{ needs.checks.result && '✅' || '❌' }}
101+
- 🛠️ Build: ${{ needs.build.result && '✅' || '❌' }}
102+
- 🧪 Tests: ${{ needs.tests.result && '✅' || '❌' }}
103+
- 📕 Docs: ${{ needs.docs.result && '✅' || '❌' }}
104+
105+
[See the logs here](https://${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run Backport CI
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pr:
7+
required: true
8+
type: number
9+
10+
jobs:
11+
trigger-ci:
12+
name: Trigger CI on Backport Branch 🚀
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Find branch
16+
id: find_branch
17+
env:
18+
GH_TOKEN: ${{ github.token }}
19+
run: |
20+
branch=$(gh pr view ${{ inputs.pr }} --json headRefName -q .headRefName)
21+
echo "branch=$branch" >> $GITHUB_OUTPUT
22+
23+
- name: Workflow Dispatch
24+
uses: benc-uk/workflow-dispatch@v1.2.4
25+
with:
26+
workflow: "on_push.yml"
27+
ref: ${{ steps.find_branch.outputs.branch }}
28+
inputs: '{"post_result": true}'

0 commit comments

Comments
 (0)