Skip to content

Commit ff0b43a

Browse files
fix: fix goreleaser pipeline for CGO enabled builds (#216)
* chore: remove bsd based os Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test action on pull request Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test run on pull request commit Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: remove 386 arch Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test darwin builds Signed-off-by: Siddhant N Trivedi <[email protected]> * fix: fix env vars Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test using golang-cross dockerfile Signed-off-by: Siddhant N Trivedi <[email protected]> * fix: fix error Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: remove config path Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: add linux and windows binaries Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: add main field Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: add the action Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: test hooks Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: fix main.go path Signed-off-by: Siddhant N Trivedi <[email protected]> * chore: change make command Signed-off-by: Siddhant N Trivedi <[email protected]> --------- Signed-off-by: Siddhant N Trivedi <[email protected]>
1 parent a71a734 commit ff0b43a

File tree

5 files changed

+124
-26
lines changed

5 files changed

+124
-26
lines changed

.github/workflows/release.yml

+11-14
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,21 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717
with:
1818
fetch-depth: 0
19-
ref: master
19+
submodules: 'true'
2020

2121
- name: Set up Go
22-
uses: actions/setup-go@v2
22+
uses: actions/setup-go@v4
2323
with:
2424
go-version: 1.18
2525

26-
- name: Run GoReleaser
27-
uses: goreleaser/goreleaser-action@v2
28-
with:
29-
distribution: goreleaser
30-
version: latest
31-
workdir: ./cmd/deepsource
32-
args: release --rm-dist --config ../../goreleaser.yaml
33-
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
HOMEBREW_TOKEN: ${{ secrets.DS_BOT_PAT }}
36-
DEEPSOURCE_CLI_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
26+
- name: Setup environment variables
27+
run: |-
28+
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
29+
echo 'HOMEBREW_TOKEN=${{secrets.DS_BOT_PAT}}' > .release-env
30+
echo 'DEEPSOURCE_CLI_SENTRY_DSN=${{secrets.SENTRY_DSN}}' > .release-env
31+
32+
- name: Publish Release
33+
run: make release

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "sysroot"]
2+
path = sysroot
3+
url = [email protected]:goreleaser/goreleaser-cross-example-sysroot.git

Makefile

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
PACKAGE_NAME := github.com/deepsourcelabs/cli
2+
GOLANG_CROSS_VERSION ?= v1.19.5
3+
4+
SYSROOT_DIR ?= sysroots
5+
SYSROOT_ARCHIVE ?= sysroots.tar.bz2
6+
17
build:
28
cd cmd/deepsource && GOOS=linux GOARCH=amd64 go build -tags static_all -o /tmp/deepsource .
39

@@ -16,6 +22,48 @@ test:
1622
test_setup:
1723
mkdir -p ${CODE_PATH}
1824
cd ${CODE_PATH} && ls -A1 | xargs rm -rf
19-
git clone https://github.com/deepsourcelabs/cli ${CODE_PATH}
25+
git clone https://github.com/DeepSourceCorp/cli ${CODE_PATH}
2026
chmod +x /tmp/deepsource
2127
cp ./command/report/tests/golden_files/python_coverage.xml /tmp
28+
29+
.PHONY: sysroot-pack
30+
sysroot-pack:
31+
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)
32+
33+
.PHONY: sysroot-unpack
34+
sysroot-unpack:
35+
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -
36+
37+
.PHONY: release-dry-run
38+
release-dry-run:
39+
@if [ ! -f ".release-env" ]; then \
40+
echo "\033[91m.release-env is required for release\033[0m";\
41+
exit 1;\
42+
fi
43+
@docker run \
44+
--rm \
45+
-e CGO_ENABLED=1 \
46+
--env-file .release-env \
47+
-v /var/run/docker.sock:/var/run/docker.sock \
48+
-v `pwd`:/go/src/$(PACKAGE_NAME) \
49+
-v `pwd`/sysroot:/sysroot \
50+
-w /go/src/$(PACKAGE_NAME) \
51+
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
52+
release --clean --skip-publish --skip-validate
53+
54+
.PHONY: release
55+
release:
56+
@if [ ! -f ".release-env" ]; then \
57+
echo "\033[91m.release-env is required for release\033[0m";\
58+
exit 1;\
59+
fi
60+
docker run \
61+
--rm \
62+
-e CGO_ENABLED=1 \
63+
--env-file .release-env \
64+
-v /var/run/docker.sock:/var/run/docker.sock \
65+
-v `pwd`:/go/src/$(PACKAGE_NAME) \
66+
-v `pwd`/sysroot:/sysroot \
67+
-w /go/src/$(PACKAGE_NAME) \
68+
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
69+
release --clean

goreleaser.yaml

+60-10
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,80 @@ project_name: deepsource
22

33
before:
44
hooks:
5-
- ../../scripts/gen-completions.sh
5+
- scripts/gen-completions.sh
66

77
builds:
8-
-
8+
# darwin-amd64
9+
- id: deepsource-darwin-amd64
10+
main: ./cmd/deepsource
911
env:
1012
- CGO_ENABLED=1
13+
- CC=o64-clang
14+
- CXX=o64-clang++
15+
flags:
16+
- -tags=static_all
17+
goos:
18+
- darwin
19+
goarch:
20+
- amd64
21+
ldflags:
22+
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"
23+
24+
# darwin-arm64
25+
- id: deepsource-darwin-arm64
26+
main: ./cmd/deepsource
27+
env:
28+
- CGO_ENABLED=1
29+
- CC=o64-clang
30+
- CXX=o64-clang++
1131
flags:
1232
- -tags=static_all
1333
goos:
14-
- freebsd
15-
- openbsd
16-
- netbsd
17-
- linux
1834
- darwin
1935
goarch:
20-
- 386
36+
- arm64
37+
ldflags:
38+
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"
39+
40+
# linux-amd64
41+
- id: deepsource-linux-amd64
42+
main: ./cmd/deepsource
43+
env:
44+
- CGO_ENABLED=1
45+
- CC=x86_64-linux-gnu-gcc
46+
- CXX=x86_64-linux-gnu-g++
47+
flags:
48+
- -tags=static_all
49+
goos:
50+
- linux
51+
goarch:
2152
- amd64
53+
ldflags:
54+
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"
55+
56+
# linux-arm64
57+
- id: deepsource-linux-arm64
58+
main: ./cmd/deepsource
59+
env:
60+
- CGO_ENABLED=1
61+
- CC=aarch64-linux-gnu-gcc
62+
- CXX=aarch64-linux-gnu-g++
63+
flags:
64+
- -tags=static_all
65+
goos:
66+
- linux
67+
goarch:
2268
- arm64
2369
ldflags:
2470
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"
71+
72+
# windows-amd64
2573
- id: "windows-deepsource"
74+
main: ./cmd/deepsource
2675
env:
27-
- CGO_ENABLED=0
76+
- CGO_ENABLED=1
77+
- CC=x86_64-w64-mingw32-gcc
78+
- CXX=x86_64-w64-mingw32-g++
2879
flags:
2980
- -tags=static_all
3081
goos:
@@ -38,8 +89,7 @@ builds:
3889
archives:
3990
-
4091
name_template: >-
41-
{{ .ProjectName }}_
42-
{{- title .Os }}_
92+
deepsource_{{ .Version }}_{{ .Os }}_
4393
{{- if eq .Arch "amd64" }}x86_64
4494
{{- else if eq .Arch "386" }}i386
4595
{{- else }}{{ .Arch }}{{ end }}

scripts/gen-completions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ mkdir completions
66

77
# Generate completion using the in-built cobra completion command
88
for shell in bash zsh fish; do
9-
go run main.go completion "$shell" > "completions/deepsource.$shell"
9+
go run cmd/deepsource/main.go completion "$shell" > "completions/deepsource.$shell"
1010
done

0 commit comments

Comments
 (0)