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: on:
schedule: schedule:
# Run every day at 00:00 UTC
- cron: '0 0 * * *' - cron: '0 0 * * *'
workflow_dispatch: 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: jobs:
generate-version: generate-version:
name: Generate Nightly Version name: Generate Version
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event.inputs.skip_version != 'true'
outputs: outputs:
version: ${{ steps.version.outputs.version }} version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }} tag: ${{ steps.version.outputs.tag }}
date: ${{ steps.version.outputs.date }}
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Generate nightly version - name: Generate version
id: version id: version
run: | run: |
# Get current date
DATE=$(date +%Y%m%d) DATE=$(date +%Y%m%d)
# Get short commit hash
SHA=$(git rev-parse --short HEAD) SHA=$(git rev-parse --short HEAD)
# Generate version: v0.1.0-nightly-YYYYMMDD-sha
VERSION="v0.1.0-nightly-${DATE}-${SHA}" VERSION="v0.1.0-nightly-${DATE}-${SHA}"
TAG="nightly-${DATE}-${SHA}" TAG="nightly-${DATE}-${SHA}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $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: build:
name: Build Picoclaw name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: generate-version needs: generate-version
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v6
with: with:
go-version: '1.21' go-version-file: go.mod
cache: true
- name: Build binary - name: Build
run: | run: make build-all
go build -v -o picoclaw .
- name: Upload artifact - name: Upload artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: picoclaw-linux-amd64 name: picoclaw-binaries
path: picoclaw path: build/*
build-docker: build-docker:
name: Build Docker Image name: Build Docker
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: generate-version
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 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 - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry - name: Log in to GHCR
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY }} registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image - name: Build and push
uses: docker/build-push-action@v5 uses: docker/build-push-action@v6
with: with:
context: . context: .
file: ./docker/Dockerfile
push: true push: true
tags: | tags: |
ghcr.io/${{ github.repository }}:${{ needs.generate-version.outputs.tag }} ghcr.io/${{ steps.repo.outputs.repo }}:nightly-${{ steps.date.outputs.date }}
ghcr.io/${{ github.repository }}:nightly-${{ needs.generate-version.outputs.date }} ghcr.io/${{ steps.repo.outputs.repo }}:nightly
ghcr.io/${{ github.repository }}:nightly
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
create-release: release:
name: Create Nightly Release name: Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [generate-version, build] needs: [generate-version, build]
if: github.event.inputs.build_only != 'true'
steps: steps:
- name: Checkout code - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: picoclaw-linux-amd64 name: picoclaw-binaries
path: ./artifacts path: ./build
- name: Prepare release notes - name: Create release
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()
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
# List all nightly releases, keep only the 7 most recent gh release create ${{ needs.generate-version.outputs.tag }} \
gh release list --limit 100 | grep nightly- | tail -n +8 | awk '{print $3}' | xargs -I {} gh release delete --yes --cleanup-tag {} --title "${{ needs.generate-version.outputs.version }}" \
--notes "Nightly build for ${{ needs.generate-version.outputs.version }}" \
notify: build/*
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