Skip to content

SLSA Go releaser #32

SLSA Go releaser

SLSA Go releaser #32

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow lets you compile your Go project using a SLSA3 compliant builder.
# This workflow will generate a so-called "provenance" file describing the steps
# that were performed to generate the final binary.
# The project is an initiative of the OpenSSF (openssf.org) and is developed at
# https://github.com/slsa-framework/slsa-github-generator.
# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier.
# For more information about SLSA and how it improves the supply-chain, visit slsa.dev.
name: SLSA Go releaser
on:
workflow_dispatch:
release:
types: [created]
push:
tags:
- "v*"
permissions: read-all
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- run: go test -v ./...
# Generate ldflags dynamically.
# Optional: only needed for ldflags.
args:
needs: [test]
runs-on: ubuntu-latest
outputs:
commit-date: ${{ steps.ldflags.outputs.commit-date }}
commit: ${{ steps.ldflags.outputs.commit }}
version: ${{ steps.ldflags.outputs.version }}
tree-state: ${{ steps.ldflags.outputs.tree-state }}
steps:
- id: checkout
uses: actions/checkout@v4
- id: ldflags
run: |
echo "commit-date=$(git log -1 --date='format:%Y-%m-%d/%H.%M.%S' --pretty=%cd)" >> "$GITHUB_OUTPUT"
echo "commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
echo "version=$(git describe --tags --always --dirty | cut -c2-)" >> "$GITHUB_OUTPUT"
echo "tree-state=$(if git diff --quiet; then echo "clean"; else echo "dirty"; fi)" >> "$GITHUB_OUTPUT"
# ===================================================================================================================================
# Prerequisite: Create a .slsa-goreleaser.yml in the root directory of your project.
# See format in https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/go/README.md#configuration-file
#====================================================================================================================================
build:
needs: [args]
permissions:
id-token: write # To sign.
contents: write # To upload release assets.
actions: read # To read workflow path.
strategy:
fail-fast: false
matrix:
os: [linux, windows, darwin]
arch: [amd64, arm64]
uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v2.0.0
with:
go-version-file: go.mod
config-file: .slsa-goreleaser/${{ matrix.os }}-${{ matrix.arch }}.yml
evaluated-envs: "MODULE_PATH:github.com/${{ github.repository }}, COMMIT_DATE:${{needs.args.outputs.commit-date}}, COMMIT:${{needs.args.outputs.commit}}, VERSION:${{needs.args.outputs.version}}, TREE_STATE:${{needs.args.outputs.tree-state}}"
# =======================================================================================================
# Optional: For more options, see https://github.com/slsa-framework/slsa-github-generator#golang-projects
# =======================================================================================================
attestation:
needs: [build]
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
attestations: write
strategy:
fail-fast: false
matrix:
artifact:
- linux-amd64
- linux-arm64
- darwin-amd64
- darwin-arm64
- windows-amd64.exe
- windows-arm64.exe
env:
a: "b"
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: yutu-${{ matrix.artifact }}
- name: Attest
uses: actions/attest-build-provenance@v1
with:
subject-path: '${{ github.workspace }}/yutu-${{ matrix.artifact }}'
winget:
needs: [build]
runs-on: windows-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: eat-pray-ai.yutu
installers-regex: '\.exe$' # Only .exe files
token: ${{ secrets.RELEASE_PAT }}
homebrew:
needs: [build]
runs-on: macos-latest
if: false
steps:
- uses: dawidd6/action-homebrew-bump-formula@v3
with:
token: ${{ secrets.RELEASE_PAT }}
tag: ${{ github.event.release.tag_name }}
org: eat-pray-ai
formula: yutu
github-package:
needs: [build]
runs-on: ubuntu-latest
# if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: eat-pray-ai/yutu/.github/actions/github-packages@main
with:
version: ${{ github.event.release.tag_name }}