Skip to content

Commit f5aad57

Browse files
committed
2 parents 5e999fe + c58075a commit f5aad57

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

.github/workflows/pr.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 🔃 Create PRs
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
dry-run:
6+
description: 'Run the workflow without creating PRs'
7+
required: false
8+
default: false
9+
type: boolean
10+
schedule:
11+
- cron: '0 0 * * *'
12+
jobs:
13+
get-branches:
14+
outputs:
15+
branches: ${{ steps.get-branches.outputs.branches }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- name: Get branches
23+
id: get-branches
24+
shell: pwsh
25+
run: |
26+
$branches = git branch -r --format="%(refname:short)" | ForEach-Object { $_.Trim() -replace "^origin/", "" }
27+
# filter only branches that start with dev/
28+
$branches = $branches | Where-Object { $_ -match "^dev/" }
29+
$branchJson = ConvertTo-Json @($branches) -Compress
30+
Write-Host "branches=$branchJson"
31+
echo "branches=$branchJson" >> $env:GITHUB_OUTPUT
32+
create-pr:
33+
needs: get-branches
34+
strategy:
35+
max-parallel: 1
36+
matrix:
37+
branch: ${{fromJson(needs.get-branches.outputs.branches)}}
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
- name: Set Env
45+
run: |
46+
TARGET=$(echo ${{ matrix.branch }} | sed 's/dev\///')
47+
SOURCE=${{ matrix.branch }}
48+
49+
if [ -z "$TARGET" ]; then
50+
echo "TARGET is empty"
51+
exit 1
52+
fi
53+
54+
if [ -z "$SOURCE" ]; then
55+
echo "SOURCE is empty"
56+
exit 1
57+
fi
58+
59+
if [ "$SOURCE" == "$TARGET" ]; then
60+
echo "SOURCE is the same as TARGET"
61+
exit 1
62+
fi
63+
64+
echo "SOURCE=$SOURCE"
65+
echo "TARGET=$TARGET"
66+
echo "SOURCE=$SOURCE" >> $GITHUB_ENV
67+
echo "TARGET=$TARGET" >> $GITHUB_ENV
68+
- name: Run the Action
69+
if: ${{ github.event.inputs.dry-run == 'false' }}
70+
uses: devops-infra/[email protected]
71+
with:
72+
github_token: ${{ secrets.GITHUB_TOKEN }}
73+
source_branch: ${{ env.SOURCE }}
74+
target_branch: ${{ env.TARGET }}
75+
title: "Merge ${{ env.SOURCE }} into ${{ env.TARGET }}"
76+
reviewer: ${{ github.repository_owner }}
77+
assignee: ${{ github.repository_owner }}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: 🔃 Sync branches
2+
3+
on:
4+
push:
5+
branches:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
check-branch:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
is-valid-branch: ${{ steps.branch_check.outputs.is-valid-branch }}
14+
steps:
15+
- name: Check if branch name starts with 'v'
16+
id: branch_check
17+
run: |
18+
BRANCH_NAME=${{ github.ref }}
19+
if [[ $BRANCH_NAME =~ refs/heads/v.* ]]; then
20+
VALID=true
21+
else
22+
VALID=false
23+
fi
24+
25+
echo "is-valid-branch=$VALID" >> $GITHUB_OUTPUT
26+
merge-branches:
27+
needs: check-branch
28+
permissions:
29+
contents: write
30+
if: needs.check-branch.outputs.is-valid-branch == 'true'
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
- name: Merge into dev/v**
38+
run: |
39+
# Extract the version number from the branch name
40+
VERSION=$(echo "${GITHUB_REF}" | sed -n 's#refs/heads/v\([0-9]\+\)#\1#p')
41+
SOURCE_BRANCH="v${VERSION}"
42+
TARGET_BRANCH="dev/v${VERSION}"
43+
# Set git config
44+
git config user.name "${{ github.actor }}"
45+
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
46+
47+
48+
echo "Merging $SOURCE_BRANCH into $TARGET_BRANCH"
49+
50+
# Checkout the source branch
51+
git checkout $SOURCE_BRANCH
52+
git pull origin $SOURCE_BRANCH
53+
echo "Pulled latest for $SOURCE_BRANCH"
54+
55+
# Merge into the target branch
56+
git checkout $TARGET_BRANCH
57+
git merge --no-ff $SOURCE_BRANCH -m "Merge v$VERSION into dev/v$VERSION"
58+
echo "Merged $SOURCE_BRANCH into $TARGET_BRANCH"
59+
60+
# Push changes
61+
git push origin $TARGET_BRANCH
62+
echo "Pushed changes to $TARGET_BRANCH"
63+

0 commit comments

Comments
 (0)