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 a59253d
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 149 deletions.
123 changes: 99 additions & 24 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- main
Expand Down Expand Up @@ -66,9 +68,9 @@ jobs:
- build: ubuntu-22.04
os: ubuntu-22.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
- build: windows
os: windows-latest
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
# - build: windows
# os: windows-latest
# buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}

steps:
- name: Git checkout with LF
Expand All @@ -85,25 +87,33 @@ 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
if: startswith(matrix.os, 'ubuntu')
if: ${{ startswith(matrix.os, 'ubuntu') }}
- name: Run tests
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'
shell: cmd
if: ${{ startswith(matrix.os, 'windows') }}
- name: Run tests
run: 'bazel test --config=ci ${{ matrix.buildflags }} "//..."'
if: ${{ ! startswith(matrix.os, 'windows') }}

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

needs: version
needs:
- bazel_test
- version

strategy:
matrix:
Expand All @@ -130,10 +140,10 @@ jobs:
os: ubuntu-22.04
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
pkgfile: proxydetox-${{ needs.version.outputs.version }}-jammy_amd64.deb
- build: windows
os: windows-latest
buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
pkgfile: proxydetox-${{ needs.version.outputs.version }}-windows-x86_64.zip
# - build: windows
# os: windows-latest
# buildflags: --features=negotiate --//:version=${{ needs.version.outputs.version }}
# pkgfile: proxydetox-${{ needs.version.outputs.version }}-windows-x86_64.zip

steps:
- name: Git checkout with LF
Expand All @@ -150,9 +160,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 +173,84 @@ 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 }}

cargo_build_and_test:
name: Cargo build and test
runs-on: ${{ matrix.os }}

strategy:
matrix:
build:
- windows
include:
- build: windows
os: windows-latest
mkcmd: ./tools/mkzip.ps1

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.os }}
# see https://github.com/rust-lang/rust-bindgen/issues/1797
- name: Install Windows dependency (LLVM)
uses: KyleMayes/[email protected]
if: startswith(matrix.os, 'windows')
with:
version: "11.0"
directory: ${{ runner.temp }}/llvm
- name: Set LIBCLANG_PATH
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
shell: pwsh
if: startswith(matrix.os, 'windows')
- name: Run cargo test
run: cargo test
- name: Build Release Package
id: buildpkg
run: ${{ matrix.mkcmd }}
shell: pwsh
- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: pkg
path: ./${{ steps.buildpkg.outputs.pkgfile }}

mkrelease:
name: Create Release
runs-on: ubuntu-latest
needs:
- bazel_build
- cargo_build_and_test
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download pkg artifact
uses: actions/download-artifact@v3
with:
name: pkg
- name: Create Release
run: |
gh release create v${{ github.event.inputs.version }} --generate-notes *.deb *.pkg *.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

format_check:
name: Rust lint
Expand Down
103 changes: 0 additions & 103 deletions .github/workflows/release.yaml

This file was deleted.

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
Loading

0 comments on commit a59253d

Please sign in to comment.