Feat/nightly align with gorelease and release note (#1285)

* feat/nightly gorelease and changelog

* update to skip docker hub when nightly

* update goreleaser check

* Update with correct lower case for ghcr

* Update with correct syntax

* remove lower case

* Update to prevent gorelease overwrite nightly changelog

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update according to review suggestions

* Update .github/workflows/nightly.yml

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove redundant gh download

* Update to delete nightly tag before creating

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Hua Audio 2026-03-09 17:53:25 +01:00 committed by GitHub
parent 110fc71349
commit c45c5073c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 124 additions and 87 deletions

View file

@ -9,67 +9,78 @@ permissions:
contents: read contents: read
jobs: jobs:
generate-version: create-tag:
name: Generate Version name: Create Git Tag
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: write
outputs: outputs:
version: ${{ steps.version.outputs.version }} version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }} tag: ${{ steps.version.outputs.tag }}
changelog: ${{ steps.version.outputs.changelog }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Generate version - name: Generate and push tag
id: version id: version
run: | run: |
DATE=$(date -u +%Y%m%d) DATE=$(date -u +%Y%m%d)
SHA=$(git rev-parse --short=8 HEAD) SHA=$(git rev-parse --short=8 HEAD)
BASE_VERSION=$(git describe --tags --match "v*" --exclude "*nightly*" --abbrev=0 2>/dev/null || true) BASE_VERSION=$(git describe --tags --match "v*" --exclude "*nightly*" --abbrev=0 2>/dev/null || true)
if [ -z "$BASE_VERSION" ] || [ "$BASE_VERSION" = "v0.0.0" ]; then if [ -z "$BASE_VERSION" ] || [ "$BASE_VERSION" = "v0.0.0" ]; then
VERSION="nightly-${DATE}-${SHA}" TAG="v0.0.0-nightly.${DATE}.${SHA}"
else else
VERSION="${BASE_VERSION}-nightly-${DATE}-${SHA}" TAG="${BASE_VERSION}-nightly.${DATE}.${SHA}"
fi fi
TAG="nightly-${DATE}-${SHA}" VERSION=$TAG
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "Tag $TAG already exists, reusing existing tag"
else
git tag -a "$TAG" -m "Nightly build $VERSION"
fi
git push origin "$TAG"
COMPARE_URL="https://github.com/${{ github.repository }}/commits/${TAG}"
if [ -n "$BASE_VERSION" ] && [ "$BASE_VERSION" != "v0.0.0" ]; then
COMPARE_URL="https://github.com/${{ github.repository }}/compare/${BASE_VERSION}...${TAG}"
fi
echo "changelog=**Full Changelog**: $COMPARE_URL" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT" echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
build: release:
name: Build name: GoReleaser Release
needs: create-tag
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: generate-version permissions:
contents: write
packages: write
steps: steps:
- name: Checkout - name: Checkout tag
uses: actions/checkout@v6 uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ needs.create-tag.outputs.tag }}
- name: Setup Go - name: Setup Go from go.mod
id: setup-go
uses: actions/setup-go@v6 uses: actions/setup-go@v6
with: with:
go-version-file: go.mod go-version-file: go.mod
- name: Build - name: Setup Node.js
env: uses: actions/setup-node@v4
VERSION: ${{ needs.generate-version.outputs.version }}
run: make build-all VERSION="$VERSION"
- name: Upload artifacts
uses: actions/upload-artifact@v6
with: with:
name: picoclaw-binaries node-version: 22
path: build
build-docker: - name: Setup pnpm
name: Build Docker run: corepack enable && corepack prepare pnpm@latest --activate
runs-on: ubuntu-latest
needs: generate-version
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
@ -77,80 +88,79 @@ jobs:
- 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 GHCR - name: Login to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata - name: Run GoReleaser
id: meta uses: goreleaser/goreleaser-action@v6
uses: docker/metadata-action@v5
with: with:
images: ghcr.io/${{ github.repository }} distribution: goreleaser
tags: | version: ~> v2
type=raw,value=${{ needs.generate-version.outputs.tag }} args: release --clean
type=raw,value=${{ needs.generate-version.outputs.version }} env:
type=raw,value=nightly GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
DOCKERHUB_IMAGE_NAME: ${{ vars.DOCKERHUB_REPOSITORY }}
GOVERSION: ${{ steps.setup-go.outputs.go-version }}
NIGHTLY_BUILD: "true"
MACOS_SIGN_P12: ${{ secrets.MACOS_SIGN_P12 }}
MACOS_SIGN_PASSWORD: ${{ secrets.MACOS_SIGN_PASSWORD }}
MACOS_NOTARY_ISSUER_ID: ${{ secrets.MACOS_NOTARY_ISSUER_ID }}
MACOS_NOTARY_KEY_ID: ${{ secrets.MACOS_NOTARY_KEY_ID }}
MACOS_NOTARY_KEY: ${{ secrets.MACOS_NOTARY_KEY }}
- name: Build and push update-rolling:
uses: docker/build-push-action@v6 name: Update Rolling Nightly
with: needs: [create-tag, release]
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/riscv64
provenance: false
release:
name: Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [generate-version, build, build-docker]
permissions: permissions:
contents: write contents: write
packages: write
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
- name: Download artifacts - name: Update nightly release
uses: actions/download-artifact@v6
with:
name: picoclaw-binaries
path: ./build
- name: Create release
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.create-tag.outputs.tag }}
TITLE: ${{ needs.create-tag.outputs.version }}
run: | run: |
TAG="${{ needs.generate-version.outputs.tag }}" CHANGELOG='${{ needs.create-tag.outputs.changelog }}'
TITLE="${{ needs.generate-version.outputs.version }}" NOTES=$(cat <<EOF
NOTES=$'Nightly build for **${{ needs.generate-version.outputs.version }}**\n\nThis is an automated build and may be unstable. Use with caution.' Nightly build for **${TITLE}**
This is an automated build and may be unstable. Use with caution.
${CHANGELOG}
EOF
)
# Download assets from the newly created release if it exists,
# otherwise fall back to using locally built dist/ artifacts.
mkdir -p build
if gh release view "$TAG" >/dev/null 2>&1; then if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists, updating metadata and assets..." echo "Downloading assets from GitHub release for $TAG..."
gh release edit "$TAG" \ gh release download "$TAG" --dir build
--title "$TITLE" \
--notes "$NOTES" \
--prerelease
gh release upload "$TAG" build/* --clobber
else else
echo "Creating new release $TAG..." echo "GitHub release for $TAG not found; falling back to local dist/ artifacts..."
gh release create "$TAG" \ if [ -d "dist" ]; then
--title "$TITLE" \ cp -R dist/* build/
--notes "$NOTES" \ else
--target "${{ github.sha }}" \ echo "Error: no GitHub release for $TAG and no local dist/ directory found." >&2
--prerelease \ exit 1
build/* fi
fi fi
echo "Updating rolling 'nightly' release..." # Delete existing nightly release and tag to avoid conflicts
gh release delete nightly --cleanup-tag -y >/dev/null 2>&1 || true echo "Deleting existing nightly release and tag..."
sleep 2 gh release delete nightly --cleanup-tag -y || true
git push origin :refs/tags/nightly || true
gh release create nightly \ gh release create nightly \
--title "Nightly Build" \ --title "Nightly Build" \
--notes "$NOTES" \ --notes "$NOTES" \
@ -159,9 +169,36 @@ jobs:
build/* build/*
echo "Cleaning up old nightly releases (keeping only the most recent)..." echo "Cleaning up old nightly releases (keeping only the most recent)..."
gh release list --limit 100 --json tagName -q '.[].tagName | select(startswith("nightly-"))' | tail -n +2 | while read -r old_tag; do gh release list --limit 100 --json tagName -q '.[].tagName | select(contains("-nightly."))' | tail -n +2 | while read -r old_tag; do
if [ -n "$old_tag" ] && [ "$old_tag" != "$TAG" ]; then if [ -n "$old_tag" ] && [ "$old_tag" != "$TAG" ]; then
echo "Deleting old nightly release: $old_tag" echo "Deleting old nightly release: $old_tag"
gh release delete "$old_tag" --cleanup-tag -y || true gh release delete "$old_tag" --cleanup-tag -y || true
fi fi
done done
echo "Cleaning up old 'vX.X.X-nightly...' Docker images on GHCR..."
OWNER="${{ github.repository_owner }}"
PACKAGE_NAME="${{ github.event.repository.name }}"
# Check if owner is an organization or user
ORG_TEST=$(gh api -H "Accept: application/vnd.github+json" /orgs/$OWNER 2>/dev/null || true)
if echo "$ORG_TEST" | grep -q '"login"'; then
ACCOUNT_TYPE="orgs"
else
ACCOUNT_TYPE="users"
fi
PACKAGE_URL="/${ACCOUNT_TYPE}/${OWNER}/packages/container/${PACKAGE_NAME}/versions"
OLD_NIGHTLY_VERSIONS=$(gh api --paginate -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"$PACKAGE_URL" \
--jq ". | map(select(any(.metadata.container.tags[]; contains(\"-nightly.\") and (. != \"nightly\") and (. != \"$TAG\")))) | .[].id" 2>/dev/null || true)
for version_id in $OLD_NIGHTLY_VERSIONS; do
if [ -n "$version_id" ]; then
echo "Deleting Docker image version ID: $version_id"
gh api -X DELETE -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/${ACCOUNT_TYPE}/${OWNER}/packages/container/${PACKAGE_NAME}/versions/$version_id" || true
fi
done

View file

@ -116,10 +116,10 @@ dockers_v2:
- picoclaw - picoclaw
images: images:
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw" - "ghcr.io/{{ .Env.GITHUB_REPOSITORY_OWNER }}/picoclaw"
- "docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}" - '{{ if not (isEnvSet "NIGHTLY_BUILD") }}docker.io/{{ .Env.DOCKERHUB_IMAGE_NAME }}{{ end }}'
tags: tags:
- "{{ .Tag }}" - "{{ .Tag }}"
- "latest" - '{{ if isEnvSet "NIGHTLY_BUILD" }}nightly{{ else }}latest{{ end }}'
platforms: platforms:
- linux/amd64 - linux/amd64
- linux/arm64 - linux/arm64
@ -159,7 +159,7 @@ archives:
nfpms: nfpms:
- id: picoclaw - id: picoclaw
builds: ids:
- picoclaw - picoclaw
- picoclaw-launcher - picoclaw-launcher
- picoclaw-launcher-tui - picoclaw-launcher-tui