Skip to content

Commit 8493e2f

Browse files
authored
Merge pull request #8 from kindlyops/bazel-skylib
Support development on Windows using bazel and powershell
2 parents c8419a4 + 06ecec8 commit 8493e2f

File tree

10 files changed

+58
-46
lines changed

10 files changed

+58
-46
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
token: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
2121
ref: ${{ github.head_ref }}
2222
- name: bazel build
23-
run: bazel run :install
23+
run: bazel build //...
2424
- name: Sync Dependencies
2525
run: bazel run //:vendor
2626
if: github.actor == 'dependabot-preview[bot]'
@@ -41,19 +41,19 @@ jobs:
4141
- name: dry run goreleaser
4242
uses: goreleaser/goreleaser-action@master
4343
env:
44-
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
44+
POWERSHELL_TELEMETRY_OPTOUT: true
4545
with:
4646
version: latest
4747
args: release --snapshot --skip-publish
4848
- uses: actions/upload-artifact@v2
4949
with:
5050
name: vbs-snapshot-macos
51-
path: bdist/vbs-darwin
51+
path: bazel-bin/bdist/vbs_darwin_amd64/vbs
5252
- uses: actions/upload-artifact@v2
5353
with:
5454
name: vbs-snapshot-windows
55-
path: bdist/vbs-windows.exe
55+
path: bazel-bin/bdist/vbs_windows_amd64/vbs.exe
5656
- uses: actions/upload-artifact@v2
5757
with:
5858
name: vbs-snapshot-linux
59-
path: bdist/vbs-linux
59+
path: bazel-bin/bdist/vbs_linux_amd64/vbs

.github/workflows/release-publisher.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: Run goreleaser
3131
uses: goreleaser/goreleaser-action@master
3232
env:
33+
POWERSHELL_TELEMETRY_OPTOUT: true
3334
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
3435
with:
3536
version: latest

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ builds:
1111
- amd64
1212
binary: vbs
1313
hooks:
14-
post: ./goreleaser-post-hook.sh
14+
post: pwsh goreleaser-post-hook.ps1
1515

1616
checksum:
1717
name_template: 'checksums.txt'

BUILD.bazel

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
22
load("@bazel_gazelle//:def.bzl", "gazelle")
3-
load("@rules_pkg//:pkg.bzl", "pkg_tar")
43
load("//:version.bzl", "VERSION")
4+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
55

66
# gazelle:prefix github.com/kindlyops/vbs
77
# gazelle:exclude dummy.go
@@ -51,25 +51,35 @@ go_binary(
5151
},
5252
)
5353

54-
pkg_tar(
55-
name = "bdist",
56-
srcs = [
57-
"//:vbs-darwin",
58-
"//:vbs-linux",
59-
"//:vbs-windows",
60-
],
61-
tags = ["manual"],
62-
visibility = ["//visibility:private"],
54+
alias(
55+
name = "vbs",
56+
actual = select({
57+
"@io_bazel_rules_go//go/platform:linux_amd64": ":vbs-linux",
58+
"@io_bazel_rules_go//go/platform:darwin_amd64": ":vbs-darwin",
59+
"@io_bazel_rules_go//go/platform:windows_amd64": ":vbs-windows",
60+
"//conditions:default": ":vbs-linux",
61+
}),
6362
)
6463

65-
sh_binary(
66-
name = "install",
67-
srcs = ["install.sh"],
68-
args = ["$(location :bdist.tar)"],
69-
data = [":bdist.tar"],
70-
tags = ["manual"],
64+
copy_file(
65+
name = "install-darwin",
66+
src = "//:vbs-darwin",
67+
out = "bdist/vbs_darwin_amd64/vbs",
7168
)
7269

70+
copy_file(
71+
name = "install-linux",
72+
src = "//:vbs-linux",
73+
out = "bdist/vbs_linux_amd64/vbs",
74+
)
75+
76+
copy_file(
77+
name = "install-windows",
78+
src = "//:vbs-windows",
79+
out = "bdist/vbs_windows_amd64/vbs.exe",
80+
)
81+
82+
7383
go_test(
7484
name = "go_default_test",
7585
size = "small",
@@ -81,6 +91,9 @@ go_test(
8191
"@io_bazel_rules_go//go/platform:darwin_amd64": [
8292
"$(location :vbs-darwin)",
8393
],
94+
"@io_bazel_rules_go//go/platform:windows_amd64": [
95+
"$(location :vbs-windows)",
96+
],
8497
"//conditions:default": [],
8598
}),
8699
data = select({
@@ -90,6 +103,9 @@ go_test(
90103
"@io_bazel_rules_go//go/platform:darwin_amd64": [
91104
":vbs-darwin",
92105
],
106+
"@io_bazel_rules_go//go/platform:windows_amd64": [
107+
":vbs-windows",
108+
],
93109
"//conditions:default": [],
94110
}),
95111
embed = [":go_default_library"],

WORKSPACE

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ http_archive(
5050
)
5151

5252
http_archive(
53-
name = "rules_pkg",
54-
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
55-
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
53+
name = "bazel_skylib",
54+
urls = [
55+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
56+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
57+
],
58+
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
5659
)
57-
58-
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
59-
60-
rules_pkg_dependencies()
60+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
61+
bazel_skylib_workspace()

bdist/.gitkeep

Whitespace-only changes.

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use at your own risk.
5454
// Execute adds all child commands to the root command and sets flags appropriately.
5555
// This is called by main.main(). It only needs to happen once to the rootCmd.
5656
func Execute(v string) {
57-
rootCmd.SetVersionTemplate(v)
57+
rootCmd.SetVersionTemplate(v + "\n")
5858
if err := rootCmd.Execute(); err != nil {
5959
fmt.Println(err)
6060
os.Exit(1)

goreleaser-post-hook.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env pwsh
2+
3+
Write-Output "moving bazel outputs to goreleaser dist directory for packaging..."
4+
5+
# this gets invoked several times by goreleaser, we already have all the artifacts
6+
# from bazel so just copy them once
7+
if (-Not (Test-Path (Resolve-Path "dist"))) {
8+
New-Item -Force -Path (Get-Location).Path -Name "dist"
9+
Copy-Item (Resolve-Path "bazel-bin/bdist/*") -Destination (Resolve-Path "dist") -Recurse -Force
10+
}

goreleaser-post-hook.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

install.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)