Repository navigation
178 lines (155 loc) ยท 6.56 KB
/
Copy pathsync-docs.yml
File metadata and controls
178 lines (155 loc) ยท 6.56 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
name: sync-docs
# ๋จธ์ง ํ ์์ ๋ง: ๋ธ๋์น์ push๋ ์ฝ๋๋ก ๋ฌธ์๋ฅผ ๋ค์ ์์ฑํ๊ณ , ๋ณ๊ฒฝ์ด ์์ผ๋ฉด ๋ฌธ์ ์
๋ฐ์ดํธ PR์ ๋ง๋ ๋ค.
#
# ํฌํฌ PR์ด๋ Dependabot PR์ฒ๋ผ apply-docs๊ฐ PR ๋ธ๋์น์ ์ปค๋ฐํ์ง ๋ชปํ ๊ฒฝ์ฐ๋ฅผ ๋ฐ์์ค๋ค.
# self-hosted ๋ฌ๋๋ ํฌํฌ PR ์ฝ๋๋ ์คํํ๋ฏ๋ก App ํค๋ ๊ฑฐ๊ธฐ์ ์ฐ์ง ์๋๋ค.
# ์์ฑ์ self-hosted(์ํฌ๋ฆฟ ์์), ์ปค๋ฐ๊ณผ PR ์์ฑ์ hosted ๋ฌ๋์์ ๋๋ ํ๋ค.
on:
push:
branches:
- develop
- main
- 'release/*'
paths:
- "**.swift"
- "Sources/Montage/Asset/Icon.xcassets/**"
- "GETTINGSTARTED.md"
- "scripts/generate_docc.sh"
- "scripts/docc_to_md.js"
- "scripts/build_mcp_data.js"
- "scripts/generate_third_party_licenses.mjs"
- "Makefile"
- "Package.swift"
- "Package.resolved"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: sync-docs-${{ github.ref }}
cancel-in-progress: true
jobs:
generate:
runs-on: self-hosted
outputs:
changed: ${{ steps.patch.outputs.changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
- name: Generate documentation
run: |
xcodebuild -version
make generate
- name: Create documentation patch
id: patch
run: |
git add -A -- documentation packages/montage-mcp/data THIRD_PARTY_LICENSES.md
mkdir -p "$RUNNER_TEMP/docs-patch"
git diff --cached --binary --no-renames > "$RUNNER_TEMP/docs-patch/docs.patch"
xcodebuild -version | head -1 > "$RUNNER_TEMP/docs-patch/xcode-version.txt"
if [ -s "$RUNNER_TEMP/docs-patch/docs.patch" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
git diff --cached --stat
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "Documentation artifacts are up to date."
fi
- name: Upload documentation patch
if: steps.patch.outputs.changed == 'true'
uses: actions/upload-artifact@v4
with:
name: docs-patch
path: ${{ runner.temp }}/docs-patch/
retention-days: 3
publish:
needs: generate
runs-on: ubuntu-latest
steps:
- name: Download documentation patch
if: needs.generate.outputs.changed == 'true'
uses: actions/download-artifact@v4
with:
name: docs-patch
path: ${{ runner.temp }}/docs-patch
- name: Check patch
if: needs.generate.outputs.changed == 'true'
env:
PATCH: ${{ runner.temp }}/docs-patch/docs.patch
run: |
# apply-docs์ ๊ฐ์ ๊ฒ์ฆ. self-hosted ๋ฌ๋๊ฐ ์ค์ผ๋์ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ๋ค.
if [ "$(wc -c < "$PATCH")" -gt 52428800 ]; then
echo "::error::patch๊ฐ ๋๋ฌด ํฝ๋๋ค."
exit 1
fi
ALLOWED='^(documentation/|packages/montage-mcp/data/|THIRD_PARTY_LICENSES\.md$)'
git apply --numstat -z "$PATCH" | tr '\0' '\n' | cut -f3- > "$RUNNER_TEMP/paths.txt"
if [ ! -s "$RUNNER_TEMP/paths.txt" ]; then
echo "::error::patch๋ฅผ ํด์ํ ์ ์์ต๋๋ค."
exit 1
fi
if grep -Ev "$ALLOWED" "$RUNNER_TEMP/paths.txt" || grep -F '..' "$RUNNER_TEMP/paths.txt"; then
echo "::error::ํ์ฉ๋์ง ์์ ๊ฒฝ๋ก๊ฐ patch์ ์์ต๋๋ค."
exit 1
fi
git apply --summary "$PATCH" > "$RUNNER_TEMP/summary.txt"
if grep -Ev '^ (create|delete) mode 100644 ' "$RUNNER_TEMP/summary.txt"; then
echo "::error::patch์ ํ์ฉ๋์ง ์์ ํ์ผ ๋ชจ๋๋ rename/copy๊ฐ ์์ต๋๋ค."
exit 1
fi
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
permission-pull-requests: write
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
token: ${{ steps.app-token.outputs.token }}
fetch-depth: 1
- name: Commit and open PR
env:
CHANGED: ${{ needs.generate.outputs.changed }}
PATCH: ${{ runner.temp }}/docs-patch/docs.patch
XCODE_VERSION_FILE: ${{ runner.temp }}/docs-patch/xcode-version.txt
BASE_BRANCH: ${{ github.ref_name }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# ๋์ ๋ธ๋์น๋ง๋ค ๋ด ๋ธ๋์น ํ๋๋ฅผ ๋๊ณ , ๋งค๋ฒ ์ต์ ์ปค๋ฐ ๊ธฐ์ค์ผ๋ก ๋ฎ์ด์ด๋ค.
SYNC_BRANCH="docs/sync-${BASE_BRANCH}"
EXISTING_PR=$(gh pr list --head "$SYNC_BRANCH" --base "$BASE_BRANCH" --state open --json number --jq '.[0].number // ""')
# ๋ฌธ์๊ฐ ์ต์ ์ด๋ฉด ์์ sync PR์ ๋ ์ด์ ํ์ ์์ผ๋ฏ๋ก ๋ซ๋๋ค.
if [ "$CHANGED" != "true" ]; then
if [ -n "$EXISTING_PR" ]; then
gh pr close "$EXISTING_PR" --delete-branch --comment "${GITHUB_SHA::7} ๊ธฐ์ค์ผ๋ก ๋ฌธ์๊ฐ ์ต์ ์ด๋ผ ๋ซ์ต๋๋ค."
fi
exit 0
fi
BOT_USER="${APP_SLUG}[bot]"
BOT_ID=$(gh api "/users/${BOT_USER}" --jq .id)
git config user.name "$BOT_USER"
git config user.email "${BOT_ID}+${BOT_USER}@users.noreply.github.com"
git checkout -B "$SYNC_BRANCH"
git apply --index "$PATCH"
XCODE_VERSION=$(head -1 "$XCODE_VERSION_FILE" 2>/dev/null || echo "unknown")
git commit -m "docs: ๋ฌธ์ ์
๋ฐ์ดํธ" -m "sync-docs๊ฐ ${XCODE_VERSION}๋ก ${GITHUB_SHA::7} ๊ธฐ์ค ๋ฌธ์๋ฅผ ๋ค์ ์์ฑํ์ต๋๋ค."
git push --force origin "HEAD:refs/heads/${SYNC_BRANCH}"
if [ -n "$EXISTING_PR" ]; then
echo "๊ธฐ์กด PR #${EXISTING_PR}์ ๊ฐฑ์ ํ์ต๋๋ค."
else
gh pr create \
--base "$BASE_BRANCH" \
--head "$SYNC_BRANCH" \
--title "docs: ๋ฌธ์ ์
๋ฐ์ดํธ (${BASE_BRANCH})" \
--body "๋จธ์ง๋ ์ฝ๋ ๊ธฐ์ค์ผ๋ก ๋ฌธ์๊ฐ ์ต์ ์ด ์๋์ด์ sync-docs๊ฐ ๋ค์ ์์ฑํ์ต๋๋ค. ํฌํฌ PR์ด๋ Dependabot PR์ฒ๋ผ PR ๋จ๊ณ์์ ๋ฌธ์๋ฅผ ์ปค๋ฐํ์ง ๋ชปํ ๊ฒฝ์ฐ์ ๋ง๋ค์ด์ง๋๋ค."
fi