-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (148 loc) · 5.8 KB
/
merge_changes.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Merge changes to all target branches
on: workflow_dispatch
jobs:
get_avatar_branches:
name: Get avatar branches
uses: ./.github/workflows/get_target_branches.yml
with:
include_base: true
check:
name: Check if the specified branch is not avatar branch
needs: get_avatar_branches
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Check if the specified branch is not avatar branch
id: check_2
run: echo is_avatar_branch=$(echo ${TARGET_BRANCHES} | jq "contains([\"${BRANCH_NAME}\"])") >> $GITHUB_OUTPUT
env:
TARGET_BRANCHES: ${{ needs.get_avatar_branches.outputs.target_branches }}
BRANCH_NAME: ${{ github.ref_name }}
- name: Output error
if: ${{ steps.check_2.outputs.is_avatar_branch == 'true' }}
run: |
echo "::error::Cannot specify an avatar branch as a merge branch."
exit 1
merge_branch:
name: Merge branch to avatar branches
needs:
- get_avatar_branches
- check
if: ${{ needs.check.result == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
target_branch: ${{ fromJSON(needs.get_avatar_branches.outputs.target_branches) }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
ref: ${{ matrix.target_branch }}
- name: Configure Git user
run: |
git remote set-url origin https://github-actions:${TOKEN}@github.com/${REPOSITORY}
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
env:
TOKEN: ${{ github.token }}
REPOSITORY: ${{ github.repository }}
- name: Check if readme templates have been changed (base)
id: check_readme_changes_base
if: ${{ matrix.target_branch == 'base' }}
run: git diff --name-only origin/${MERGE_BRANCH} | grep -e '.github/README_templates/' -e '.github/readme_generator/' -e '.github/workflows/'
env:
MERGE_BRANCH: ${{ github.ref_name }}
continue-on-error: true
- name: Merge branch
id: merge_branch
run: git merge origin/${BRANCH_NAME}
env:
BRANCH_NAME: ${{ github.ref_name }}
continue-on-error: true
- name: Output error
if: ${{ steps.merge_branch.outcome == 'failure' }}
run: echo "::error::Failed to merge \"${MERGE_BRANCH}\" to \"${BASE_BRANCH}\" because of merge conflicts. You need to resolve conflicts manually."
env:
MERGE_BRANCH: ${{ github.ref_name }}
BASE_BRANCH: ${{ matrix.target_branch }}
- name: Push changes
if: ${{ steps.merge_branch.outcome == 'success' }}
run: git push origin
- name: Check if readme templates have been changed
id: check_readme_changes
if: ${{ steps.merge_branch.outcome == 'success' }}
run: |
if [ ${BASE_BRANCH} = 'base' ]; then
echo ${BASE_RESULT} | grep 'success'
else
git diff --name-only HEAD~ | grep -e '.github/README_templates/' -e '.github/readme_generator/' -e '.github/workflows/'
fi
env:
BASE_RESULT: ${{ steps.check_readme_changes_base.outcome }}
BASE_BRANCH: ${{ matrix.target_branch }}
continue-on-error: true
- name: Output readme status
if: ${{ steps.merge_branch.outcome == 'success' && steps.check_readme_changes.outcome == 'success' }}
run: |
echo '{"generate_required": true}' > ./${BRANCH_NAME}.json
env:
BRANCH_NAME: ${{ matrix.target_branch }}
- name: Output readme status
if: ${{ steps.merge_branch.outcome != 'success' || steps.check_readme_changes.outcome != 'success' }}
run: |
echo '{"generate_required": false}' > ./${BRANCH_NAME}.json
env:
BRANCH_NAME: ${{ matrix.target_branch }}
- name: Upload artifact
uses: actions/[email protected]
with:
name: ${{ matrix.target_branch }}
path: ./${{ matrix.target_branch }}.json
retention-days: 1
get_readme_array:
name: Get array of branches that are required to generate readme
needs: merge_branch
runs-on: ubuntu-latest
outputs:
branch_array: ${{ steps.output_branch_array.outputs.branch_array }}
branch_count: ${{ steps.output_branch_array.outputs.branch_count }}
steps:
- name: Prepare artifacts directory
run: mkdir ./branches
- name: Download artifacts
uses: actions/[email protected]
with:
path: ./branches
- name: Get generate readme branch array
run: |
echo -n '[' > ./readme_array.json
for file in $(ls ./branches); do
result=$(cat ./branches/${file}/${file}.json | jq '.generate_required')
if [ ${result} = 'true' ]; then
echo "\"${file}\", " | sed -z 's/.json//g; s/\r//g; s/\n//g' >> ./readme_array.json
fi
done
echo $(cat ./readme_array.json | sed 's/, $//g')] > ./readme_array.json
- name: Output generate readme branch array
id: output_branch_array
run: |
echo branch_array=$(<./readme_array.json) >> $GITHUB_OUTPUT
echo branch_count=$(cat ./readme_array.json | jq length) >> $GITHUB_OUTPUT
generate_readme:
name: Generate readme
needs: get_readme_array
if: ${{ needs.get_readme_array.outputs.branch_count > 0 }}
permissions:
contents: write
strategy:
matrix:
target_branch: ${{ fromJSON(needs.get_readme_array.outputs.branch_array) }}
uses: ./.github/workflows/generate_readme_core.yml
with:
branch-name: ${{ matrix.target_branch }}