Skip to content

Commit

Permalink
refactor(ci): rename CLASH_RS_CI to CLASH_DOCKER_TEST (#601)
Browse files Browse the repository at this point in the history
* ci: rename CLASH_RS_CI to CLASH_DOCKER_TEST

* ci(cross): add environment passthrough

* simplification
  • Loading branch information
Itsusinn authored Sep 21, 2024
1 parent 650ca53 commit 9e580a6
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 24 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,21 @@ jobs:
cross: false
postfix: ".exe"
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
rustflags: >-
-Ctarget-feature=+crt-static
-Clink-args=/NODEFAULTLIB:libvcruntimed.lib
-Clink-args=/NODEFAULTLIB:vcruntime.lib
-Clink-args=/NODEFAULTLIB:vcruntimed.lib
-Clink-args=/NODEFAULTLIB:libcmtd.lib
-Clink-args=/NODEFAULTLIB:msvcrt.lib
-Clink-args=/NODEFAULTLIB:msvcrtd.lib
-Clink-args=/NODEFAULTLIB:libucrt.lib
-Clink-args=/NODEFAULTLIB:libucrtd.lib
-Clink-args=/DEFAULTLIB:libcmt.lib
-Clink-args=/DEFAULTLIB:libvcruntime.lib
-Clink-args=/DEFAULTLIB:ucrt.lib
--cfg tokio_unstable
- os: windows-latest
target: aarch64-pc-windows-msvc
release-name: aarch64-pc-windows-msvc-static-crt
Expand Down Expand Up @@ -189,11 +203,18 @@ jobs:
toolchain: ${{ matrix.toolchain || 'nightly' }}
target: ${{ matrix.target }}
components: ${{ matrix.components || 'rustfmt, clippy' }}

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
version: "23.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Set environment variables
run: |
echo "CLASH_GIT_REF=${GITHUB_REF}" >> $GITHUB_ENV
echo "CLASH_GIT_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Cargo fmt
uses: clechasseur/rs-cargo@v2
with:
Expand All @@ -207,8 +228,6 @@ jobs:
use-cross: ${{ matrix.cross }}
command: clippy
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} -- -D warnings
env:
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}

- name: Cargo test (docker test on linux)
uses: clechasseur/rs-cargo@v2
Expand All @@ -219,6 +238,7 @@ jobs:
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }}
env:
CROSS_CONTAINER_OPTS: "--network host"
CLASH_DOCKER_TEST: "true"
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}

- name: Cargo test (no docker test on windows-non-arm and macos)
Expand All @@ -229,7 +249,6 @@ jobs:
command: test
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }}
env:
CLASH_RS_CI: "true"
RUSTFLAGS: ${{ matrix.rustflags || '--cfg tokio_unstable' }}

- name: Cargo build
Expand Down Expand Up @@ -353,9 +372,8 @@ jobs:
with:
submodules: true

- name: Get the current Git commit hash
- name: Set docker image's tag
run: |
echo "OWNER=${GITHUB_REPOSITORY_OWNER@L}" >> $GITHUB_ENV
echo "TAG_VERSION=${REGISTRY}/${GITHUB_REPOSITORY_OWNER@L}/${IMAGE_NAME}:${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TAG_LATEST=${REGISTRY}/${GITHUB_REPOSITORY_OWNER@L}/${IMAGE_NAME}:latest" >> $GITHUB_ENV
Expand Down Expand Up @@ -386,7 +404,7 @@ jobs:
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.OWNER }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push release
Expand All @@ -395,7 +413,7 @@ jobs:
context: .
file: .github/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
push: true
tags: ${{ env.TAG_VERSION }},${{ env.TAG_LATEST }}


Expand Down
4 changes: 2 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pre-build = [
]

[build.env]
# Docker in docker
volumes = ["/var/run/docker.sock=/var/run/docker.sock"]
volumes = ["/var/run/docker.sock=/var/run/docker.sock"] # Docker in docker
passthrough = ["CLASH_GIT_REF", "CLASH_GIT_SHA", "RUSTFLAGS", "CLASH_DOCKER_TEST"]

[target.x86_64-unknown-linux-gnu]
image = "ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main"
Expand Down
10 changes: 7 additions & 3 deletions clash/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#![feature(let_chains)]
fn main() {
println!("cargo:rerun-if-env-changed=GITHUB_REF");
let version = if let Some("refs/heads/master") = option_env!("GITHUB_REF")
&& let Some(sha) = option_env!("GITHUB_SHA")
let vars = ["CLASH_GIT_REF", "CLASH_GIT_SHA"];
for var in vars {
println!("cargo:rerun-if-env-changed={var}");
}

let version = if let Some("refs/heads/master") = option_env!("CLASH_GIT_REF")
&& let Some(sha) = option_env!("CLASH_GIT_SHA")
{
let short_sha = &sha[..7];
// Nightly relase below
Expand Down
8 changes: 4 additions & 4 deletions clash_lib/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() -> std::io::Result<()> {
println!("cargo::rustc-check-cfg=cfg(ci)");
println!("cargo:rerun-if-env-changed=CLASH_RS_CI");
if std::env::var("CLASH_RS_CI").is_ok() {
println!("cargo::rustc-cfg=ci");
println!("cargo::rustc-check-cfg=cfg(docker_test)");
println!("cargo:rerun-if-env-changed=CLASH_DOCKER_TEST");
if let Some("1" | "true") = option_env!("CLASH_DOCKER_TEST") {
println!("cargo::rustc-cfg=docker_test");
}

println!("cargo:rerun-if-changed=src/common/geodata/geodata.proto");
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl OutboundHandler for Handler {
}

#[cfg(feature = "shadowsocks")]
#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {

use tokio::sync::RwLock;
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/shadowsocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {

use super::super::utils::test_utils::{
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/socks/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {

use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/trojan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {

use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
};

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
pub mod test_utils;

mod platform;
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/vmess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {
use crate::proxy::utils::test_utils::{
config_helper::test_config_base_dir,
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/wg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl OutboundHandler for Handler {
}
}

#[cfg(all(test, not(ci)))]
#[cfg(all(test, docker_test))]
mod tests {

use crate::proxy::utils::{
Expand Down

0 comments on commit 9e580a6

Please sign in to comment.