Skip to content

Commit 3ad8f14

Browse files
committed
CI: Update build workflow, also build on Forgejo
1 parent 1c5cf1a commit 3ad8f14

4 files changed

Lines changed: 118 additions & 40 deletions

File tree

.forgejo/workflows/build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build my website
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
build:
9+
name: Build my website
10+
runs-on: codeberg-tiny-lazy
11+
env:
12+
UV_CACHE_DIR: .uv-cache
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
lfs: true
19+
submodules: recursive
20+
21+
- name: Build the website
22+
run: python build_website.py
23+
env:
24+
GOOGLE_PROOF: ${{ secrets.GOOGLE_PROOF }}
25+
KEYBASE_PROOF: ${{ secrets.KEYBASE_PROOF }}
26+
27+
- name: Deploy to repository
28+
run: |
29+
mkdir -p ~/.ssh
30+
cat << EOF > ~/.ssh/forgejo
31+
${{ secrets.SSH_PRIVATE_KEY }}
32+
EOF
33+
chmod 400 ~/.ssh/forgejo
34+
eval `ssh-agent -s`
35+
ssh-add ~/.ssh/forgejo
36+
git config --global user.name "forgejo-actions-bot"
37+
git config --global user.email "actions@forgejo.local"
38+
cd public
39+
git init --initial-branch main
40+
echo "git@${{ secrets.FORGEJO_URL }}.git" | sed "0,/\//{s/\//:/}" | xargs git remote add origin
41+
git add .
42+
git commit -m "Deploy site"
43+
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git push --force origin main

.github/workflows/build.yml

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,11 @@ jobs:
1818
lfs: true
1919
submodules: recursive
2020

21-
- name: Install Rust
22-
run: rustup update stable && rustup default stable
23-
24-
- name: Cache Cargo files
25-
uses: actions/cache@v4
26-
with:
27-
path: |
28-
~/.cargo/bin/
29-
~/.cargo/registry/index/
30-
~/.cargo/registry/cache/
31-
~/.cargo/git/db/
32-
key: cargo-stable-${{ runner.os }}-${{ github.sha }}
33-
restore-keys: cargo-stable-${{ runner.os }}-
34-
35-
- name: Install Zola
36-
run: cargo install --git https://github.com/getzola/zola.git --locked --force
37-
38-
- name: Build the documentation
39-
run: zola build
40-
41-
- name: Add Keybase proof
42-
run: echo "${{ secrets.KEYBASE_PROOF }}" > public/keybase.txt
43-
44-
- name: Add Google proof
45-
# Use the GOOGLE_PROOF secret to add a Google proof file to the public directory
46-
run: 'echo "google-site-verification: google${{ secrets.GOOGLE_PROOF }}.html" > "public/google${{ secrets.GOOGLE_PROOF }}.html"'
21+
- name: Build the website
22+
run: python build_website.py
23+
env:
24+
GOOGLE_PROOF: ${{ secrets.GOOGLE_PROOF }}
25+
KEYBASE_PROOF: ${{ secrets.KEYBASE_PROOF }}
4726

4827
- name: Upload GitHub Pages artifact
4928
uses: actions/upload-pages-artifact@v3

.gitlab-ci.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,8 @@ variables:
44
GIT_SUBMODULE_STRATEGY: recursive
55

66
pages:
7-
cache:
8-
- key:
9-
files:
10-
- config.toml
11-
paths:
12-
- ~/.cargo/bin/
13-
- ~/.cargo/registry/index/
14-
- ~/.cargo/registry/cache/
15-
- ~/.cargo/git/db/
167
script:
17-
- rustup update stable && rustup default stable
18-
- cargo install --git https://github.com/getzola/zola.git --locked --force
19-
- zola build
20-
- echo "$KEYBASE_PROOF" > public/keybase.txt
21-
- 'echo "google-site-verification: google$GOOGLE_PROOF.html" > "public/google$GOOGLE_PROOF.html"'
8+
- python build_website.html
229
artifacts:
2310
paths:
2411
- public

build_website.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import io
2+
import json
3+
import os
4+
import platform
5+
import shutil
6+
import subprocess as sp
7+
import sys
8+
import tarfile
9+
import tempfile
10+
from pathlib import Path
11+
from urllib.request import urlopen
12+
13+
# Download the latest release of zola
14+
url = "https://api.github.com/repos/getzola/zola/releases/latest"
15+
data = json.load(urlopen(url))
16+
tag_name = data["tag_name"]
17+
print(f"Latest zola version is {tag_name}")
18+
19+
# Download the zola binary
20+
url = (
21+
f"https://github.com/getzola/zola/releases/download/{tag_name}/zola-{tag_name}-{platform.processor()}-"
22+
+ (
23+
"pc-windows-msvc" if sys.platform == "win32"
24+
else "apple-darwin" if sys.platform == "darwin"
25+
else "unknown-linux-gnu"
26+
)
27+
+ ".tar.gz"
28+
)
29+
30+
output_file_name = "zola.exe" if sys.platform == "win32" else "zola"
31+
32+
with tempfile.TemporaryDirectory() as dir:
33+
output_file = Path(dir) / output_file_name
34+
print(f"Downloading {url} to {output_file}...")
35+
36+
# Decompress the tarball and extract the zola binary
37+
with open(output_file, "wb") as f:
38+
with urlopen(url) as response:
39+
buffer = io.BytesIO()
40+
shutil.copyfileobj(response, buffer)
41+
buffer.seek(0)
42+
with tarfile.open(fileobj=buffer, mode="r:gz") as tar:
43+
shutil.copyfileobj(tar.extractfile(output_file_name), f)
44+
45+
# Make the zola binary executable
46+
os.chmod(output_file, 0o755)
47+
print(f"Changed file attributes of {output_file_name}")
48+
49+
# Build the website
50+
print("Running build command...")
51+
sp.run([output_file, "build"], check=True)
52+
53+
# Add the Keybase proof
54+
KEYBASE_PROOF = os.getenv("KEYBASE_PROOF", "")
55+
if KEYBASE_PROOF:
56+
with open("public/keybase.txt", "w") as f:
57+
f.write(KEYBASE_PROOF)
58+
print("Keybase proof added")
59+
else:
60+
print("Keybase proof not found")
61+
62+
# Add the Google proof
63+
GOOGLE_PROOF = os.getenv("GOOGLE_PROOF", "")
64+
if GOOGLE_PROOF:
65+
with open(f"public/google{GOOGLE_PROOF}.html", "w") as f:
66+
f.write(f"google-site-verification: google{GOOGLE_PROOF}.html")
67+
print("Google proof added")
68+
else:
69+
print("Google proof not found")

0 commit comments

Comments
 (0)