Refactor nightly build workflow for clarity and efficiency

Refactor nightly build workflow to improve clarity and efficiency. Update job names, streamline version generation, and enhance Docker build process.
This commit is contained in:
Hua Audio 2026-03-08 00:53:46 +01:00 committed by GitHub
parent 01f07ab323
commit f3cc7c9401
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,230 +2,110 @@ name: Nightly Build
on:
schedule:
# Run every day at 00:00 UTC
- cron: '0 0 * * *'
workflow_dispatch:
# Allow manual triggering
inputs:
skip_version:
description: 'Skip version generation (use current)'
required: false
default: 'false'
type: boolean
build_only:
description: 'Build only, skip release'
required: false
default: 'false'
type: boolean
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
generate-version:
name: Generate Nightly Version
name: Generate Version
runs-on: ubuntu-latest
if: github.event.inputs.skip_version != 'true'
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
date: ${{ steps.version.outputs.date }}
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate nightly version
- name: Generate version
id: version
run: |
# Get current date
DATE=$(date +%Y%m%d)
# Get short commit hash
SHA=$(git rev-parse --short HEAD)
# Generate version: v0.1.0-nightly-YYYYMMDD-sha
VERSION="v0.1.0-nightly-${DATE}-${SHA}"
TAG="nightly-${DATE}-${SHA}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "date=${DATE}" >> $GITHUB_OUTPUT
echo "Generated version: ${VERSION}"
echo "Generated tag: ${TAG}"
echo "Generated date: ${DATE}"
build:
name: Build Picoclaw
name: Build
runs-on: ubuntu-latest
needs: generate-version
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.21'
cache: true
go-version-file: go.mod
- name: Build binary
run: |
go build -v -o picoclaw .
- name: Build
run: make build-all
- name: Upload artifact
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: picoclaw-linux-amd64
path: picoclaw
name: picoclaw-binaries
path: build/*
build-docker:
name: Build Docker Image
name: Build Docker
runs-on: ubuntu-latest
needs: generate-version
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4
- name: Generate lowercase repo
id: repo
run: echo "repo=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
- name: Generate date tag
id: date
run: echo "date=$(date +%Y%m%d)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ needs.generate-version.outputs.tag }}
ghcr.io/${{ github.repository }}:nightly-${{ needs.generate-version.outputs.date }}
ghcr.io/${{ github.repository }}:nightly
ghcr.io/${{ steps.repo.outputs.repo }}:nightly-${{ steps.date.outputs.date }}
ghcr.io/${{ steps.repo.outputs.repo }}:nightly
cache-from: type=gha
cache-to: type=gha,mode=max
create-release:
name: Create Nightly Release
release:
name: Release
runs-on: ubuntu-latest
needs: [generate-version, build]
if: github.event.inputs.build_only != 'true'
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: picoclaw-linux-amd64
path: ./artifacts
name: picoclaw-binaries
path: ./build
- name: Prepare release notes
run: |
cat > release_notes.md << 'EOF'
# Picoclaw Nightly Release
📅 **Date**: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
🏷️ **Version**: ${{ needs.generate-version.outputs.version }}
🌿 **Branch**: ${{ github.ref_name }}
🔗 **Commit**: ${{ github.sha }}
---
## 📦 Download
### Linux AMD64 Binary
- `picoclaw-linux-amd64` - Pre-built binary for Linux x86_64
### Docker Image
\`\`\`bash
docker pull ghcr.io/${{ github.repository }}:nightly-$(date +%Y%m%d)
# or latest nightly
docker pull ghcr.io/${{ github.repository }}:nightly
\`\`\`
---
## 🔧 Installation
### Using binary
\`\`\`bash
chmod +x picoclaw
sudo mv picoclaw /usr/local/bin/
\`\`\`
### Using Docker
\`\`\`bash
docker run -d --name picoclaw \\
-v /path/to/config:/config \\
ghcr.io/${{ github.repository }}:nightly
\`\`\`
---
## ⚠️ Disclaimer
This is a **nightly build** and may contain:
- Unfinished features
- Bugs and instability
- Breaking changes
For production use, please use a stable release instead.
---
🦞 **Built with ❤️ by Picoclaw**
EOF
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.generate-version.outputs.version }}
TAG: ${{ needs.generate-version.outputs.tag }}
run: |
gh release create "$TAG" \
--title "$VERSION" \
--notes-file release_notes.md \
./artifacts/picoclaw-linux-amd64
- name: Update nightly tag reference
if: success()
run: |
# Update 'nightly' tag to point to latest nightly
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -f nightly ${{ github.sha }}
git push origin nightly --force
- name: Clean up old nightly releases (keep last 7)
if: success()
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# List all nightly releases, keep only the 7 most recent
gh release list --limit 100 | grep nightly- | tail -n +8 | awk '{print $3}' | xargs -I {} gh release delete --yes --cleanup-tag {}
notify:
name: Notify Results
runs-on: ubuntu-latest
needs: [build-docker, create-release]
if: always()
steps:
- name: Check build status
run: |
if [ "${{ needs.create-release.result }}" == "success" ]; then
echo "✅ Nightly build completed successfully!"
echo "Version: ${{ needs.generate-version.outputs.version }}"
else
echo "❌ Nightly build failed"
echo "Check the workflow logs for details"
fi
gh release create ${{ needs.generate-version.outputs.tag }} \
--title "${{ needs.generate-version.outputs.version }}" \
--notes "Nightly build for ${{ needs.generate-version.outputs.version }}" \
build/*