Skip to content

docs: some reorganisation #70

docs: some reorganisation

docs: some reorganisation #70

Workflow file for this run

name: Build and release workflow
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
version-bump:
name: Update version numbers
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
outputs:
version: ${{ steps.setver.outputs.version }}
new_sha: ${{ steps.newsha.outputs.new_sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Parse version from tag
id: setver
shell: bash
run: |
set -e
ref="${GITHUB_REF#refs/tags/}"
version="${ref#v}"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Using version: $version"
- name: Checkout main branch
shell: bash
run: |
git checkout main
- name: Update versions in files
shell: bash
run: |
set -e
ver='${{ steps.setver.outputs.version }}'
echo "Updating version to: $ver"
cd web-page
# Update root package.json
echo "Before updating package.json:"
cat package.json | jq '.version'
tmp=$(mktemp)
jq --arg v "$ver" '.version=$v' package.json > "$tmp" && mv "$tmp" package.json
echo "After updating package.json:"
cat package.json | jq '.version'
# Update add-on config.json
echo "Before updating xzg-multi-tool-addon/config.json:"
cat ../xzg-multi-tool-addon/config.json | jq '.version'
tmp=$(mktemp)
jq --arg v "$ver" '.version=$v' ../xzg-multi-tool-addon/config.json > "$tmp" && mv "$tmp" ../xzg-multi-tool-addon/config.json
echo "After updating xzg-multi-tool-addon/config.json:"
cat ../xzg-multi-tool-addon/config.json | jq '.version'
echo "Git status after updates:"
git status --porcelain
- name: Fetch draft release notes from Release Drafter and prepend to CHANGELOG
id: fetch_draft
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
owner_repo="${GITHUB_REPOSITORY}"
# get first draft release body (release-drafter keeps an editable draft release)
draft_body=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$owner_repo/releases" | jq -r 'map(select(.draft==true))[0].body // empty')
if [ -z "$draft_body" ]; then
echo "No draft release found; skipping changelog update"
echo "draft_found=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "draft_found=true" >> "$GITHUB_OUTPUT"
ver='${{ steps.setver.outputs.version }}'
header="## v$ver"
tmpfile=$(mktemp)
printf "%s\n\n%s\n\n" "$header" "$draft_body" > "$tmpfile"
if [ -f xzg-multi-tool-addon/CHANGELOG.md ]; then
cat xzg-multi-tool-addon/CHANGELOG.md >> "$tmpfile"
fi
mv "$tmpfile" xzg-multi-tool-addon/CHANGELOG.md
git add xzg-multi-tool-addon/CHANGELOG.md
echo "Prepended xzg-multi-tool-addon/CHANGELOG.md with draft release notes."
- name: Commit version bumps
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(release): bump version to ${{ steps.setver.outputs.version }}"
branch: main
file_pattern: "web-page/package.json xzg-multi-tool-addon/config.json xzg-multi-tool-addon/CHANGELOG.md"
- name: Get bumped commit SHA
id: newsha
run: |
# ensure we have the latest remote ref (commit just pushed by previous step)
git fetch origin main
sha=$(git rev-parse origin/main)
echo "new_sha=$sha" >> "$GITHUB_OUTPUT"
build-web-deploy:
name: Build & Deploy Web
runs-on: ubuntu-latest
needs: [version-bump]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.version-bump.outputs.new_sha }}
fetch-depth: 0
- name: Ensure full git history and export short SHA
shell: bash
run: |
git fetch --prune --unshallow || true
short_sha=$(git rev-parse --short HEAD)
echo "sha=$short_sha" >> "$GITHUB_OUTPUT"
echo "COMMIT_SHA=$short_sha" >> "$GITHUB_ENV"
id: short_sha
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
working-directory: web-page
- name: Build project
run: npm run build
working-directory: web-page
- name: Upload web-page artifacts
uses: actions/upload-artifact@v4
with:
name: web-page-artifacts
path: |
web-page/dist/**
if-no-files-found: error
- name: Create CNAME for GitHub Pages
shell: bash
run: |
mkdir -p web-page/dist
echo 'mt.xyzroe.cc' > web-page/dist/CNAME
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./web-page/dist
publish_branch: web
force_orphan: true
release:
name: Publish Release
runs-on: ubuntu-latest
needs: [build-go, version-bump]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.version-bump.outputs.new_sha }}
fetch-depth: 0
- name: Download go artifacts
uses: actions/download-artifact@v4
with:
name: go-binaries
path: dist-release
- name: Show downloaded files
run: ls -Rla dist-release || true
- name: Get draft release body (Release Drafter)
id: get_draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
owner_repo="${GITHUB_REPOSITORY}"
draft_body=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$owner_repo/releases" | jq -r 'map(select(.draft==true))[0].body // ""')
# write multiline output
echo "body<<EOF" >> "$GITHUB_OUTPUT"
printf "%s\n" "$draft_body" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release and upload assets files (use draft body)
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version-bump.outputs.version }}
name: v${{ needs.version-bump.outputs.version }}
body: ${{ steps.get_draft.outputs.body }}
files: dist-release/**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-go:
name: Build Go binaries (macos-latest)
runs-on: macos-latest
needs: [version-bump, build-web-deploy]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.version-bump.outputs.new_sha }}
fetch-depth: 0
- name: Ensure full git history and export short SHA
shell: bash
run: |
git fetch --prune --unshallow || true
short_sha=$(git rev-parse --short HEAD)
echo "sha=$short_sha" >> "$GITHUB_OUTPUT"
echo "COMMIT_SHA=$short_sha" >> "$GITHUB_ENV"
id: short_sha
- name: Download web-page artifacts
uses: actions/download-artifact@v4
with:
name: web-page-artifacts
path: tmp/web-artifacts
if-no-files-found: error
- name: Copy web assets into bridge/web
shell: bash
run: |
set -e
mkdir -p bridge/web
cp -a tmp/web-artifacts/. bridge/web/ || true
ls -la bridge/web || true
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install upx
run: |
echo "Installing upx for binary compression"
brew install upx || true
- name: Build go binaries for multiple platforms
working-directory: bridge
env:
USE_UPX: '1'
run: |
make deps
make build
- name: Upload go binaries
uses: actions/upload-artifact@v4
with:
name: go-binaries
path: |
bridge/dist/**
if-no-files-found: error
docker-go:
name: Build & Push Docker image (bridge)
runs-on: ubuntu-latest
needs: [version-bump, build-web-deploy]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.version-bump.outputs.new_sha }}
fetch-depth: 0
- name: Download web-page artifacts
uses: actions/download-artifact@v4
with:
name: web-page-artifacts
path: tmp/web-artifacts
if-no-files-found: error
- name: Copy web assets into bridge/web
shell: bash
run: |
set -e
mkdir -p bridge/web
cp -a tmp/web-artifacts/. bridge/web/ || true
ls -la bridge/web || true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for bridge
id: meta-go
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ needs.version-bump.outputs.version }}
type=raw,value=latest
- name: Compute short commit SHA
id: short_sha_go
run: |
echo "sha=$(echo ${GITHUB_SHA} | cut -c1-8)" >> "$GITHUB_OUTPUT"
- name: Build and push bridge Docker image (multi-arch)
uses: docker/build-push-action@v6
with:
context: .
file: ./bridge/Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386
tags: ${{ steps.meta-go.outputs.tags }}
labels: ${{ steps.meta-go.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.version-bump.outputs.version }}
COMMIT_SHA=${{ steps.short_sha_go.outputs.sha }}