Skip to content

Commit

Permalink
build: Handle detached HEAD and shadow.rs in target/
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Aug 21, 2024
1 parent 2ab2c1e commit ee22a27
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- uses: actions/cache@v3
Expand All @@ -26,9 +26,15 @@ jobs:
run: |
fixtures/start_fileserver.sh &
- name: Remove files for a build with correct version info
run: |
find target/ -name 'shadow*' -exec rm -r {} + || true
find target/ -name 'tsumugu' -delete || true
- name: Test & Compile
run: |
mkdir -p ~/.cargo/{git,registry}
# Fix git permission issue with Docker and shadow-rs
sudo chown -R root .
docker run --rm -t \
--mount type=bind,source=${{ github.workspace }},target=/volume \
--mount type=bind,source=$HOME/.cargo/registry,target=/root/.cargo/registry \
Expand All @@ -44,7 +50,9 @@ jobs:
clux/muslrust:stable \
cargo build --release
sudo chown -R runner ~/.cargo/
sudo chown -R runner target/
sudo chown -R runner .
# show version info
RUST_LOG=debug target/x86_64-unknown-linux-musl/release/tsumugu --version
- name: Deploy - Create and Upload Release
if: startsWith(github.ref, 'refs/tags/')
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ humansize = "2.1.3"
console = { version = "0.15", default-features = false, features = ["ansi-parsing"] }
apt-parser = "1.0.0"
flate2 = "1.0.28"
shadow-rs = "0.26.1"
shadow-rs = "0.32.0"

[build-dependencies]
shadow-rs = "0.26.1"
shadow-rs = "0.32.0"

[dev-dependencies]
test-log = { version = "0.2.14", default-features = false, features = ["trace"] }
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ mod extensions;

use crate::regex_process::ExpandedRegex;

fn get_version() -> &'static str {
let tag = build::TAG;
let clean = build::GIT_CLEAN;
if !clean {
return Box::leak(format!("{} (dirty)", build::SHORT_COMMIT).into_boxed_str());
} else if tag.len() == 0 {
return build::SHORT_COMMIT;
} else {
return tag;
}
}

#[derive(Parser, Debug)]
#[command(about)]
#[command(propagate_version = true)]
#[command(version = build::SHORT_COMMIT)]
#[command(version = get_version())]
struct Cli {
#[command(subcommand)]
command: Commands,
Expand Down

0 comments on commit ee22a27

Please sign in to comment.