-
Notifications
You must be signed in to change notification settings - Fork 1
191 lines (182 loc) · 6.63 KB
/
template.yml
File metadata and controls
191 lines (182 loc) · 6.63 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: template
on:
workflow_dispatch:
inputs:
BRANCH:
description: 'Branch to run the workflow on'
required: true
default: 'live'
type: string
TARGET_BRANCH_SUFFIX:
description: 'Suffix for the target branch of this repo'
required: false
default: ''
type: string
FLAVOR:
description: 'Flavor to filter the input for'
required: true
default: 'mainline'
type: choice
options:
- mainline
- mists
- cata
- wrath
- tbc
- vanilla
FORCE_UPDATE:
description: 'Force update the branch'
required: false
default: false
type: boolean
MIX_ANNOTATIONS_INTO_SOURCE:
description: 'Include all lua source files, and add class annotations to the source files'
required: false
default: false
type: boolean
INCLUDE_RAW_XML_SOURCE:
description: 'Include raw XML source files'
required: false
default: false
type: boolean
workflow_call:
inputs:
BRANCH:
description: 'Branch to run the workflow on'
required: true
default: 'live'
type: string
TARGET_BRANCH_SUFFIX:
description: 'Suffix for the target branch of this repo'
required: false
default: ''
type: string
FLAVOR:
description: 'Flavor to filter the input for'
required: true
default: 'mainline'
type: string
FORCE_UPDATE:
description: 'Force update the branch'
required: false
default: false
type: boolean
MIX_ANNOTATIONS_INTO_SOURCE:
description: 'Include all lua source files, and add class annotations to the source files'
required: false
default: false
type: boolean
INCLUDE_RAW_XML_SOURCE:
description: 'Include raw XML source files'
required: false
default: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout latest Getho/wow-ui-source
if: ${{ steps.check.outputs.skip != 'true' }}
uses: actions/checkout@v4
with:
repository: gethe/wow-ui-source
path: ./.wow-ui-source
fetch-depth: 1
ref: ${{ inputs.BRANCH }}
- name: Checkout or create latest Annotations branch
if: ${{ steps.check.outputs.skip != 'true' }}
run: |
set -ex
git clone "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" ./.annotations_temp
cd ./.annotations_temp
git fetch --prune origin
target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}"
git config user.name "GitHub Actions"
git config user.email noreply@github.com
cleanup() {
find . -maxdepth 1 -mindepth 1 ! -name .git -exec rm -rf {} +
}
if git show-ref --quiet "refs/remotes/origin/${target_branch_name}"; then
echo "Re-using existing branch..."
git fetch origin "${target_branch_name}"
git checkout -b "${target_branch_name}" "origin/${target_branch_name}"
git pull --rebase origin "${target_branch_name}"
git rm -rfq . || true
cleanup
else
echo "Creating new branch..."
cleanup
git rm -rfq . || true
git checkout --orphan "${target_branch_name}"
git commit --allow-empty --message "Initialize"
git push --set-upstream origin "${target_branch_name}"
fi
cp ../annotation_branch_readme.md README.md
- name: Compare local and remote commit hashes
id: check
run: |
set -ex
if [[ "${{ inputs.FORCE_UPDATE }}" == "true" ]]; then
echo "skip=false" >> $GITHUB_OUTPUT
exit 0
fi
target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}"
cd ./.wow-ui-source
remote_commit_hash=$(git rev-parse HEAD)
cd ../.annotations_temp
local_commit_hash=$(git log --oneline -n1 | grep -Po "Synced to commit \K.*" || echo "unknown")
echo "${target_branch_name}: ${local_commit_hash} -> ${remote_commit_hash}"
if [[ "${local_commit_hash}" == "${remote_commit_hash}" ]]; then
echo "Branch is already up-to-date."
echo "skip=true" >> $GITHUB_OUTPUT
fi
- name: Setup PHP with composer v2
if: ${{ steps.check.outputs.skip != 'true' }}
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: xml, dom
tools: composer:v2
- name: Install dependencies
if: ${{ steps.check.outputs.skip != 'true' }}
run: |
set -ex
composer install --no-interaction --no-progress --no-suggest --prefer-dist
- name: Create annotations and push
if: ${{ steps.check.outputs.skip != 'true' }}
run: |
set -ex
branch_name="${{ inputs.BRANCH }}"
target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}"
flavor=${{ inputs.FLAVOR }}
cd ./.wow-ui-source
remote_commit_hash=$(git rev-parse HEAD)
message="Synced to commit ${remote_commit_hash}"
cd ..
extraArgs=""
if [[ "${{ inputs.MIX_ANNOTATIONS_INTO_SOURCE }}" == "true" ]]; then
extraArgs="${extraArgs} --mixAnnotationsIntoSource"
fi
if [[ "${{ inputs.INCLUDE_RAW_XML_SOURCE }}" == "true" ]]; then
extraArgs="${extraArgs} --includeRawXmlSource"
fi
bin/annotate ${flavor} --inputDir=./.wow-ui-source/Interface --outputDir=./.annotations_temp/Annotations --linkPrefix="https://github.com/Gethe/wow-ui-source/blob/${branch_name}/Interface" ${extraArgs}
cd ./.annotations_temp
git config user.name "GitHub Actions"
git config user.email noreply@github.com
git add -v .
echo "Checking if there are changes to be commited and pushed..."
if [[ -n $(git status --porcelain) ]] || ! git diff --quiet; then
if git commit --message "${message}" >/dev/null 2>&1; then
echo "Commiting and pushing..."
git push --force-with-lease --set-upstream origin "${target_branch_name}"
else
echo "Unable to commit."
fi
else
echo "Nothing to commit."
fi
echo "Done!"