Skip to content

fix(ci): create release once before build jobs to avoid duplicate drafts #8

fix(ci): create release once before build jobs to avoid duplicate drafts

fix(ci): create release once before build jobs to avoid duplicate drafts #8

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: 'Version tag (e.g. v0.1.0)'
required: true
type: string
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Resolve tag
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "${{ steps.tag.outputs.tag }}" --generate-notes --draft
build:
needs: create-release
strategy:
matrix:
include:
- { target: x86_64-unknown-linux-gnu, runner: ubuntu-latest, os: linux, arch: x64, ext: "", archive: tar.gz }
- { target: aarch64-unknown-linux-gnu, runner: ubuntu-24.04-arm, os: linux, arch: arm64, ext: "", archive: tar.gz }
- { target: x86_64-apple-darwin, runner: macos-latest, os: darwin, arch: x64, ext: "", archive: tar.gz }
- { target: aarch64-apple-darwin, runner: macos-latest, os: darwin, arch: arm64, ext: "", archive: tar.gz }
runs-on: ${{ matrix.runner }}
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Resolve tag
id: tag
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
VERSION="${{ steps.tag.outputs.version }}"
NAME="ghpool-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}"
mkdir -p dist
cp target/${{ matrix.target }}/release/ghpool${{ matrix.ext }} dist/
cp config.example.toml dist/
cd dist
tar czf ../${NAME}.tar.gz *
- name: Upload to release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
TAG="${{ steps.tag.outputs.tag }}"
VERSION="${{ steps.tag.outputs.version }}"
NAME="ghpool-${VERSION}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz"
gh release upload "$TAG" "$NAME" --clobber
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ghpool-${{ matrix.os }}-${{ matrix.arch }}
path: ghpool-*.tar.gz
retention-days: 7
docker:
strategy:
matrix:
include:
- { platform: linux/amd64, runner: ubuntu-latest }
- { platform: linux/arm64, runner: ubuntu-24.04-arm }
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v6
- name: Resolve tag
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
echo "arch=$(echo ${{ matrix.platform }} | tr '/' '-')" >> "$GITHUB_OUTPUT"
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: ${{ matrix.platform }}
tags: ghcr.io/${{ github.repository }}:${{ steps.tag.outputs.version }}-${{ steps.tag.outputs.arch }}
docker-manifest:
needs: docker
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Resolve tag
id: tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
run: |
VERSION="${{ steps.tag.outputs.version }}"
IMAGE="ghcr.io/${{ github.repository }}"
docker buildx imagetools create -t ${IMAGE}:${VERSION} \
${IMAGE}:${VERSION}-linux-amd64 \
${IMAGE}:${VERSION}-linux-arm64
docker buildx imagetools create -t ${IMAGE}:latest \
${IMAGE}:${VERSION}-linux-amd64 \
${IMAGE}:${VERSION}-linux-arm64