cache-apt-pkgs-action/.github/workflows/build-distribute.yml

120 lines
4.1 KiB
YAML

name: Build and Release Distribute Artifacts
on:
push:
tags:
- "v2.*.*"
branches:
- dev-v2
workflow_call:
workflow_dispatch:
permissions:
contents: write
id-token: write
env:
VERSION_PREFIX: "commit"
working_directory: ${{ github.workspace }}
jobs:
build-and-release:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
arch: X64
- goos: linux
goarch: arm64
arch: ARM64
- goos: linux
goarch: arm
goarch_variant: "6"
arch: ARM
- goos: linux
goarch: "386"
arch: X86
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version: 1.24
- name: Generate version from commit SHA
id: version
run: ./scripts/distribute.sh generate-version
- name: Create distribute directory
run: ./scripts/distribute.sh create-distribute-directory "${{ matrix.arch }}"
- name: Clone apt-fast repository
run: ./scripts/distribute.sh clone-apt-fast
- name: Build binary for ${{ matrix.goos }}/${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarch_variant }}
CGO_ENABLED: 0
run: |
./scripts/distribute.sh build-binary \
"${{ matrix.goos }}" \
"${{ matrix.goarch }}" \
"${{ matrix.goarch_variant }}" \
"${{ matrix.arch }}"
- name: Generate checksums
run: ./scripts/distribute.sh generate-checksums "${{ matrix.arch }}"
- name: Verify build
run: |
./scripts/distribute.sh verify-build "${{ matrix.arch }}"
- name: Upload artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: cache-apt-pkgs-${{ matrix.arch }}-${{ steps.version.outputs.commit_sha }}
path: distribute/${{ matrix.arch }}/*
retention-days: 30
create-release:
needs: build-and-release
runs-on: ubuntu-latest
if: success() && github.event_name == 'workflow_dispatch'
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Generate version from commit SHA
id: version
run: |
COMMIT_SHA="${GITHUB_SHA:0:8}"
VERSION="${{ env.VERSION_PREFIX }}-${COMMIT_SHA}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: distribute-artifacts
- name: Reorganize artifacts
run: |
./scripts/distribute.sh reorganize-artifacts
- name: Consolidate release artifacts
run: |
./scripts/distribute.sh consolidate-release
- name: Create or update release
uses: softprops/action-gh-release@2bb465e97f322d3cb2a965294d483e0d26a67aa9 # v3.0.1
with:
tag_name: ${{ steps.version.outputs.version }}
name: "${{ steps.version.outputs.version }}"
generate_release_notes: true
files: |
distribute/release/*
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clean up old pre-releases
run: |
echo "Cleaning up old commit-based releases..."
# Keep last 10 commit-based releases, delete older ones
gh release list --limit 50 --json tagName,isPrerelease | \
jq -r '.[] | select(.isPrerelease == true and (.tagName | startswith("commit-"))) | .tagName' | \
tail -n +11 | \
xargs -I {} gh release delete {} --yes --cleanup-tag || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}