-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (126 loc) · 4.6 KB
/
template.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
name: template
on:
workflow_call:
inputs:
BRANCH:
description: 'Branch to run the workflow on'
required: true
default: 'live'
type: string
FORCE_UPDATE:
description: 'Force update the branch'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
BRANCH:
description: 'Branch to run the workflow on'
required: true
default: 'live'
type: string
FORCE_UPDATE:
description: 'Force update the branch'
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
branch_name="${{ inputs.BRANCH }}"
git config user.name "GitHub Actions"
git config user.email [email protected]
cleanup() {
find . -maxdepth 1 -mindepth 1 ! -name .git -exec rm -rf {} +
}
if git show-ref --quiet "refs/remotes/origin/${branch_name}"; then
echo "Re-using existing branch..."
git fetch origin "${branch_name}"
git checkout -b "${branch_name}" "origin/${branch_name}"
git pull --rebase origin "${branch_name}"
git rm -rfq . || true
cleanup
else
echo "Creating new branch..."
cleanup
git rm -rfq . || true
git checkout --orphan "${branch_name}"
git commit --allow-empty --message "Initialize"
git push --set-upstream origin "${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
branch=${{ inputs.BRANCH }}
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 "${branch}: ${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=${{ inputs.BRANCH }}
cd ./.wow-ui-source
remote_commit_hash=$(git rev-parse HEAD)
message="Synced to commit ${remote_commit_hash}"
cd ..
bin/annotate --inputDir=./.wow-ui-source/Interface --outputDir=./.annotations_temp/Annotations --linkPrefix="https://github.com/Gethe/wow-ui-source/blob/${branch}/Interface"
cd ./.annotations_temp
git config user.name "GitHub Actions"
git config user.email [email protected]
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 "${branch}"
else
echo "Unable to commit."
fi
else
echo "Nothing to commit."
fi
echo "Done!"