Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix goreleaser pipeline for CGO enabled builds #216

Merged
merged 16 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
submodules: 'true'

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.18

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
workdir: ./cmd/deepsource
args: release --rm-dist --config ../../goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TOKEN: ${{ secrets.DS_BOT_PAT }}
DEEPSOURCE_CLI_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Setup environment variables
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
echo 'HOMEBREW_TOKEN=${{secrets.DS_BOT_PAT}}' > .release-env
echo 'DEEPSOURCE_CLI_SENTRY_DSN=${{secrets.SENTRY_DSN}}' > .release-env

- name: Publish Release
run: make release
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sysroot"]
path = sysroot
url = git@github.com:goreleaser/goreleaser-cross-example-sysroot.git
50 changes: 49 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
PACKAGE_NAME := github.com/deepsourcelabs/cli
GOLANG_CROSS_VERSION ?= v1.19.5

SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2

build:
cd cmd/deepsource && GOOS=linux GOARCH=amd64 go build -tags static_all -o /tmp/deepsource .

Expand All @@ -16,6 +22,48 @@ test:
test_setup:
mkdir -p ${CODE_PATH}
cd ${CODE_PATH} && ls -A1 | xargs rm -rf
git clone https://github.com/deepsourcelabs/cli ${CODE_PATH}
git clone https://github.com/DeepSourceCorp/cli ${CODE_PATH}
chmod +x /tmp/deepsource
cp ./command/report/tests/golden_files/python_coverage.xml /tmp

.PHONY: sysroot-pack
sysroot-pack:
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)

.PHONY: sysroot-unpack
sysroot-unpack:
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -

.PHONY: release-dry-run
release-dry-run:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
@docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --skip-publish --skip-validate

.PHONY: release
release:
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean
70 changes: 60 additions & 10 deletions goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,80 @@ project_name: deepsource

before:
hooks:
- ../../scripts/gen-completions.sh
- scripts/gen-completions.sh

builds:
-
# darwin-amd64
- id: deepsource-darwin-amd64
main: ./cmd/deepsource
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
flags:
- -tags=static_all
goos:
- darwin
goarch:
- amd64
ldflags:
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"

# darwin-arm64
- id: deepsource-darwin-arm64
main: ./cmd/deepsource
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
flags:
- -tags=static_all
goos:
- freebsd
- openbsd
- netbsd
- linux
- darwin
goarch:
- 386
- arm64
ldflags:
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"

# linux-amd64
- id: deepsource-linux-amd64
main: ./cmd/deepsource
env:
- CGO_ENABLED=1
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
flags:
- -tags=static_all
goos:
- linux
goarch:
- amd64
ldflags:
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"

# linux-arm64
- id: deepsource-linux-arm64
main: ./cmd/deepsource
env:
- CGO_ENABLED=1
- CC=aarch64-linux-gnu-gcc
- CXX=aarch64-linux-gnu-g++
flags:
- -tags=static_all
goos:
- linux
goarch:
- arm64
ldflags:
- "-X 'main.version={{ .Version }}' -X 'main.SentryDSN={{ .Env.DEEPSOURCE_CLI_SENTRY_DSN }}'"

# windows-amd64
- id: "windows-deepsource"
main: ./cmd/deepsource
env:
- CGO_ENABLED=0
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -tags=static_all
goos:
Expand All @@ -38,8 +89,7 @@ builds:
archives:
-
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
deepsource_{{ .Version }}_{{ .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen-completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ mkdir completions

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