Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ci): rename CLASH_RS_CI to CLASH_DOCKER_TEST #601

Merged
merged 18 commits into from
Sep 21, 2024
Merged
25 changes: 11 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ jobs:
postfix: ".exe"
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --cfg tokio_unstable"
ibigbug marked this conversation as resolved.
Show resolved Hide resolved
- os: windows-latest
target: i686-pc-windows-msvc
release-name: i686-pc-windows-msvc-static-crt
cross: false
postfix: ".exe"
extra-args: "--all-features"
rustflags: "-Ctarget-feature=+crt-static --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 +182,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 +207,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 +217,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 +228,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 +351,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 +383,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 +392,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