From fc1729df7db0e53ed8620859ed63aa04724451e1 Mon Sep 17 00:00:00 2001 From: Lkhsss Date: Sun, 17 Nov 2024 10:38:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=B0=91=E9=87=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 194 ++++++++++++++++++++++++------------ Cargo.lock | 2 +- Cargo.toml | 2 +- src/clap.rs | 2 +- src/main.rs | 3 +- 5 files changed, 133 insertions(+), 70 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a2c037..d4079a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,78 +1,140 @@ -name: build + +name: Release + on: push: - tags: - - "v*.*.*" - workflow_dispatch: {} + tags: + - v[0-9]+.[0-9]+.[0-9]+* + jobs: - build: - name: build - runs-on: ${{ matrix.os }} + release: + name: Publish to Github Releases + permissions: + contents: write + outputs: + rc: ${{ steps.check-tag.outputs.rc }} + strategy: matrix: - build: [linux, macos, windows] include: - - build: linux - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-musl - archive-name: ncmmiao-linux.tar.gz - - build: macos - os: macos-latest - rust: stable - target: x86_64-apple-darwin - archive-name: ncmmiao-macos.tar.gz - - build: windows - os: windows-latest - rust: stable-x86_64-msvc - target: x86_64-pc-windows-msvc - archive-name: ncmmiao-windows.7z - fail-fast: false + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + use-cross: true + cargo-flags: "" + - target: aarch64-apple-darwin + os: macos-latest + use-cross: true + cargo-flags: "" + - target: aarch64-pc-windows-msvc + os: windows-latest + use-cross: true + cargo-flags: "" + - target: x86_64-apple-darwin + os: macos-latest + cargo-flags: "" + - target: x86_64-pc-windows-msvc + os: windows-latest + cargo-flags: "" + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + use-cross: true + cargo-flags: "" + - target: i686-unknown-linux-musl + os: ubuntu-latest + use-cross: true + cargo-flags: "" + - target: i686-pc-windows-msvc + os: windows-latest + use-cross: true + cargo-flags: "" + - target: armv7-unknown-linux-musleabihf + os: ubuntu-latest + use-cross: true + cargo-flags: "" + - target: arm-unknown-linux-musleabihf + os: ubuntu-latest + use-cross: true + cargo-flags: "" + + runs-on: ${{matrix.os}} + env: + BUILD_CMD: cargo steps: - - name: Checkout repository - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v4 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - profile: minimal - override: true - components: rustfmt, clippy - target: ${{ matrix.target }} - - name: Test - run: cargo test + - name: Check Tag + id: check-tag + shell: bash + run: | + ver=${GITHUB_REF##*/} + echo "version=$ver" >> $GITHUB_OUTPUT + if [[ "$ver" =~ [0-9]+.[0-9]+.[0-9]+$ ]]; then + echo "rc=false" >> $GITHUB_OUTPUT + else + echo "rc=true" >> $GITHUB_OUTPUT + fi + - name: Install Rust Toolchain Components + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} - - name: Build binary - run: cargo build --verbose --release --target ${{ matrix.target }} - env: - RUST_BACKTRACE: 1 + - name: Install cross + if: matrix.use-cross + uses: taiki-e/install-action@v2 + with: + tool: cross - - name: Strip binary (linux and macos) - if: matrix.build == 'linux' || matrix.build == 'macos' - run: strip "target/${{ matrix.target }}/release/ncmmiao" + - name: Overwrite build command env variable + if: matrix.use-cross + shell: bash + run: echo "BUILD_CMD=cross" >> $GITHUB_ENV + + - name: Show Version Information (Rust, cargo, GCC) + shell: bash + run: | + gcc --version || true + rustup -V + rustup toolchain list + rustup default + cargo -V + rustc -V + + - name: Build + shell: bash + run: $BUILD_CMD build --locked --release --target=${{ matrix.target }} ${{ matrix.cargo-flags }} - - name: Build archive - shell: bash - run: | - mkdir archive - # cp LICENSE README.md archive/ - cp README.md archive/ - cd archive - if [ "${{ matrix.build }}" = "windows" ]; then - cp "../target/${{ matrix.target }}/release/ncmmiao.exe" ./ - # 7z a "${{ matrix.archive-name }}" LICENSE README.md ncmmiao.exe - 7z a "${{ matrix.archive-name }}" README.md ncmmiao.exe - else - cp "../target/${{ matrix.target }}/release/ncmmiao" ./ - # tar -czf "${{ matrix.archive-name }}" LICENSE README.md ncmmiao - tar -czf "${{ matrix.archive-name }}" README.md ncmmiao - fi - - name: Release archive - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') - with: - # name: ${{ matrix.archive-name }} - files: archive/${{ matrix.archive-name }} - token: ${{ secrets.TOKEN }} + - name: Build Archive + shell: bash + id: package + env: + target: ${{ matrix.target }} + version: ${{ steps.check-tag.outputs.version }} + run: | + set -euxo pipefail + bin=${GITHUB_REPOSITORY##*/} + dist_dir=`pwd`/dist + name=$bin-$version-$target + executable=target/$target/release/$bin + if [[ "$RUNNER_OS" == "Windows" ]]; then + executable=$executable.exe + fi + mkdir $dist_dir + cp $executable $dist_dir + cd $dist_dir + if [[ "$RUNNER_OS" == "Windows" ]]; then + archive=$dist_dir/$name.zip + 7z a $archive * + echo "archive=dist/$name.zip" >> $GITHUB_OUTPUT + else + archive=$dist_dir/$name.tar.gz + tar -czf $archive * + echo "archive=dist/$name.tar.gz" >> $GITHUB_OUTPUT + fi + - name: Publish Archive + uses: softprops/action-gh-release@v2 + if: ${{ startsWith(github.ref, 'refs/tags/') }} + with: + draft: false + files: ${{ steps.package.outputs.archive }} + prerelease: ${{ steps.check-tag.outputs.rc == 'true' }} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3448134..4d6e084 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -799,7 +799,7 @@ checksum = "07dcca13d1740c0a665f77104803360da0bdb3323ecce2e93fa2c959a6d52806" [[package]] name = "ncmmiao" -version = "2.2.5" +version = "2.2.6" dependencies = [ "aes", "audiotags", diff --git a/Cargo.toml b/Cargo.toml index ac5f217..674c6ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ncmmiao" -version = "2.2.5" +version = "2.2.6" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/clap.rs b/src/clap.rs index fbe7d3b..53e9cd8 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -5,7 +5,7 @@ use clap::Parser; #[command(author = "lkhsss")] #[command(version,about = "一个解密ncm文件的神秘程序", long_about = None)] pub struct Cli { - /// 最大线程数 约束逻辑在主函数 + /// 并发的最大线程数,默认为4线程 #[arg(short, long)] pub workers: Option, /// 需要解密的文件夹或文件 diff --git a/src/main.rs b/src/main.rs index e095077..c799105 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,10 +71,11 @@ fn main() { } let taskcount = undumpfile.len(); if taskcount == 0 { - error!("没有找到有效文件") + error!("没有找到有效文件。使用-i参数输入需要解密的文件或文件夹。") } else { // 初始化线程池 let pool = threadpool::Pool::new(max_workers); + info!("启用{}线程",max_workers); for filepath in undumpfile { let output = outputdir.clone();