Skip to content

Commit

Permalink
Add static binary build to GHA workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Aug 14, 2024
1 parent e196b0e commit 28011ab
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 40 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI
on:
pull_request:
push:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Dependencies
run: |
sudo apt update
sudo apt --yes install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
- name: Verify
run: |
./scripts/verify.sh
- name: Test
run: |
./scripts/test.sh
- name: Static Build
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: build --clean --snapshot
51 changes: 51 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI
on:
push:
tags:
- 'v*'
jobs:
ci:
runs-on: ubuntu-latest
steps:
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# registry: ${{ vars.PUBLIC_REGISTRY }}
# username: ${{ secrets.PUBLIC_REGISTRY_USERNAME }}
# password: ${{ secrets.PUBLIC_REGISTRY_PASSWORD }}
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Dependencies
run: |
sudo apt update
sudo apt --yes install libgpgme-dev libassuan-dev libbtrfs-dev libdevmapper-dev pkg-config gcc
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
- name: Verify
run: |
./scripts/verify.sh
- name: Test
run: |
./scripts/test.sh
- name: Static Build
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
# - name: Image Push
# run: |
# make image-push
# env:
# TAG: ${{ github.ref_name }}
# REPO: ${{ vars.PUBLIC_REGISTRY }}/${{ vars.PUBLIC_REGISTRY_REPO }}
53 changes: 53 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- id: hangar
main: ./main.go
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
tags:
- containers_image_openpgp
- exclude_graphdriver_btrfs
- exclude_graphdriver_devicemapper
flags:
- -buildmode=pie
ldflags:
- -extldflags -static
- -s -w
- -X github.com/cnrancher/hangar/pkg/utils.Version={{.Version}}
binary: hangar

release:
prerelease: auto

archives:
- format: tar.gz
wrap_in_directory: true
files:
- LICENSE
- README.md
# 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 }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGETS := ci build test validate
TARGETS := ci build test verify
.PHONY: $(TARGETS) $(TEST_TARGETS) validation-test clean help

.dapper:
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
cd $(dirname $0)/../
WORKINGDIR=$(pwd)

${WORKINGDIR}/scripts/validate.sh
${WORKINGDIR}/scripts/verify.sh
${WORKINGDIR}/scripts/test.sh
${WORKINGDIR}/scripts/build-test.sh
${WORKINGDIR}/scripts/build.sh
Expand Down
38 changes: 0 additions & 38 deletions scripts/validate.sh

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail
cd $(dirname $0)/..
WORKINGDIR=$(pwd)

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo 'Ensure git directory is clean before run this script:'
git status --short
exit 1
fi

echo 'Running: go mod verify'
go mod verify

echo 'Running: go fmt'
go fmt
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo 'go fmt produced differences'
exit 1
fi

echo 'Running: go generate'
go generate
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo 'go generate produced differences'
exit 1
fi

echo 'Running: go mod tidy'
go mod tidy
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
echo 'go mod tidy produced differences'
exit 1
fi

0 comments on commit 28011ab

Please sign in to comment.