Skip to content

Commit

Permalink
CI: Stamp version into binary
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Dec 17, 2023
1 parent 505d40d commit 46cd2e4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 15 deletions.
61 changes: 48 additions & 13 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
id: version
run: |
bazel run --config=ci //:current_version | tee -a $GITHUB_OUTPUT
- name: Rev
id: rev
run: |
printf 'rev=%s\n' $(git rev-parse --short HEAD) | tee -a $GITHUB_OUTPUT
bazel_test:
name: Bazel test
Expand All @@ -62,16 +66,16 @@ jobs:
include:
- build: macos-x86_64
os: macos-latest
buildflags: --features=negotiate --config=x86_64_apple_darwin --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate --config=x86_64_apple_darwin
- build: ubuntu-20.04
os: ubuntu-20.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate
- build: ubuntu-22.04
os: ubuntu-22.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate
# - build: windows
# os: windows-latest
# buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
# buildflags: --features=negotiate

steps:
- name: Git checkout with LF
Expand Down Expand Up @@ -101,11 +105,25 @@ jobs:
run: sudo apt-get install libkrb5-dev
if: ${{ startswith(matrix.os, 'ubuntu') }}
- name: Run tests
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'
run: >
bazel
test
--config=ci
--//:version=${{ needs.version.outputs.version }}
--//:rev=${{ needs.version.outputs.rev }}
${{ matrix.buildflags }}
"//..."
shell: cmd
if: ${{ startswith(matrix.os, 'windows') }}
- name: Run tests
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'
run: >
bazel
test
--config=ci
--//:version=${{ needs.version.outputs.version }}
--//:rev=${{ needs.version.outputs.rev }}
${{ matrix.buildflags }}
"//..."
if: ${{ ! startswith(matrix.os, 'windows') }}

bazel_build:
Expand All @@ -127,23 +145,23 @@ jobs:
include:
- build: macos-aarch64
os: macos-latest
buildflags: --features=negotiate --config=aarch64_apple_darwin --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate --config=aarch64_apple_darwin
pkgfile: proxydetox-${{ needs.version.outputs.version }}-apple-darwin-aarch64.pkg
- build: macos-x86_64
os: macos-latest
buildflags: --features=negotiate --config=x86_64_apple_darwin --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate --config=x86_64_apple_darwin
pkgfile: proxydetox-${{ needs.version.outputs.version }}-apple-darwin-x86_64.pkg
- build: ubuntu-20.04
os: ubuntu-20.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate
pkgfile: proxydetox-${{ needs.version.outputs.version }}-focal_amd64.deb
- build: ubuntu-22.04
os: ubuntu-22.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
buildflags: --features=negotiate
pkgfile: proxydetox-${{ needs.version.outputs.version }}-jammy_amd64.deb
# - build: windows
# os: windows-latest
# buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
# buildflags: --features=negotiate
# pkgfile: proxydetox-${{ needs.version.outputs.version }}-windows-x86_64.zip

steps:
Expand Down Expand Up @@ -174,9 +192,26 @@ jobs:
run: sudo apt-get install libkrb5-dev
if: startswith(matrix.os, 'ubuntu')
- name: Build package
run: bazel build -c opt --config=ci ${{ matrix.buildflags }} "//pkg"
run: >
bazel build
-c opt
--config=ci
--//:version=${{ needs.version.outputs.version }}
--//:rev=${{ needs.version.outputs.rev }}
${{ matrix.buildflags }}
"//pkg"
- name: Copy package
run: bazel run -c opt --config=ci ${{ matrix.buildflags }} "//pkg:copy" -- ${{ matrix.pkgfile }}
run: >
bazel
run
-c opt
--config=ci
--//:version=${{ needs.version.outputs.version }}
--//:rev=${{ needs.version.outputs.rev }}
${{ matrix.buildflags }}
"//pkg:copy"
--
${{ matrix.pkgfile }}
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ string_flag(
visibility = ["//visibility:public"],
)

string_flag(
name = "rev", # `git rev-parse --short=10 HEAD`
build_setting_default = "unknown",
visibility = ["//visibility:public"],
)

string_list_flag(
name = "features",
build_setting_default = [],
Expand Down
9 changes: 8 additions & 1 deletion bazel/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ def _pkg_variables_impl(ctx):
values = {
"architecture": ctx.attr.architecture,
"os": ctx.attr.os,
"rev": ctx.attr.rev[BuildSettingInfo].value,
"version": ctx.attr.version[BuildSettingInfo].value,
}
return PackageVariablesInfo(values = values)
return [
PackageVariablesInfo(values = values),
platform_common.TemplateVariableInfo({k.upper(): v for k, v in values.items()}),
]

pkg_variables = rule(
implementation = _pkg_variables_impl,
Expand All @@ -18,6 +22,9 @@ pkg_variables = rule(
"os": attr.string(
doc = "Operating system of this build.",
),
"rev": attr.label(
doc = "Revision of this build.",
),
"version": attr.label(
doc = "Version of this build.",
),
Expand Down
6 changes: 5 additions & 1 deletion pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ pkg_variables(
"@platforms//os:windows": "windows",
"//conditions:default": "unknown",
}),
rev = "//:rev",
version = "//:version",
visibility = ["//pkg:__subpackages__"],
visibility = [
"//pkg:__subpackages__",
"//proxydetoxlib:__subpackages__",
],
)

genrule(
Expand Down
6 changes: 6 additions & 0 deletions proxydetoxlib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ rust_library(
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
rustc_env = {
"CARGO_PKG_VERSION": "$(VERSION)",
"PROXYDETOX_BUILD_GIT_HASH": "$(REV)",
},
toolchains = ["//pkg:variables"],
visibility = ["//visibility:public"],
deps = [
"//detox_net",
Expand Down Expand Up @@ -83,6 +88,7 @@ rust_test(
normal_dev = True,
),
)

rust_test(
name = "proxydetoxlib_http_direct_test",
srcs = ["tests/http_direct.rs"] + env_src,
Expand Down

0 comments on commit 46cd2e4

Please sign in to comment.