Repository navigation
194 lines (179 loc) · 8.31 KB
/
Copy pathaether-sync-upstream.yml
File metadata and controls
194 lines (179 loc) · 8.31 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
192
193
194
name: Aether - Sync upstream
# Follows NuvioMedia/NuvioMobile: merges each new upstream release (or the upstream branch tip)
# into this fork, then builds and publishes the IPA with the AetherEngine player.
#
# Settings (Settings > Secrets and variables > Actions):
# secret FORK_SYNC_TOKEN fine-grained token with Contents + Workflows read/write on this
# repository. Needed whenever an upstream merge touches
# .github/workflows (the default token is not allowed to push those).
# secret NUVIO_LOCAL_PROPERTIES_BASE64 optional, same as upstream's (runtime keys)
# variable UPSTREAM_REPOSITORY default NuvioMedia/NuvioMobile
# variable UPSTREAM_BRANCH default cmp-rewrite
# variable AETHER_TRACK "release" (default) or "branch"
# variable AETHER_MACOS_RUNNER default xcode-27
on:
schedule:
- cron: "23 */6 * * *"
workflow_dispatch:
inputs:
track:
description: Follow upstream releases, or the tip of the upstream branch
type: choice
options:
- release
- branch
default: release
force_build:
description: Build and publish even if this version was already published
type: boolean
default: false
permissions:
contents: write
issues: write
concurrency:
group: aether-sync-upstream
cancel-in-progress: false
jobs:
sync:
name: Merge upstream
# Fork-only: upstream is only ever read (fetch, release list); everything is written to this
# repository, and the workflow never runs in the upstream repository itself.
if: github.repository != 'NuvioMedia/NuvioMobile'
runs-on: ubuntu-latest
env:
UPSTREAM_REPOSITORY: ${{ vars.UPSTREAM_REPOSITORY || 'NuvioMedia/NuvioMobile' }}
UPSTREAM_BRANCH: ${{ vars.UPSTREAM_BRANCH || 'cmp-rewrite' }}
TRACK: ${{ inputs.track || vars.AETHER_TRACK || 'release' }}
FORCE_BUILD: ${{ inputs.force_build || false }}
BRANCH: ${{ github.ref_name }}
HAS_SYNC_TOKEN: ${{ secrets.FORK_SYNC_TOKEN != '' }}
GH_TOKEN: ${{ github.token }}
outputs:
build: ${{ steps.decide.outputs.build }}
upstream_tag: ${{ steps.upstream.outputs.tag }}
branch: ${{ github.ref_name }}
steps:
- name: Check out fork
uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
token: ${{ secrets.FORK_SYNC_TOKEN || github.token }}
- name: Find the upstream target
id: upstream
run: |
git remote add upstream "https://github.com/${UPSTREAM_REPOSITORY}.git"
if [[ "${TRACK}" == "branch" ]]; then
git fetch --no-tags upstream "${UPSTREAM_BRANCH}"
ref="refs/remotes/upstream/${UPSTREAM_BRANCH}"
label="${UPSTREAM_REPOSITORY}@${UPSTREAM_BRANCH}"
tag=""
else
# Newest published release, pre-releases included (upstream ships "x.y.z-beta").
tag="$(gh release list --repo "${UPSTREAM_REPOSITORY}" --exclude-drafts --limit 1 \
--json tagName --jq '.[0].tagName')"
if [[ -z "${tag}" ]]; then
echo "No upstream release found." >&2
exit 1
fi
git fetch --no-tags upstream "+refs/tags/${tag}:refs/upstream-tags/${tag}"
ref="refs/upstream-tags/${tag}"
label="${UPSTREAM_REPOSITORY} ${tag}"
fi
{
echo "ref=${ref}"
echo "label=${label}"
echo "tag=${tag}"
} >> "${GITHUB_OUTPUT}"
echo "Upstream target: ${label} ($(git rev-parse --short "${ref}^{commit}"))"
- name: Merge
id: merge
env:
REF: ${{ steps.upstream.outputs.ref }}
LABEL: ${{ steps.upstream.outputs.label }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
report() {
local title="Upstream sync blocked: ${LABEL}"
local body_file="${RUNNER_TEMP}/issue.md"
{
echo "$1"
echo
echo "Resolve it locally, then push:"
echo
echo '```bash'
echo "git remote add upstream https://github.com/${UPSTREAM_REPOSITORY}.git"
echo "git fetch upstream"
echo "git merge $(git rev-parse "${REF}^{commit}") # ${LABEL}"
echo "python3 aether/scripts/patch-xcode-project.py # must still succeed (do not commit its changes)"
echo "git checkout -- iosApp/iosApp.xcodeproj/project.pbxproj"
echo "git push"
echo '```'
echo
echo "Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
} > "${body_file}"
cat "${body_file}" >> "${GITHUB_STEP_SUMMARY}"
# Best effort: issues may be disabled on the fork.
existing="$(gh issue list --repo "${GITHUB_REPOSITORY}" --state open --search "\"${title}\" in:title" \
--json number --jq '.[0].number // empty' 2>/dev/null || true)"
if [[ -n "${existing}" ]]; then
gh issue comment "${existing}" --repo "${GITHUB_REPOSITORY}" --body-file "${body_file}" || true
else
gh issue create --repo "${GITHUB_REPOSITORY}" --title "${title}" --body-file "${body_file}" || true
fi
}
target="$(git rev-parse "${REF}^{commit}")"
if git merge-base --is-ancestor "${target}" HEAD; then
echo "${BRANCH} already contains ${LABEL}."
echo "merged=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
if ! git merge --no-ff --no-edit -m "Merge upstream ${LABEL} into ${BRANCH}" "${target}"; then
# shellcheck disable=SC2016 # "$" is sed's end-of-line anchor
conflicts="$(git diff --name-only --diff-filter=U | sed 's/^/- `/; s/$/`/')"
git merge --abort
report "Merging ${LABEL} into \`${BRANCH}\` conflicts in:"$'\n\n'"${conflicts}"
exit 1
fi
# The AetherEngine integration must still apply to upstream's Xcode project.
cp iosApp/iosApp.xcodeproj/project.pbxproj "${RUNNER_TEMP}/project.pbxproj"
if ! python3 aether/scripts/patch-xcode-project.py "${RUNNER_TEMP}/project.pbxproj"; then
report "After merging ${LABEL}, \`aether/scripts/patch-xcode-project.py\` no longer applies to upstream's Xcode project. Nothing was pushed."
exit 1
fi
if ! git push origin "HEAD:${BRANCH}" 2> "${RUNNER_TEMP}/push.log"; then
cat "${RUNNER_TEMP}/push.log" >&2
if grep -q "workflow" "${RUNNER_TEMP}/push.log" && [[ "${HAS_SYNC_TOKEN}" != "true" ]]; then
report "The merge of ${LABEL} changes \`.github/workflows\`, which the default token cannot push. Add a \`FORK_SYNC_TOKEN\` secret (fine-grained token, Contents and Workflows: read and write) and re-run."
else
report "Pushing the merge of ${LABEL} to \`${BRANCH}\` failed."
fi
exit 1
fi
echo "merged=true" >> "${GITHUB_OUTPUT}"
echo "Merged ${LABEL} into ${BRANCH}." >> "${GITHUB_STEP_SUMMARY}"
- name: Decide whether to build
id: decide
run: |
version="$(sed -nE 's/^[[:space:]]*MARKETING_VERSION[[:space:]]*=[[:space:]]*([^[:space:]#]+).*$/\1/p' \
iosApp/Configuration/Version.xcconfig | head -n 1)"
published="$(gh release list --repo "${GITHUB_REPOSITORY}" --limit 200 --json tagName \
--jq "[.[] | select(.tagName | startswith(\"${version}-aether\"))] | length")"
build=false
if [[ "${FORCE_BUILD}" == "true" || "${published}" == "0" ]]; then
build=true
fi
echo "build=${build}" >> "${GITHUB_OUTPUT}"
echo "Version ${version}: ${published} AetherEngine release(s) published, build=${build}" >> "${GITHUB_STEP_SUMMARY}"
build:
name: Build and publish
needs: sync
if: needs.sync.outputs.build == 'true'
uses: ./.github/workflows/aether-build-ipa.yml
with:
ref: ${{ needs.sync.outputs.branch }}
configuration: Release
publish: true
upstream_tag: ${{ needs.sync.outputs.upstream_tag }}
secrets: inherit