-
Notifications
You must be signed in to change notification settings - Fork 45
88 lines (75 loc) · 2.86 KB
/
close-pull-request.yaml
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
name: PR Closed - purging developer_branch
on:
pull_request_target:
branches: [main]
types: [closed]
jobs:
# All Closed branches reverse commits made by the open/reopen/sync GH Action
revert-testing-commit:
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: developer_branch
fetch-depth: 0
- name: Remove Updates from this PR
run: |
# Get Commits from this PR
TAG=PR_${{ github.event.pull_request.number }}
# Revert Commits or Log that no change was made
git config --local user.email "dev@null"
git config --local user.name "Conformitron Bot"
for commit in $(git rev-list HEAD --grep=$TAG); do
echo $commit
git revert $commit --no-edit || echo "Commit $commit not reverted"
done
git push
# Accepted PR's apply merged changes
commit-accepted-pr-files:
if: github.event.pull_request.merged == true
needs: revert-testing-commit
timeout-minutes: 2
runs-on: ubuntu-latest
steps:
- name: Checkout Base
uses: actions/checkout@v4
- name: Checkout PR Code
run:
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr
- name: Remove Deleted Files, copy over added or modified files in accepted PR
id: find-namespace-yaml
run: |
# Pull file information down into a JSON array
readarray -t files < <(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | jq -c '.[]')
# Checkout and update Developer branch
git fetch --all
git config --local user.email "dev@null"
git config --local user.name "Conformitron Bot"
# fetch most recent update to dev
git checkout developer_branch
git pull
# Remove Deleted Files, copy over added or modified files
for item in "${files[@]}"; do
status=$(echo "$item" | jq -r '.status')
filename=$(echo "$item" | jq -r '.filename')
if [ "$status" == renamed ]; then
git checkout pr -- $filename
git add $filename
if [ -f $(echo "$item" | jq -r '.previous_filename') ]; then
git rm $(echo "$item" | jq -r '.previous_filename')
fi
echo "Renaming $filename"
elif [ "$status" != removed ]; then
git checkout pr -- $filename
git add $filename
echo "Moving $filename"
else
if [ -f $filename ]; then
echo "Deleting $filename"
git rm $filename
fi
fi
done
git commit -m "Adding new and changed files for merged PR_${{ github.event.pull_request.number }}"
git push