Skip to content

Release run by bleggett #237

Release run by bleggett

Release run by bleggett #237

name: Release Binaries and Images
run-name: 'Release run by ${{ github.actor }}'
on:
# Release unstable from HEAD on every merge
push:
branches:
- main
# Run manually to release unstable from HEAD
workflow_dispatch:
inputs:
protect_ref:
description: 'Commit/branch/tag'
default: ''
# Official stable versioned release
release:
types:
- published
permissions:
contents: read
jobs:
oci:
name: 'Build and publish ${{ matrix.component }} images'
if: ${{ github.repository_owner == 'edera-dev' && (github.event_name == 'release' || github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
component:
- edera-check
permissions:
contents: read
id-token: write
packages: write
steps:
- name: 'Harden runner'
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
with:
egress-policy: audit
- name: 'Checkout repository'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.0
with:
submodules: recursive
persist-credentials: false
- name: 'Setup docker buildx'
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
with:
cache-binary: false
- name: 'Login to ghcr'
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
registry: ghcr.io
username: '${{ github.actor }}'
password: '${{ github.token }}'
- name: Docker meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
id: meta
with:
images: |
ghcr.io/edera-dev/${{ matrix.component }}
tags: |
# Tag with branch on push
type=ref,event=branch
# Tag with short sha on all events
type=sha,prefix=
# Tag version and stable on tag push
type=semver,pattern={{raw}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=stable
# Tag nightly on schedule event
type=schedule,pattern=nightly
- name: 'Docker build and push ${{ matrix.component }}'
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
id: push
with:
file: images/Containerfile.edera-check
platforms: "linux/amd64,linux/arm64"
tags: '${{ steps.meta.outputs.tags }}'
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
- name: 'Install cosign'
uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 # v4.1.0
- name: 'Cosign sign all images'
shell: bash
run: |
images=""
for tag in ${TAGS}; do
pullstring="${tag}@${DIGEST}"
echo "Signing ${pullstring}"
cosign sign --yes "${pullstring}"
done
env:
TAGS: '${{ steps.meta.outputs.tags }}'
DIGEST: '${{ steps.push.outputs.digest }}'
upload-artifact:
if: ${{ github.repository_owner == 'edera-dev' && (github.event_name == 'release' || github.event.pull_request.head.repo.full_name == github.repository) }}
name: Publish Binaries to Release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform:
- { os: linux, arch: x86_64, libc: musl, static: true, on: ubuntu-latest }
- { os: linux, arch: aarch64, libc: musl, static: true, on: ubuntu-24.04-arm }
binary:
- edera-check
runs-on: '${{ matrix.platform.on }}'
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: 'Build and assemble ${{ matrix.binary }} ${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}'
run: |
set -e
# Build configuration
TARGET="${{ matrix.platform.arch }}-unknown-linux-${{ matrix.platform.libc }}"
rustup target add "$TARGET"
${{ matrix.platform.static == true && 'export RUSTFLAGS="-Ctarget-feature=+crt-static"' || '' }}
cargo build --release --target "$TARGET"
# Platform name
PLATFORM="${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}"
# Tag name
TAG="${{ github.event.release.tag_name }}"
[ -z "$TAG" ] && TAG="${{ github.event.repository.default_branch }}"
# Assemble asset
mkdir -p target/assets
BINARY="${{ matrix.binary }}"
OUTPUT_NAME="${BINARY}_${TAG}_${PLATFORM}"
cp "target/${TARGET}/release/${BINARY}" "target/assets/${OUTPUT_NAME}"
cd target/assets
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${OUTPUT_NAME}" > "${OUTPUT_NAME}.sha256"
else
shasum -a 256 "${OUTPUT_NAME}" > "${OUTPUT_NAME}.sha256"
fi
- name: 'Upload ${{ matrix.binary }} to workflow run'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ matrix.binary }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}-${{ matrix.platform.libc }}
path: target/assets/${{ matrix.binary }}_*
- name: Generate cultivator token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: generate-token
with:
app-id: "${{ secrets.EDERA_CULTIVATION_APP_ID }}"
private-key: "${{ secrets.EDERA_CULTIVATION_APP_PRIVATE_KEY }}"
- name: 'Upload release artifacts with retry'
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
with:
timeout_minutes: 5
max_attempts: 10
retry_wait_seconds: 1
command: |
cd target/assets
gh release upload "${{ github.event.release.tag_name }}" --clobber ./*
env:
GITHUB_TOKEN: "${{ steps.generate-token.outputs.token }}"