From 57c1aa3e54eb90a3b4f243c920f72f1319212d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Mon, 21 Oct 2024 06:04:54 +0900 Subject: [PATCH] ci: produce zip for windows build --- .drone.jsonnet | 21 +++++++++++++++------ .drone.yml | 23 +++++++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index a2bdfee..facefb8 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -17,21 +17,30 @@ local CreateRelease() = { local StepGoBuild(GOOS, GOARCH) = { - local filepath = 'dist/um-%s-%s.tar.gz' % [GOOS, GOARCH], + local windows = GOOS == 'windows', + local archiveExt = if windows then 'zip' else 'tar.gz', + local filepath = 'dist/um-%s-%s.%s' % [GOOS, GOARCH, archiveExt], + + local archive = if windows then [ + // Ensure zip is installed + 'command -v zip >/dev/null || (apt update && apt install -y zip)', + 'zip -9 -j -r "%s" $DIST_DIR' % filepath, + ] else [ + 'tar -zc -C $DIST_DIR um | gzip -9 > "%s"' % filepath, + ], name: 'go build %s/%s' % [GOOS, GOARCH], image: 'golang:1.22', environment: { GOOS: GOOS, GOARCH: GOARCH, - GOPROXY: "https://goproxy.io,direct", + GOPROXY: 'https://goproxy.io,direct', }, commands: [ 'DIST_DIR=$(mktemp -d)', 'go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um', 'mkdir -p dist', - 'tar cz -f %s -C $DIST_DIR .' % filepath, - ], + ] + archive, }; local StepUploadArtifact(GOOS, GOARCH) = { @@ -71,7 +80,7 @@ local PipelineBuild(GOOS, GOARCH, RUN_TEST) = { name: 'go test', image: 'golang:1.22', environment: { - GOPROXY: "https://goproxy.io,direct", + GOPROXY: 'https://goproxy.io,direct', }, commands: ['go test -v ./...'], }] else [] @@ -100,7 +109,7 @@ local PipelineRelease() = { name: 'go test', image: 'golang:1.22', environment: { - GOPROXY: "https://goproxy.io,direct", + GOPROXY: 'https://goproxy.io,direct', }, commands: ['go test -v ./...'], }, diff --git a/.drone.yml b/.drone.yml index 535660c..873d51e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-linux-amd64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-linux-amd64.tar.gz" environment: GOARCH: amd64 GOOS: linux @@ -53,7 +53,8 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-windows-amd64.tar.gz -C $DIST_DIR . + - command -v zip >/dev/null || (apt update && apt install -y zip) + - zip -9 -j -r "dist/um-windows-amd64.zip" $DIST_DIR environment: GOARCH: amd64 GOOS: windows @@ -89,7 +90,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-darwin-amd64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-darwin-amd64.tar.gz" environment: GOARCH: amd64 GOOS: darwin @@ -131,7 +132,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-linux-amd64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-linux-amd64.tar.gz" environment: GOARCH: amd64 GOOS: linux @@ -143,7 +144,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-linux-arm64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-linux-arm64.tar.gz" environment: GOARCH: arm64 GOOS: linux @@ -155,7 +156,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-linux-386.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-linux-386.tar.gz" environment: GOARCH: "386" GOOS: linux @@ -167,7 +168,8 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-windows-amd64.tar.gz -C $DIST_DIR . + - command -v zip >/dev/null || (apt update && apt install -y zip) + - zip -9 -j -r "dist/um-windows-amd64.zip" $DIST_DIR environment: GOARCH: amd64 GOOS: windows @@ -179,7 +181,8 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-windows-386.tar.gz -C $DIST_DIR . + - command -v zip >/dev/null || (apt update && apt install -y zip) + - zip -9 -j -r "dist/um-windows-386.zip" $DIST_DIR environment: GOARCH: "386" GOOS: windows @@ -191,7 +194,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-darwin-amd64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-darwin-amd64.tar.gz" environment: GOARCH: amd64 GOOS: darwin @@ -203,7 +206,7 @@ steps: - go build -v -trimpath -ldflags="-w -s -X main.AppVersion=$(git describe --tags --always)" -o $DIST_DIR ./cmd/um - mkdir -p dist - - tar cz -f dist/um-darwin-arm64.tar.gz -C $DIST_DIR . + - tar -zc -C $DIST_DIR um | gzip -9 > "dist/um-darwin-arm64.tar.gz" environment: GOARCH: arm64 GOOS: darwin