mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
242 lines
6.7 KiB
YAML
242 lines
6.7 KiB
YAML
name: Release
|
|
|
|
on:
|
|
release:
|
|
types: [created]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-release:
|
|
name: Build Release Binaries
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
target:
|
|
- name: linux-x64
|
|
os: linux
|
|
arch: x86_64
|
|
ext: ""
|
|
- name: linux-aarch64
|
|
os: linux
|
|
arch: aarch64
|
|
ext: ""
|
|
- name: macos-x64
|
|
os: macos
|
|
arch: x86_64
|
|
ext: ""
|
|
- name: macos-aarch64
|
|
os: macos
|
|
arch: aarch64
|
|
ext: ""
|
|
- name: windows-x64
|
|
os: windows
|
|
arch: x86_64
|
|
ext: ".exe"
|
|
- name: windows-aarch64
|
|
os: windows
|
|
arch: aarch64
|
|
ext: ".exe"
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Zig
|
|
uses: mlugg/setup-zig@v2
|
|
with:
|
|
version: 0.15.2
|
|
|
|
- name: Cache Zig build artifacts
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.cache/zig
|
|
zig-out
|
|
key: ${{ runner.os }}-zig-release-${{ hashFiles('**/build.zig', '**/build.zig.zon', '**/*.zig') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-zig-release-
|
|
|
|
- name: Sync Template Files
|
|
run: bash tools/synctemplate
|
|
|
|
- name: Build release binary
|
|
run: zig build release-${{ matrix.target.name }}
|
|
|
|
- name: Prepare artifact
|
|
shell: bash
|
|
run: |
|
|
mkdir -p dist
|
|
BINARY_NAME="zx-${{ matrix.target.name }}${{ matrix.target.ext }}"
|
|
if [ "${{ matrix.target.os }}" = "windows" ]; then
|
|
# For Windows, create a zip file
|
|
cd zig-out/bin/release
|
|
zip ../../../dist/zx-${{ matrix.target.name }}.zip "$BINARY_NAME"
|
|
cd ../../..
|
|
else
|
|
# For Unix-like systems, create a tar.gz file
|
|
cd zig-out/bin/release
|
|
tar -czf ../../../dist/zx-${{ matrix.target.name }}.tar.gz "$BINARY_NAME"
|
|
cd ../../..
|
|
fi
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: zx-${{ matrix.target.name }}
|
|
path: dist/zx-${{ matrix.target.name }}.*
|
|
retention-days: 30
|
|
|
|
create-release:
|
|
name: Create Release Assets
|
|
runs-on: ubuntu-latest
|
|
needs: build-release
|
|
if: github.event_name == 'release'
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: dist
|
|
|
|
- name: Flatten artifact structure
|
|
shell: bash
|
|
run: |
|
|
cd dist
|
|
# Move files from subdirectories to dist root
|
|
for dir in */; do
|
|
if [ -d "$dir" ]; then
|
|
mv "$dir"* . 2>/dev/null || true
|
|
rmdir "$dir" 2>/dev/null || true
|
|
fi
|
|
done
|
|
|
|
- name: Upload to release
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
files: dist/*
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
publish-npm:
|
|
name: Publish CLI to NPM
|
|
runs-on: ubuntu-latest
|
|
needs: build-release
|
|
if: github.event_name == 'release'
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
registry-url: https://registry.npmjs.org
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: dist
|
|
|
|
- name: Place binaries in zig-out/bin/release
|
|
shell: bash
|
|
run: |
|
|
mkdir -p zig-out/bin/release
|
|
for dir in dist/*/; do
|
|
for file in "$dir"*; do
|
|
case "$file" in
|
|
*.tar.gz) tar -xzf "$file" -C zig-out/bin/release ;;
|
|
*.zip) unzip -o "$file" -d zig-out/bin/release ;;
|
|
esac
|
|
done
|
|
done
|
|
|
|
- name: Prepare and publish @ziex packages
|
|
run: |
|
|
cd pkg/@ziex
|
|
bash prepare.sh
|
|
npm publish --workspaces --access public --provenance
|
|
|
|
sync-templates:
|
|
name: Sync & Release Templates
|
|
runs-on: ubuntu-latest
|
|
needs: create-release
|
|
if: github.event_name == 'release'
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Zig
|
|
uses: mlugg/setup-zig@v2
|
|
with:
|
|
version: 0.15.2
|
|
|
|
- name: Setup Git
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
- name: Sync and release all templates
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
OWNER=$(echo $GITHUB_REPOSITORY | cut -d'/' -f1)
|
|
TAG="${{ github.event.release.tag_name }}"
|
|
|
|
# Update _base build.zig.zon to point to the release tag
|
|
cd templates/_base
|
|
zig fetch --save "git+https://github.com/ziex-dev/ziex#${TAG}"
|
|
cd ../..
|
|
|
|
ALL_TEMPLATES=$(ls -d templates/*/ | grep -v "_base" | xargs -n 1 basename)
|
|
|
|
for TEMPLATE in $ALL_TEMPLATES; do
|
|
REPO_NAME="template-${TEMPLATE}"
|
|
TEMP_DIR=$(mktemp -d)
|
|
|
|
echo "Syncing and releasing ${TEMPLATE} to ${REPO_NAME} at ${TAG}"
|
|
|
|
# Populate template with base files
|
|
bash ./tools/template.sh populate "${TEMPLATE}"
|
|
|
|
# Copy populated template to temp dir
|
|
cp -a "templates/${TEMPLATE}/." "$TEMP_DIR/"
|
|
[ ! -f "$TEMP_DIR/LICENSE" ] && [ -f LICENSE ] && cp LICENSE "$TEMP_DIR/"
|
|
|
|
cd "$TEMP_DIR"
|
|
|
|
# Initialize and push to main
|
|
git init -b main
|
|
git add .
|
|
git commit -m "release: ${TAG} from ziex-dev/ziex"
|
|
|
|
REMOTE_URL="https://x-access-token:${GITHUB_TOKEN}@github.com/$OWNER/$REPO_NAME.git"
|
|
git remote add origin "$REMOTE_URL"
|
|
git push -u origin main --force
|
|
|
|
# Create the release tag
|
|
git tag "$TAG"
|
|
git push origin "$TAG" --force
|
|
|
|
# Create a GitHub release for the template repo
|
|
gh release create "$TAG" \
|
|
--repo "$OWNER/$REPO_NAME" \
|
|
--title "$TAG" \
|
|
--notes "Release ${TAG} — synced from [ziex-dev/ziex@${TAG}](https://github.com/ziex-dev/ziex/releases/tag/${TAG})" \
|
|
|| echo "Release $TAG may already exist for $REPO_NAME, skipping..."
|
|
|
|
cd -
|
|
rm -rf "$TEMP_DIR"
|
|
done
|
|
|