From f7a42dd12a50ed818a7e068bb9677acc8926003f Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 11 Jul 2024 12:43:37 +0700 Subject: [PATCH] enhance ci build and upload artifact per commit upload release asset merge nightly release to ci.yml --- .github/workflows/ci.yml | 121 +++++++++++++++++++++-- .github/workflows/nightly-release.yml | 135 -------------------------- 2 files changed, 114 insertions(+), 142 deletions(-) delete mode 100644 .github/workflows/nightly-release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a16770f..7c49031 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,26 +2,133 @@ name: Build and Test on: push: - branches: [ "main" ] pull_request: branches: [ "main" ] + workflow_dispatch: + release: + types: + - created + schedule: # Every day at the 2 P.M. (UTC) we run a scheduled nightly build + - cron: "0 14 * * *" env: CARGO_TERM_COLOR: always +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + jobs: build: - - runs-on: ubuntu-latest + name: build (${{ matrix.config.arch }}) + strategy: + matrix: + config: + - os: windows-latest + arch: win-x64 + - os: windows-latest + arch: win-x86 + - os: ubuntu-latest + arch: linux-x64 + - os: macos-latest + arch: macos-arm64 + - os: macos-12 + arch: macos-x64 + runs-on: ${{ matrix.config.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install libudev for Linux if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y libudev-dev + - name: Set target + run: | + if [[ "${{ matrix.config.arch }}" == "win-x86" ]]; then + echo TARGET="--target i686-pc-windows-msvc" >> $GITHUB_ENV + else + echo TARGET="" >> $GITHUB_ENV + fi + shell: bash - name: Build - run: cargo build --verbose + run: cargo build --release ${{ env.TARGET }} - name: Run tests - run: cargo test --verbose + run: cargo test --release ${{ env.TARGET }} --verbose - name: Run help - run: cargo run -- --help + run: cargo run --release ${{ env.TARGET }} -- --help + + - name: Prepare artifacts + run: | + if [[ "${{ matrix.config.arch }}" == "win-x64" ]]; then + WLINK_EXE="target/release/wlink.exe" + elif [[ "${{ matrix.config.arch }}" == "win-x86" ]]; then + WLINK_EXE="target/i686-pc-windows-msvc/release/wlink.exe" + else + WLINK_EXE="target/release/wlink" + fi + + mkdir wlink-${{ matrix.config.arch }} + cp $WLINK_EXE wlink-${{ matrix.config.arch }} + cp README.md wlink-${{ matrix.config.arch }} + shell: bash + - uses: actions/upload-artifact@v4 + with: + name: wlink-${{ matrix.config.arch }} + path: wlink-${{ matrix.config.arch }} + + - name: Prepare Release Asset + if: github.event_name == 'release' + run: | + if [[ "${{ runner.os }}" == "Windows" ]]; then + 7z a -tzip wlink-${{ github.event.release.tag_name }}-${{ matrix.config.arch }}.zip wlink-${{ matrix.config.arch }} + else + tar -czvf wlink-${{ github.event.release.tag_name }}-${{ matrix.config.arch }}.tar.gz wlink-${{ matrix.config.arch }} + fi + shell: bash + - name: Upload Release Asset + uses: softprops/action-gh-release@v2 + if: github.event_name == 'release' + with: + fail_on_unmatched_files: false + files: | + wlink-*.tar.gz + wlink-*.zip + + nightly-release: + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'schedule' + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: ./ + + - name: Prepare Nightly Asset + run: | + ls -R ./ + for f in wlink-*; do + echo "Compressing $f" + if [[ $f == wlink-win* ]]; then + zip -r $f.zip $f + else + tar -czvf $f.tar.gz $f + fi + done + ls ./ + + - name: Update Nightly Release + uses: andelf/nightly-release@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: nightly + name: "wlink nightly release $$" + draft: false + prerelease: true + body: | + This is a nightly binary release of the wlink command line tool. + + For Windows users, please use the x86 version since it has the Windows driver support. + files: | + wlink-*.tar.gz + wlink-*.zip diff --git a/.github/workflows/nightly-release.yml b/.github/workflows/nightly-release.yml deleted file mode 100644 index 5187428..0000000 --- a/.github/workflows/nightly-release.yml +++ /dev/null @@ -1,135 +0,0 @@ -name: Nightly Release - -on: - workflow_dispatch: - schedule: # Every day at the 2 P.M. (UTC) we run a scheduled nightly build - - cron: "0 14 * * *" - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - name: build (${{ matrix.config.arch }}) - strategy: - matrix: - config: - - os: windows-latest - arch: win-x64 - - os: ubuntu-latest - arch: linux-x64 - - os: macos-latest - arch: macos-x64 - runs-on: ${{ matrix.config.os }} - - steps: - - uses: actions/checkout@v3 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - components: rustfmt, clippy - override: true - - name: Install libudev for Linux (optional) - if: runner.os == 'Linux' - run: sudo apt-get install libudev-dev - - name: Build - run: cargo build --release - - name: Run help - run: cargo run --release -- --help - - name: Compress binary - run: | - mkdir -p release - cp target/release/wlink release/ || true - cp target/release/wlink.exe release/ || true - cp README.md release/ - (cd release/ && tar -czvf ../wlink-${{ matrix.config.arch }}.tar.gz *) - shell: bash - - uses: actions/upload-artifact@v3 - with: - name: wlink-binaries - path: wlink-${{ matrix.config.arch }}.tar.gz - - build-win-x86: - name: build (windows-x86) - runs-on: windows-latest - steps: - - uses: actions/checkout@v3 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: i686-pc-windows-msvc - components: rustfmt, clippy - override: true - - name: Build - run: cargo build --release --target i686-pc-windows-msvc - - name: Compress binary - run: | - mkdir -p release - cp target/i686-pc-windows-msvc/release/wlink.exe release/ - cp README.md release/ - (cd release/ && tar -czvf ../wlink-win-x86.tar.gz *) - - uses: actions/upload-artifact@v3 - with: - name: wlink-binaries - path: wlink-win-x86.tar.gz - - build-macos-arm64: - name: build (macos-arm64) - runs-on: macos-latest - steps: - - uses: actions/checkout@v3 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - target: aarch64-apple-darwin - components: rustfmt, clippy - override: true - - name: Build - run: cargo build --release --target aarch64-apple-darwin - - name: Compress binary - run: | - mkdir -p release - cp target/aarch64-apple-darwin/release/wlink release/ - cp README.md release/ - (cd release/ && tar -czvf ../wlink-macos-arm64.tar.gz *) - - uses: actions/upload-artifact@v3 - with: - name: wlink-binaries - path: wlink-macos-arm64.tar.gz - - release: - needs: [build, build-macos-arm64, build-win-x86] - runs-on: ubuntu-22.04 - steps: - - name: Download Artifacts - uses: actions/download-artifact@v3 - with: - name: wlink-binaries - path: ./ - - - name: List files - run: ls -R ./ - shell: bash - - - name: Update Nightly Release - uses: andelf/nightly-release@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: nightly - name: "wlink Nightly Release $$" - draft: false - prerelease: false - body: | - This is a nightly binary release of the wlink command line tool. - - For Windows users, please use the x86 version since it has the Windows driver support. - - files: | - wlink-*.tar.gz