-
Notifications
You must be signed in to change notification settings - Fork 102
98 lines (78 loc) · 3.03 KB
/
publish-github-pages.yml
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
name: Publish Github Pages
on:
workflow_dispatch:
push:
branches: [main]
release:
types:
- published
jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 0.13.0
- name: Download and install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh
- name: Authenticate with GitHub CLI
run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
- name: Build
working-directory: website
run: zig build
- name: List, download, unpack, and generate metadata
run: |
# Create an array to store releases with the artifact
releases_with_artifact=()
# Fetch all releases and iterate over them
releases=$(gh release list --limit 100 --repo ${{ github.repository }} | awk '{print $1}')
for release in $releases; do
echo "Processing release: $release"
# Create the target directory if it doesn't exist
mkdir -p website/zig-out/www/downloads/microzig
# Download the artifact 'boxzer-out.tar.gz' if it exists
gh release download "$release" --pattern "boxzer-out.tar.gz" --repo ${{ github.repository }} --dir . || echo "Failed to download boxzer-out.tar.gz"
# Check if the tarball was downloaded and unpack it
if [ -f "boxzer-out.tar.gz" ]; then
echo "Unpacking boxzer-out.tar.gz for release: $release"
tar -xzvf boxzer-out.tar.gz -C website/zig-out/www/downloads/microzig
rm boxzer-out.tar.gz
# Add the release to the metadata array
releases_with_artifact+=("\"$release\"")
else
echo "Artifact 'boxzer-out.tar.gz' not found for release: $release"
fi
done
# Generate metadata.json file
echo "Generating metadata.json"
echo "{ \"releases\": [$(IFS=,; echo "${releases_with_artifact[*]}")] }" > website/zig-out/www/downloads/microzig/metadata.json
echo "List of files uploaded to github pages:"
tree website/zig-out/www
- name: Upload Artifact
uses: actions/upload-pages-artifact@v3
id: deployment
with:
path: website/zig-out/www
# Deploy job
deploy:
# Add a dependency to the build job
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action