From b98313b74faa883360825a5719e93d921de8904e Mon Sep 17 00:00:00 2001 From: neuecc Date: Sun, 16 Apr 2023 01:27:25 +0900 Subject: [PATCH] test CI run --- .github/workflows/build-debug.yml | 1 + .github/workflows/build-release.yml | 105 ++++++++++++++++++++++++++++ csbindgen/src/lib.rs | 60 ++++++++++++---- 3 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build-release.yml diff --git a/.github/workflows/build-debug.yml b/.github/workflows/build-debug.yml index 8b390a8..9b8da81 100644 --- a/.github/workflows/build-debug.yml +++ b/.github/workflows/build-debug.yml @@ -16,6 +16,7 @@ jobs: steps: - uses: actions/checkout@v3 - run: cargo build --verbose + - run: cargo test update_package_version -- 1.0.0 --nocapture build-dotnet: runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 0000000..2f643f2 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,105 @@ +name: Build-Release + +on: + workflow_dispatch: + inputs: + tag: + description: "tag: git tag you want create. (sample 1.0.0)" + required: true + dry-run: + description: "dry-run: false = create release/nuget. true = never create release/nuget." + required: true + default: false + type: boolean + +jobs: + update-packagejson: + uses: Cysharp/Actions/.github/workflows/update-packagejson.yaml@main + with: + file-path: ./src/MemoryPack.Unity/Assets/Plugins/MemoryPack/package.json + tag: ${{ inputs.tag }} + dry-run: ${{ inputs.dry-run }} + push-tag: false + + build-dotnet: + needs: [update-packagejson] + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - run: echo ${{ needs.update-packagejson.outputs.sha }} + - uses: actions/checkout@v3 + with: + ref: ${{ needs.update-packagejson.outputs.sha }} + - uses: Cysharp/Actions/.github/actions/setup-dotnet@main + with: + dotnet-version: | + 6.0.x + 7.0.x + # pack nuget + - run: dotnet build -c Release -p:Version=${{ inputs.tag }} + - run: dotnet test -c Release --no-build + - run: dotnet pack -c Release --no-build -p:Version=${{ inputs.tag }} -o ./publish + - uses: actions/upload-artifact@v3 + with: + name: nuget + path: ./publish + + build-unity: + needs: [update-packagejson] + strategy: + matrix: + unity: ["2021.3.11f1"] + include: + - unity: 2021.3.11f1 + license: UNITY_LICENSE_2021 + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - run: echo ${{ needs.update-packagejson.outputs.sha }} + - uses: actions/checkout@v3 + with: + ref: ${{ needs.update-packagejson.outputs.sha }} + # Execute scripts: Export Package + # /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export + - name: Export unitypackage + uses: game-ci/unity-builder@v2 + env: + UNITY_LICENSE: ${{ secrets[matrix.license] }} + with: + projectPath: src/MemoryPack.Unity + unityVersion: ${{ matrix.unity }} + targetPlatform: StandaloneLinux64 + buildMethod: PackageExporter.Export + versioning: None + # check meta files + - uses: Cysharp/Actions/.github/actions/check-metas@main + with: + directory: src/MemoryPack.Unity + # Store artifacts. + - uses: actions/upload-artifact@v3 + with: + name: MemoryPack.${{ inputs.tag }}.unitypackage + path: ./src/MemoryPack.Unity/MemoryPack.${{ inputs.tag }}.unitypackage + if-no-files-found: error + + # release + create-release: + needs: [update-packagejson, build-dotnet, build-unity] + uses: Cysharp/Actions/.github/workflows/create-release.yaml@main + with: + dry-run: ${{ inputs.dry-run }} + commit-id: ${{ needs.update-packagejson.outputs.sha }} + tag: ${{ inputs.tag }} + push-tag: true + nuget-push: true + unitypackage-upload: true + unitypackage-name: MemoryPack.${{ inputs.tag }}.unitypackage + unitypackage-path: ./MemoryPack.${{ inputs.tag }}.unitypackage/MemoryPack.${{ inputs.tag }}.unitypackage + secrets: inherit + + cleanup: + if: needs.update-packagejson.outputs.is-branch-created == 'true' + needs: [update-packagejson, create-release] + uses: Cysharp/Actions/.github/workflows/clean-packagejson-branch.yaml@main + with: + branch: ${{ needs.update-packagejson.outputs.branch-name }} diff --git a/csbindgen/src/lib.rs b/csbindgen/src/lib.rs index e5a3233..331ce21 100644 --- a/csbindgen/src/lib.rs +++ b/csbindgen/src/lib.rs @@ -136,18 +136,52 @@ fn collect_field_types( } } -#[test] -fn test() { - let path = std::env::current_dir().unwrap(); - println!("starting dir: {}", path.display()); // csbindgen/csbindgen +#[cfg(test)] +mod tests { + use std::{ + env, + fs::{self}, + }; - Builder::new() - .input_bindgen_file("csbindgen-tests/src/liblz4.rs") - .csharp_class_name("LibLz4") - .csharp_dll_name("csbindgen_tests") - .generate_to_file( - "csbindgen-tests/src/lz4_ffi.rs", - "dotnet-sandbox/lz4_bindgen.cs", - ) - .unwrap(); + use super::*; + + #[test] + fn test() { + let path = std::env::current_dir().unwrap(); + println!("starting dir: {}", path.display()); // csbindgen/csbindgen + + Builder::new() + .input_bindgen_file("csbindgen-tests/src/liblz4.rs") + .csharp_class_name("LibLz4") + .csharp_dll_name("csbindgen_tests") + .generate_to_file( + "csbindgen-tests/src/lz4_ffi.rs", + "dotnet-sandbox/lz4_bindgen.cs", + ) + .unwrap(); + } + + // cargo test update_package_version -- 1.0.0 --nocapture + #[test] + fn update_package_version() { + let args: Vec = env::args().collect(); + // 0: exe path + // 1: update_package_version + // 2: 1.0.0 + // 3: --nocapture + + if args[1] != "update_package_version" { + return; + } + + println!("version: {}", args[2]); + let mut path = std::env::current_dir().unwrap(); + println!("current_dir: {}", path.display()); + + path.push("Cargo.toml"); + + let toml = fs::read_to_string(path).unwrap(); + + println!("current toml: {}", toml); + } }