-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update GitHub Action release workflow
Use goreleaser to build binary, images and perform attestation. Note: At the moment we only build amd64 versions as arm64 is currently broken because of kafka dependency that is only build for amd64.
- Loading branch information
Showing
2 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,79 @@ | ||
name: Build and Publish Docker Images | ||
name: Release with goreleaser | ||
|
||
on: | ||
- push # Perform a build of the contents from the branch | ||
- pull_request # Perform a build after merging with the target branch | ||
- workflow_dispatch | ||
push: | ||
tags: | ||
- v* | ||
|
||
permissions: write-all # Necessary for the generate-build-provenance action with containers | ||
|
||
jobs: | ||
build_and_release: | ||
uses: Cray-HPE/hms-build-image-workflows/.github/workflows/build_and_release_image.yaml@v2 | ||
with: | ||
image-name: cray-power-control | ||
enable-pr-comment: true | ||
secrets: inherit | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install cross-compilation tools | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | ||
- name: Set up latest stable Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: stable | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Checkout out the repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-tags: 1 | ||
fetch-depth: 1 | ||
|
||
# Set environment variables required by GoReleaser | ||
- name: Set build environment variables | ||
run: | | ||
echo "GIT_STATE=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" >> $GITHUB_ENV | ||
echo "BUILD_HOST=$(hostname)" >> $GITHUB_ENV | ||
echo "GO_VERSION=$(go version | awk '{print $3}')" >> $GITHUB_ENV | ||
echo "BUILD_USER=$(whoami)" >> $GITHUB_ENV | ||
- name: Docker Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Release with goreleaser | ||
uses: goreleaser/goreleaser-action@v6 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
version: '~> v2' | ||
args: release --clean | ||
id: goreleaser | ||
|
||
- name: Process goreleaser output | ||
id: process_goreleaser_output | ||
run: | | ||
echo "const fs = require('fs');" > process.js | ||
echo 'const artifacts = ${{ steps.goreleaser.outputs.artifacts }}' >> process.js | ||
echo "const firstNonNullDigest = artifacts.find(artifact => artifact.extra && artifact.extra.Digest != null)?.extra.Digest;" >> process.js | ||
echo "console.log(firstNonNullDigest);" >> process.js | ||
echo "fs.writeFileSync('digest.txt', firstNonNullDigest);" >> process.js | ||
node process.js | ||
echo "digest=$(cat digest.txt)" >> $GITHUB_OUTPUT | ||
- name: Attest power-control binary amd64 | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
subject-path: dist/pcs_linux_amd64_v3/hms-power-control | ||
# - name: Attest power-control binary arm64 | ||
# uses: actions/attest-build-provenance@v1 | ||
# with: | ||
# subject-path: dist/pcs_linux_arm64_v8.0/hms-power-control | ||
- name: Generate build provenance | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
subject-name: ghcr.io/cjh1/pcs | ||
subject-digest: ${{ steps.process_goreleaser_output.outputs.digest }} | ||
push-to-registry: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
version: 2.4 | ||
|
||
project_name: pcs | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
|
||
builds: | ||
- id: pcs | ||
main: ./cmd/hms-power-control | ||
binary: hms-power-control | ||
goos: | ||
- linux | ||
#- darwin | ||
goarch: | ||
- amd64 | ||
#- arm64 | ||
goamd64: | ||
- v3 | ||
env: | ||
- CGO_ENABLED=1 | ||
ldflags: | ||
- "-s -w -X main.GitCommit={{.Commit}} \ | ||
-X main.BuildTime={{.Timestamp}} \ | ||
-X main.Version={{.Version}} \ | ||
-X main.GitBranch={{.Branch}} \ | ||
-X main.GitTag={{.Tag}} \ | ||
-X main.GitState={{ .Env.GIT_STATE }} \ | ||
-X main.BuildHost={{ .Env.BUILD_HOST }} \ | ||
-X main.GoVersion={{ .Env.GO_VERSION }} \ | ||
-X main.BuildUser={{ .Env.BUILD_USER }} " | ||
|
||
dockers: | ||
- image_templates: | ||
- &amd64_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-amd64 | ||
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-amd64 | ||
- ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-amd64 | ||
use: buildx | ||
build_flag_templates: | ||
- "--pull" | ||
- "--platform=linux/amd64" | ||
- "--label=org.opencontainers.image.created={{.Date}}" | ||
- "--label=org.opencontainers.image.title={{.ProjectName}}" | ||
- "--label=org.opencontainers.image.revision={{.FullCommit}}" | ||
- "--label=org.opencontainers.image.version={{.Version}}" | ||
goarch: amd64 | ||
goamd64: v3 | ||
extra_files: | ||
- LICENSE | ||
- CHANGELOG.md | ||
- README.md | ||
- configs/ | ||
- .version | ||
|
||
# - image_templates: | ||
# - &arm64v8_linux_image ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}-arm64 | ||
# - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}-arm64 | ||
# - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}-arm64 | ||
# use: buildx | ||
# build_flag_templates: | ||
# - "--pull" | ||
# - "--platform=linux/arm64" | ||
# - "--label=org.opencontainers.image.created={{.Date}}" | ||
# - "--label=org.opencontainers.image.title={{.ProjectName}}" | ||
# - "--label=org.opencontainers.image.revision={{.FullCommit}}" | ||
# - "--label=org.opencontainers.image.version={{.Version}}" | ||
# goarch: arm64 | ||
# extra_files: | ||
# - LICENSE | ||
# - CHANGELOG.md | ||
# - README.md | ||
# - configs/ | ||
# - .version | ||
|
||
docker_manifests: | ||
- name_template: "ghcr.io/openchami/{{.ProjectName}}:latest" | ||
image_templates: | ||
- *amd64_linux_image | ||
#- *arm64v8_linux_image | ||
|
||
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }}" | ||
image_templates: | ||
- *amd64_linux_image | ||
#- *arm64v8_linux_image | ||
|
||
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}" | ||
image_templates: | ||
- *amd64_linux_image | ||
#- *arm64v8_linux_image | ||
|
||
- name_template: "ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }}" | ||
image_templates: | ||
- *amd64_linux_image | ||
#- *arm64v8_linux_image | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
files: | ||
- LICENSE | ||
- CHANGELOG.md | ||
- README.md | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
version_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
|
||
# The lines beneath this are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj |