Skip to content

Commit 254e312

Browse files
committed
ci: fix rsync workflow
1 parent 5945435 commit 254e312

3 files changed

Lines changed: 49 additions & 17 deletions

File tree

.github/workflows/reusable-publish-rsync.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,29 @@ jobs:
131131
132132
REPO_SOURCE_REF_TYPE="$SOURCE_REF_TYPE" \
133133
REPO_SOURCE_REF_NAME="$SOURCE_REF_NAME" \
134+
REPO_PUBLIC_BASE_URL="https://repo.keen-pbr.fyi" \
134135
make -C "$GITHUB_WORKSPACE/src" build-repository \
135136
REPO_DIR="$GITHUB_WORKSPACE/staged-repository" \
136137
REPO_TARGET_ROOT="$branch"
137138
139+
printf '%s\n' \
140+
'<!doctype html>' \
141+
'<html lang="en">' \
142+
'<head>' \
143+
' <meta charset="utf-8">' \
144+
' <meta http-equiv="refresh" content="0; url=https://repo.keen-pbr.fyi/repository/stable/">' \
145+
' <link rel="canonical" href="https://repo.keen-pbr.fyi/repository/stable/">' \
146+
' <title>keen-pbr repository</title>' \
147+
'</head>' \
148+
'<body>' \
149+
' <p><a href="https://repo.keen-pbr.fyi/repository/stable/">Open the stable keen-pbr repository</a></p>' \
150+
'</body>' \
151+
'</html>' \
152+
> "$GITHUB_WORKSPACE/staged-repository/index.html"
153+
printf '%s\n' \
154+
'RedirectMatch 302 ^/$ https://repo.keen-pbr.fyi/repository/stable/' \
155+
> "$GITHUB_WORKSPACE/staged-repository/.htaccess"
156+
138157
echo "branch=$branch" >> "$GITHUB_OUTPUT"
139158
echo "release-prefix=$release_prefix" >> "$GITHUB_OUTPUT"
140159
echo "link-name=$link_name" >> "$GITHUB_OUTPUT"
@@ -185,12 +204,13 @@ jobs:
185204
rsync_target="$ssh_target"
186205
fi
187206
target_root="${RSYNC_TARGET_ROOT%/}"
188-
release_dir="$target_root/${RELEASE_PREFIX}_${BUILD_NUMBER}.release"
207+
repository_root="$target_root/repository"
208+
release_dir="$repository_root/${RELEASE_PREFIX}_${BUILD_NUMBER}.release"
189209
source_dir="$GITHUB_WORKSPACE/staged-repository/$BRANCH/"
190210
static_source="$GITHUB_WORKSPACE/staged-repository"
191211
192212
ssh "${ssh_options[@]}" "$ssh_target" \
193-
"mkdir -p -- '$release_dir' '$target_root/assets' '$target_root/keys'"
213+
"mkdir -p -- '$release_dir' '$target_root/assets' '$target_root/keys' '$repository_root'"
194214
# The generated repository page references these shared paths from the
195215
# target root, so publish them before exposing this build.
196216
rsync -a --delete --delay-updates \
@@ -199,11 +219,17 @@ jobs:
199219
rsync -a --delete --delay-updates \
200220
-e "ssh -i $HOME/.ssh/id_rsync -p $RSYNC_PORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new" \
201221
"$static_source/keys/" "$rsync_target:$target_root/keys/"
222+
rsync -a --delay-updates \
223+
-e "ssh -i $HOME/.ssh/id_rsync -p $RSYNC_PORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new" \
224+
"$static_source/index.html" "$rsync_target:$target_root/index.html"
225+
rsync -a --delay-updates \
226+
-e "ssh -i $HOME/.ssh/id_rsync -p $RSYNC_PORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new" \
227+
"$static_source/.htaccess" "$rsync_target:$target_root/.htaccess"
202228
rsync -a --delete --delay-updates \
203229
-e "ssh -i $HOME/.ssh/id_rsync -p $RSYNC_PORT -o BatchMode=yes -o StrictHostKeyChecking=accept-new" \
204230
"$source_dir" "$rsync_target:$release_dir/"
205231
206232
# This runs only after every rsync exits successfully. Renaming the
207233
# prepared temporary symlink atomically replaces the live link.
208234
ssh "${ssh_options[@]}" "$ssh_target" \
209-
"rm -f -- '$target_root/.${LINK_NAME}.new' && ln -s -- '$release_dir' '$target_root/.${LINK_NAME}.new' && mv -Tf -- '$target_root/.${LINK_NAME}.new' '$target_root/$LINK_NAME'"
235+
"rm -f -- '$repository_root/.${LINK_NAME}.new' && ln -s -- '$release_dir' '$repository_root/.${LINK_NAME}.new' && mv -Tf -- '$repository_root/.${LINK_NAME}.new' '$repository_root/$LINK_NAME'"

build_scripts/generate_repository_page.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,21 @@ def main() -> None:
235235
keys_manifest_source = Path(args.keys_manifest_source).resolve()
236236
keys_source_dir = Path(args.keys_source_dir).resolve()
237237
public_base_url = args.public_base_url.rstrip("/")
238-
instructions_url = f"{public_base_url}/{args.target_root}/"
238+
repository_base_url = f"{public_base_url}/repository"
239+
instructions_url = f"{repository_base_url}/{args.target_root}/"
239240

240241
replace_tree(shared_assets_source, repo_dir / "assets")
241242
copy_shared_keys(keys_manifest_source, keys_source_dir, repo_dir / "keys", public_base_url)
242243

243244
payload = {
244-
"baseUrl": f"{public_base_url}/{args.target_root}",
245+
"baseUrl": f"{repository_base_url}/{args.target_root}",
245246
"targetRoot": args.target_root,
246247
"source": build_source_payload(
247248
args.source_ref_type,
248249
args.source_ref_name,
249250
args.source_pr_number or None,
250251
),
251-
"catalog": collect_catalog(root_dir, f"{public_base_url}/{args.target_root}"),
252+
"catalog": collect_catalog(root_dir, f"{repository_base_url}/{args.target_root}"),
252253
}
253254

254255
write_index_html(root_dir, payload)

docs/repository-layout.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ build but are not deployed.
1515
## Directory structure
1616

1717
```text
18-
<target-root>/<branch>_<build-number>.release/keenetic/<keenetic_version>/<arch>
19-
<target-root>/<branch>_<build-number>.release/openwrt/<openwrt_version>/<arch>
20-
<target-root>/<branch>_<build-number>.release/debian/<debian_version>/<arch>
18+
<target-root>/assets/
19+
<target-root>/keys/
20+
<target-root>/index.html -> redirects to /repository/stable/
21+
<target-root>/.htaccess -> redirects / to /repository/stable/
22+
23+
<target-root>/repository/<branch>_<build-number>.release/keenetic/<keenetic_version>/<arch>
24+
<target-root>/repository/<branch>_<build-number>.release/openwrt/<openwrt_version>/<arch>
25+
<target-root>/repository/<branch>_<build-number>.release/debian/<debian_version>/<arch>
2126
22-
<target-root>/<branch> -> <branch>_<build-number>.release
27+
<target-root>/repository/<branch> -> <branch>_<build-number>.release
2328
24-
<target-root>/stable_<tag>_<build-number>.release/...
25-
<target-root>/stable -> stable_<tag>_<build-number>.release
29+
<target-root>/repository/stable_<tag>_<build-number>.release/...
30+
<target-root>/repository/stable -> stable_<tag>_<build-number>.release
2631
```
2732

2833
Package format folders (`opkg`, `ipk`, `apk`, `deb`) are intentionally omitted.
@@ -65,13 +70,13 @@ key material.
6570

6671
For the sample configuration, a build of branch `feature/new-ui` at commit UTC
6772
timestamp `1786718400` is uploaded to
68-
`/srv/www/keen-pbr/feature-new-ui_1786718400.release/`, then the symlink
69-
`/srv/www/keen-pbr/feature-new-ui` is atomically repointed to it. A tag
70-
`v3.2.0` is published as `stable_v3.2.0_1786718400.release` and updates the
71-
`stable` symlink to that release directory.
73+
`/srv/www/keen-pbr/repository/feature-new-ui_1786718400.release/`, then the symlink
74+
`/srv/www/keen-pbr/repository/feature-new-ui` is atomically repointed to it. A tag
75+
`v3.2.0` is published as `repository/stable_v3.2.0_1786718400.release` and
76+
updates the `repository/stable` symlink to that release directory.
7277

7378
The SSH account needs permission to create directories, write files, and replace
74-
symlinks below `<RSYNC_TARGET_ROOT>`.
79+
symlinks below `<RSYNC_TARGET_ROOT>/repository`.
7580

7681
## Generated repository metadata
7782

0 commit comments

Comments
 (0)