Skip to content

Commit

Permalink
[CI] Update GitHub actions config (#312)
Browse files Browse the repository at this point in the history
# Description

Release build missing commit hash information, binaries are not
statically linked, this will cause problems on different distributions
(glibc compatibility), this PR updates the build command, and increases
the default stack size to reduce GC pressure

build config add commit hash info, disable cgo and upgrade docker image
to alpine linux 3.17 (alpine linux 3.14 EOL on 2023-05-01)

# Changes include

- [x] New feature (non-breaking change that adds functionality)
  • Loading branch information
0xcb9ff9 authored Mar 1, 2023
1 parent 3b1d596 commit a604ba4
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ jobs:
# uses: actions/[email protected]
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: "1.17.x"

- name: Build Dogechain
run: go build -ldflags="-X \"github.com/dogechain-lab/dogechain/versioning.Version=${GITHUB_REF_NAME}\" -X \"github.com/dogechain-lab/dogechain/versioning.Commit=${GITHUB_SHA}\"" -a -o dogechain . && tar -czvf dogechain.tar.gz dogechain
run: |
go build -a -o dogechain -ldflags="\
-X 'github.com/dogechain-lab/dogechain/versioning.Version=${GITHUB_REF_NAME}' \
-X 'github.com/dogechain-lab/dogechain/versioning.Commit=${GITHUB_COMMIT_HASH}' \
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime=${GITHUB_BUILT_AT}' \
-extldflags '"-Wl,-z,stack-size=0x800000" "-static"' "\
-tags 'osusergo netgo static_build' && tar -czvf dogechain.tar.gz dogechain
env:
CGO_ENABLED: 0
CC: gcc
CXX: g++
GOARC: amd64
GOOS: linux
GITHUB_COMMIT_HASH: ${{ github.sha }}
GITHUB_BUILT_AT: ${{ github.event.head_commit.timestamp }}

- name: Extract branch name
# if: github.event_name != 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: "1.17.x"
- name: Run tests
run: make test-e2e
# - name: Archive test logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: "1.17.x"

- name: Checkout code
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ jobs:
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-e CGO_ENABLED=0 \
-e GITHUB_TOKEN \
-e DOCKER_USERNAME \
-e DOCKER_PASSWORD \
-e SLACK_WEBHOOK \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
ghcr.io/goreleaser/goreleaser-cross:v${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate
env:
PACKAGE_NAME: github.com/dogechain-lab/dogechain
GOLANG_CROSS_VERSION: v1.17.9
GOLANG_CROSS_VERSION: "1.17.9"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.prepare.outputs.tag_name }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: "1.17.x"

- name: Checkout Code
uses: actions/checkout@v3
Expand Down
47 changes: 39 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ builds:
env:
- CC=o64-clang
- CXX=o64-clang++
ldflags: -s -w -X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
ldflags: >
-s -w
-X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{.Version}}'
-X 'github.com/dogechain-lab/dogechain/versioning.Commit={{ .Commit }}'
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime={{ .Date }}'
tags:
- osusergo
- netgo
- static_build

- id: darwin-arm64
main: ./main.go
Expand All @@ -28,7 +36,15 @@ builds:
env:
- CC=oa64-clang
- CXX=oa64-clang++
ldflags: -s -w -X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
ldflags: >
-s -w
-X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
-X 'github.com/dogechain-lab/dogechain/versioning.Commit={{ .Commit }}'
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime={{ .Date }}'
tags:
- osusergo
- netgo
- static_build

- id: linux-amd64
main: ./main.go
Expand All @@ -40,9 +56,17 @@ builds:
env:
- CC=gcc
- CXX=g++
ldflags:
# We need to build a static binary because we are building in a glibc based system and running in a musl container
-s -w -linkmode external -extldflags "-static" -X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
# We need to build a static binary because we are building in a glibc based system and running in a musl container
ldflags: >
-s -w
-X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
-X 'github.com/dogechain-lab/dogechain/versioning.Commit={{ .Commit }}'
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime={{ .Date }}'
-extldflags '"-Wl,-z,stack-size=0x800000" "-static"'
tags:
- osusergo
- netgo
- static_build

- id: linux-arm64
main: ./main.go
Expand All @@ -54,9 +78,16 @@ builds:
env:
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
ldflags:
# We need to build a static binary because we are building in a glibc based system and running in a musl container
-s -w -linkmode external -extldflags "-static" -X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
ldflags: >
-s -w
-X 'github.com/dogechain-lab/dogechain/versioning.Version=v{{ .Version }}'
-X 'github.com/dogechain-lab/dogechain/versioning.Commit={{ .Commit }}'
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime={{ .Date }}'
-extldflags '"-Wl,-z,stack-size=0x800000" "-static"'
tags:
- osusergo
- netgo
- static_build

archives:
- files:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.14
FROM alpine:3.17

RUN set -x \
&& apk add --update --no-cache \
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CGO_ENABLED ?= 0

.PHONY: download-spec-tests
download-spec-tests:
Expand All @@ -24,7 +25,8 @@ build:
go build -o dogechain -ldflags="\
-X 'github.com/dogechain-lab/dogechain/versioning.Version=$(LATEST_VERSION)'\
-X 'github.com/dogechain-lab/dogechain/versioning.Commit=$(COMMIT_HASH)'\
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime=$(DATE)'" \
-X 'github.com/dogechain-lab/dogechain/versioning.BuildTime=$(DATE)' "\
-tags 'osusergo netgo static_build' \
main.go

.PHONY: lint
Expand Down

0 comments on commit a604ba4

Please sign in to comment.