-
Notifications
You must be signed in to change notification settings - Fork 4
145 lines (128 loc) · 4.31 KB
/
deploy-docs.yml
File metadata and controls
145 lines (128 loc) · 4.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
name: Deploy Docs
on:
push:
branches:
- main
paths:
- docs/**
- .github/workflows/deploy-docs.yml
release:
types:
- published
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
deploy:
name: Publish GitHub Pages
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Build Pages site
shell: bash
env:
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
rm -rf _site
mkdir -p _site
cp -R docs/. _site/
python <<'PY'
import json
import os
import pathlib
import urllib.error
import urllib.request
repo = os.environ["GH_REPO"]
site_dir = pathlib.Path("_site")
downloads_dir = site_dir / "downloads"
metadata_dir = site_dir / "site-data"
downloads_dir.mkdir(parents=True, exist_ok=True)
metadata_dir.mkdir(parents=True, exist_ok=True)
default_manifest = {
"tag_name": None,
"html_url": f"https://github.com/{repo}/releases",
"assets": {},
}
def request_json(url: str):
request = urllib.request.Request(
url,
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"User-Agent": "github-pages-deploy",
},
)
with urllib.request.urlopen(request) as response:
return json.load(response)
def download_asset(url: str, output_path: pathlib.Path):
request = urllib.request.Request(
url,
headers={
"Accept": "application/octet-stream",
"X-GitHub-Api-Version": "2022-11-28",
"User-Agent": "github-pages-deploy",
},
)
with urllib.request.urlopen(request) as response:
output_path.write_bytes(response.read())
try:
release = request_json(f"https://api.github.com/repos/{repo}/releases/latest")
except urllib.error.HTTPError as error:
if error.code == 404:
release = None
else:
raise
manifest = default_manifest
if release:
manifest = {
"tag_name": release.get("tag_name"),
"html_url": release.get("html_url") or default_manifest["html_url"],
"assets": {},
}
track_names = ("momentum_dev", "unleashed")
release_assets = release.get("assets") or []
for track_name in track_names:
asset = next(
(
item
for item in release_assets
if (item.get("name") or "").endswith(f"_{track_name}.fap")
),
None,
)
if not asset:
continue
relative_path = f"downloads/latest_{track_name}.fap"
output_path = site_dir / relative_path
download_asset(asset["url"], output_path)
manifest["assets"][track_name] = {
"name": asset.get("name"),
"size": asset.get("size"),
"content_type": asset.get("content_type"),
"url": f"./{relative_path}",
}
(metadata_dir / "latest-release.json").write_text(
json.dumps(manifest, indent=2),
encoding="utf-8",
)
print(json.dumps(manifest, indent=2))
PY
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: _site
- name: Deploy Pages
id: deployment
uses: actions/deploy-pages@v4