diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..0ae0af6 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,68 @@ +name: Build + +on: + workflow_dispatch: + workflow_call: + + push: + branches: + - "*" + + pull_request: + branches: + - "*" + +jobs: + build: + name: Build (${{ matrix.type }}) + runs-on: windows-latest + strategy: + matrix: + include: + - type: debug + args: "" + artifacts: | + target/debug/*.exe + target/debug/*.pdb + + - type: release + args: --release + artifacts: | + target/release/*.exe + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Build Cache + uses: actions/cache@v4 + id: build-cache + with: + path: | + target/*/*.exe + target/*/*.pdb + key: windows-latest-${{ matrix.type }}-${{ hashFiles('./Cargo.*', './*.rs', 'img/*', 'img/**/*', 'resources/*', 'resources/**/*', 'src/*', 'src/**/*') }} + + - name: Cargo Cache + uses: actions/cache@v4 + if: ${{ steps.build-cache.outputs.cache-hit != 'true' }} + with: + path: | + ~/.cargo/ + target/ + key: windows-latest-${{ matrix.type }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: windows-latest-${{ matrix.type }}-cargo- + + - name: Cargo Build + if: ${{ steps.build-cache.outputs.cache-hit != 'true' }} + uses: actions-rs/cargo@v1 + with: + command: build + args: ${{ matrix.args }} + + - name: Artifact Upload + uses: actions/upload-artifact@v4 + with: + name: wsl-usb-manager-${{ matrix.type }} + path: ${{ matrix.artifacts }} + if-no-files-found: error diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..93bd826 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,52 @@ +name: Release + +on: + release: + types: published + +jobs: + build: + uses: ./.github/workflows/build.yaml + + release: + runs-on: ubuntu-latest + needs: build + permissions: + contents: write + + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + pattern: '*-release' + path: artifacts + + - name: Release Artifact Upload + uses: softprops/action-gh-release@v2 + with: + files: artifacts/**/* + + winget: + runs-on: ubuntu-latest + needs: release + + steps: + - name: Check if WINGET_TOKEN is present + id: check_secret + run: | + if [ -z "${{ secrets.WINGET_TOKEN }}" ]; then + echo "WINGET_TOKEN is not set" + echo "winget_token_present=false" >> $GITHUB_ENV + else + echo "WINGET_TOKEN is present" + echo "winget_token_present=true" >> $GITHUB_ENV + fi + - name: Submit to winget + id: winget_deploy + uses: vedantmgoyal9/winget-releaser@main + if: env.winget_token_present == 'true' + with: + identifier: nickbeth.wsl-usb-manager + installers-regex: '\.exe$' + fork-user: ${{ secrets.WINGET_FORK_USER }} + token: ${{ secrets.WINGET_TOKEN }} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index cee674d..74056b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,11 @@ authors = ["Niccolò Betto "] edition = "2021" license = "MIT" +[profile.release] +strip = true # Automatically strip symbols from the binary. +lto = true # Enable link time optimization. +codegen-units = 1 # Limit codegen units to 1 for better optimization. + [dependencies] windows-sys = { version = "0.52.0", features = [ "Win32_Devices_DeviceAndDriverInstallation",