Skip to content

update boxzer and fix metadata location (#279) #21

update boxzer and fix metadata location (#279)

update boxzer and fix metadata location (#279) #21

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 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 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[*]}")] }" > zig-out/www/downloads/microzig/metadata.json
- 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