-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (74 loc) · 3.01 KB
/
auto_pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Auto PR
on:
push:
branches:
- dev
jobs:
create_or_update_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install GitHub CLI
run: sudo apt-get install gh
- name: Get committer username and email
run: |
committer_username=$(git log -1 --pretty=format:'%an')
committer_email=$(git log -1 --pretty=format:'%ae')
echo "committer_username=$committer_username" >> $GITHUB_ENV
echo "committer_email=$committer_email" >> $GITHUB_ENV
- name: Hash committer username
id: hash_committer
run: |
branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }')
echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV
echo "::set-output name=branch_name::dev_pr_$branch_name"
- name: Configure git
run: |
git config --global user.name "${{ env.committer_username }}"
git config --global user.email "${{ env.committer_email }}"
- name: Create and push new branch based on dev
run: |
git fetch origin
git checkout dev
git pull origin dev
git checkout -b ${{ steps.hash_committer.outputs.branch_name }}
echo "$(date +%s%N)" > timestamp.txt # Create a file with current timestamp in nanoseconds
git add timestamp.txt
git commit -m "Add timestamp file to ensure branch differences"
git push origin ${{ steps.hash_committer.outputs.branch_name }}
- name: Create or Update Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.hash_committer.outputs.branch_name }}
base: main
title: "Auto PR from ${{ steps.hash_committer.outputs.branch_name }}"
body: "This is an automated PR created from ${{ steps.hash_committer.outputs.branch_name }}"
draft: false
update_existing: true # Automatically update the existing PR if it exists
sync_commits:
runs-on: ubuntu-latest
needs: create_or_update_pr
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install GitHub CLI
run: sudo apt-get install gh
- name: Get committer username
run: |
committer_username=$(git log -1 --pretty=format:'%an')
echo "committer_username=$committer_username" >> $GITHUB_ENV
- name: Hash committer username
id: hash_committer
run: |
branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }')
echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV
echo "::set-output name=branch_name::dev_pr_$branch_name"
- name: Fetch and rebase on existing branch
run: |
git fetch origin
git checkout ${{ needs.create_or_update_pr.outputs.branch_name }}
git pull origin ${{ needs.create_or_update_pr.outputs.branch_name }} --rebase
git push origin ${{ needs.create_or_update_pr.outputs.branch_name }}