Skip to content

Commit e9d4f76

Browse files
authored
Add action for cherry-picking staging changes (#243)
1 parent 69baab3 commit e9d4f76

File tree

2 files changed

+66
-54
lines changed

2 files changed

+66
-54
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Cherry pick staging PRs merged into main
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- 'main'
9+
10+
11+
jobs:
12+
create-pr-for-staging:
13+
if: |
14+
github.event.pull_request.merged == true &&
15+
contains(github.event.pull_request.labels.*.name, 'staging')
16+
name: Create PR against staging branch
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout main
21+
uses: actions/checkout@v4
22+
with:
23+
ref: main
24+
fetch-depth: 2
25+
26+
- name: Fetch and checkout latest staging branch
27+
run: |
28+
branch=$(git ls-remote --heads origin 'staging*' | tail -1 | awk 'gsub(".*refs/heads/","")')
29+
git fetch origin $branch
30+
git checkout $branch
31+
32+
- name: Set git credentials
33+
run: |
34+
git config --global user.name openslides-automation
35+
git config --global user.email openslides-automation@users.noreply.github.com
36+
37+
- name: Cherry-pick new commit
38+
id: cherry-pick
39+
run: |
40+
git fetch origin
41+
# -m 1 to also be able to cherry-pick merge commits
42+
git cherry-pick -m 1 ${{ github.sha }} || {
43+
echo "error=1" >> $GITHUB_OUTPUT
44+
git add .
45+
git cherry-pick --continue
46+
}
47+
48+
- name: Generate access token
49+
uses: tibdex/github-app-token@v2
50+
id: generate-token
51+
with:
52+
app_id: ${{ secrets.AUTOMATION_APP_ID }}
53+
private_key: ${{ secrets.AUTOMATION_APP_PRIVATE_KEY }}
54+
55+
- name: Create or update PR
56+
uses: peter-evans/create-pull-request@v6
57+
with:
58+
token: ${{ steps.generate-token.outputs.token }}
59+
branch: apply/commit-${{ github.sha }}
60+
delete-branch: true
61+
title: "[Cherry-Pick] ${{ github.event.pull_request.title }}"
62+
body: "Triggered by commit [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})\n\n${{ steps.cherry-pick.outputs.error && 'There were conflicts during the cherry-pick. These were commited without any resolving. Please resolve them manually and push the result to this branch before merging.' || 'The cherry-pick was successful without any conflicts. You should be able to simply merge this PR.' }}"
63+
reviewers: ${{ github.event.pull_request.user.login }}
64+
assignees: ${{ github.event.pull_request.user.login }}
65+
labels: picked-to-staging
66+
milestone: 4

.github/workflows/staging-to-main.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)