Skip to content

Commit

Permalink
Improve CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Dec 16, 2023
1 parent 122936b commit 754e786
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ jobs:
path: |
~/.cache/bazel_build_cache
~/.cache/bazel_repo_cache
key: ${{ runner.os }}-bazel-test-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
key: ${{ matrix.build }}-bazel-test-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-test-
${{ matrix.build }}-bazel-test-
- name: Setup Windows Bazelrc
# https://bazel.build/configure/windows
run: |
echo "startup --output_user_root=C:/tmp" > ${{ github.workspace }}/user.bazelrc
shell: cmd
if: startswith(matrix.os, 'windows')
- name: Install Linux dependency
run: sudo apt-get install libkrb5-dev
Expand All @@ -100,7 +101,7 @@ jobs:
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'

bazel_build:
name: Bazel build and test
name: Bazel build release package
runs-on: ${{ matrix.os }}

needs: version
Expand Down Expand Up @@ -150,9 +151,9 @@ jobs:
path: |
~/.cache/bazel_build_cache
~/.cache/bazel_repo_cache
key: ${{ runner.os }}-bazel-test-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
key: ${{ matrix.build }}-bazel-test-${{ hashFiles('Cargo.Bazel.lock', 'WORKSPACE') }}
restore-keys: |
${{ runner.os }}-bazel-test-
${{ matrix.build }}-bazel-test-
- name: Setup Windows Bazelrc
# https://bazel.build/configure/windows
run: |
Expand All @@ -163,19 +164,14 @@ 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
- name: Query package file
id: querypkg
run: |
set -o pipefail
BAZEL_OUT=$(bazel info --config=ci output_path)
PKGFILE=$(bazel cquery --config=ci ${{ matrix.buildflags }} --output=files //pkg)
printf 'pkgfile=%s/%s\n' "${BAZEL_OUT}" "${PKGFILE#bazel-out/}" | tee -a "${GITHUB_OUTPUT}"
run: bazel build -c opt --config=ci ${{ matrix.buildflags }} "//pkg"
- name: Copy package
run: bazel run -c opt --config=ci ${{ matrix.buildflags }} "//pkg:copy" -- ${{ matrix.pkgfile }}
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.pkgfile }}
path: ./${{ steps.querypkg.outputs.pkgfile }}
name: pkg
path: ./${{ matrix.pkgfile }}

format_check:
name: Rust lint
Expand Down
11 changes: 8 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "string_list_flag")
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")

exports_files(
[".cargo/config.toml"],
[
".cargo/config.toml",
"Cargo.toml",
],
visibility = ["//visibility:public"],
)

Expand Down Expand Up @@ -39,9 +43,10 @@ platform(
],
)

sh_binary(
native_binary(
name = "current_version",
srcs = ["//tools:toml_get"],
out = "current_version",
src = "//tools:toml_get",
args = [
"-f$(location //:Cargo.toml)",
"-nversion",
Expand Down
12 changes: 10 additions & 2 deletions pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ pkg_variables(

genrule(
name = "version",
srcs = ["//proxydetox:Cargo.toml"],
srcs = ["//:Cargo.toml"],
outs = ["version.txt"],
cmd = "$(location //tools:toml_get) -f $(location //proxydetox:Cargo.toml) package version > \"$@\"",
cmd = "$(location //tools:toml_get) -f $(location //:Cargo.toml) workspace package version > \"$@\"",
tools = ["//tools:toml_get"],
visibility = ["//pkg:__subpackages__"],
)

sh_binary(
name = "copy",
srcs = ["copy.sh"],
data = [":pkg"],
env = {"PKG": "$(location :pkg)"},
deps = ["@bazel_tools//tools/bash/runfiles"],
)
26 changes: 26 additions & 0 deletions pkg/copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v3 ---

set -euo pipefail

# When not arguemnt is given, copy to the workspace root directory.
dst=${1:-${BUILD_WORKSPACE_DIRECTORY}}

# Take care of relative path, since this scripts working directoy is
# not the one where `bazel run ...` was called.
case "${dst}" in
/*) ;;
*) dst=${BUILD_WORKING_DIRECTORY}/${dst}
esac

install -v "$(rlocation proxydetox/$PKG)" "${dst}"
6 changes: 2 additions & 4 deletions proxydetox/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("@build_bazel_rules_apple//apple:macos.bzl", "macos_command_line_applicatio
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_static_library", "rust_test")

exports_files(["Cargo.toml"])

rust_binary(
name = "proxydetox",
srcs = [
Expand Down Expand Up @@ -42,8 +40,8 @@ rust_test(
proc_macro = True,
),
deps = [
"//proxydetoxlib",
"//detox_net",
"//proxydetoxlib",
] + all_crate_deps(
normal = True,
),
Expand All @@ -69,8 +67,8 @@ rust_static_library(
"static_library",
],
deps = [
"//proxydetoxlib",
"//detox_net",
"//proxydetoxlib",
] + all_crate_deps(
normal = True,
),
Expand Down

0 comments on commit 754e786

Please sign in to comment.