Skip to content

Commit 56014b9

Browse files
reuse make file in gh actions
1 parent 475b630 commit 56014b9

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

.github/workflows/go.yml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,8 @@ jobs:
1313
fetch-depth: 0 # Needed for git history
1414
- name: Set up Go
1515
uses: actions/setup-go@v4
16-
- name: Set version info
17-
id: version
18-
run: |
19-
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "development")
20-
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
21-
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
22-
echo "VERSION=${VERSION}" >> $GITHUB_ENV
23-
echo "COMMIT=${COMMIT}" >> $GITHUB_ENV
24-
echo "BUILD_TIME=${BUILD_TIME}" >> $GITHUB_ENV
25-
echo "LDFLAGS=-X 'codacy/cli-v2/version.Version=${VERSION}' -X 'codacy/cli-v2/version.GitCommit=${COMMIT}' -X 'codacy/cli-v2/version.BuildTime=${BUILD_TIME}'" >> $GITHUB_ENV
26-
- name: Build CLI for Linux
27-
run: |
28-
GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o cli-v2-linux ./cli-v2.go
29-
- name: Build CLI for Windows
30-
run: |
31-
GOOS=windows GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o cli-v2.exe ./cli-v2.go
32-
- name: Build CLI for macOS
33-
run: |
34-
GOOS=darwin GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o cli-v2-macos ./cli-v2.go
16+
- name: Build CLI for all platforms
17+
run: make build-all
3518
- name: Upload CLI binaries
3619
uses: actions/upload-artifact@v4
3720
with:
@@ -50,7 +33,7 @@ jobs:
5033
uses: actions/setup-go@v4
5134
- name: Install dependencies from .codacy/codacy.yaml
5235
run: |
53-
go build ./cli-v2.go
36+
make build
5437
./cli-v2 install
5538
- name: "Run tests"
5639
run: |

.github/workflows/it-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
steps:
1717
- name: Checkout code
1818
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Needed for git history
1921

2022
- name: Set up Go
2123
uses: actions/setup-go@v5
@@ -46,7 +48,6 @@ jobs:
4648
if: matrix.os != 'windows-latest'
4749
run: chmod +x cli-v2
4850

49-
5051
- name: Run tool tests
5152
if: matrix.os != 'windows-latest'
5253
id: run_tests

Makefile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
.PHONY: build clean
1+
.PHONY: build clean build-all build-linux build-darwin build-windows
22

33
# Get the version from git describe or fallback to a default version
44
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "development")
55
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
66
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
77

88
# Build flags
9-
LDFLAGS := -X 'codacy/cli-v2/version.Version=$(VERSION)' -X 'codacy/cli-v2/version.GitCommit=$(COMMIT)' -X 'codacy/cli-v2/version.BuildTime=$(BUILD_TIME)'
9+
LDFLAGS := -X 'codacy/cli-v2/version.Version=$(VERSION)' \
10+
-X 'codacy/cli-v2/version.GitCommit=$(COMMIT)' \
11+
-X 'codacy/cli-v2/version.BuildTime=$(BUILD_TIME)'
1012

11-
# Build the CLI
13+
# Build the CLI for current platform
1214
build:
1315
go build -ldflags "$(LDFLAGS)" -o cli-v2
1416

15-
# Clean build artifacts
16-
clean:
17-
rm -f cli-v2
17+
# Build for Linux
18+
build-linux:
19+
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2-linux
20+
21+
# Build for macOS
22+
build-darwin:
23+
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2-macos
24+
25+
# Build for Windows
26+
build-windows:
27+
GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2.exe
1828

1929
# Build for all platforms
20-
build-all: clean
21-
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2_linux_amd64
22-
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2_darwin_amd64
23-
GOOS=windows GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o cli-v2_windows_amd64.exe
30+
build-all: build-linux build-darwin build-windows
31+
32+
# Clean build artifacts
33+
clean:
34+
rm -f cli-v2 cli-v2-linux cli-v2-macos cli-v2.exe

0 commit comments

Comments
 (0)