From b5dd0b32913f41e7b5996f7e2064f0f24293c388 Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Wed, 21 Sep 2022 16:28:47 +0200 Subject: [PATCH] ci: rewrite Rewrite github actions inspirated from https://github.com/ClementTsang/bottom/tree/3d2c40ce2f999e2d25030014cfae745591fd9d5e/.github/workflows --- ...release-binaries.yml => build-release.yml} | 49 +++------ .github/workflows/ci.yml | 101 ++++++++++++++++++ .github/workflows/nightly.yml | 53 +++++++++ .github/workflows/rust.yml | 63 ----------- 4 files changed, 171 insertions(+), 95 deletions(-) rename .github/workflows/{build-release-binaries.yml => build-release.yml} (70%) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/nightly.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/build-release-binaries.yml b/.github/workflows/build-release.yml similarity index 70% rename from .github/workflows/build-release-binaries.yml rename to .github/workflows/build-release.yml index 7caaa54..67c92f1 100644 --- a/.github/workflows/build-release-binaries.yml +++ b/.github/workflows/build-release.yml @@ -1,13 +1,8 @@ -name: Build release binaries (and publish them if this is a tag) +name: Build release binaries on: - push: - tags: - - "*" - - # pull_request: - workflow_dispatch: + workflow_call: env: CARGO_TERM_COLOR: always @@ -29,7 +24,7 @@ jobs: include: - os: ubuntu-latest target: x86_64-unknown-linux-musl - artifact_name: target/x86_64-unknown-linux-musl/release/homedisk + artifact_path: target/x86_64-unknown-linux-musl/release/homedisk release_name: x86_64-unknown-linux-musl cross: true strip: true @@ -37,7 +32,7 @@ jobs: - os: ubuntu-latest target: armv7-unknown-linux-musleabihf - artifact_name: target/armv7-unknown-linux-musleabihf/release/homedisk + artifact_path: target/armv7-unknown-linux-musleabihf/release/homedisk release_name: armv7-unknown-linux-musleabihf cross: true strip: false @@ -45,7 +40,7 @@ jobs: - os: ubuntu-latest target: aarch64-unknown-linux-musl - artifact_name: target/aarch64-unknown-linux-musl/release/homedisk + artifact_path: target/aarch64-unknown-linux-musl/release/homedisk release_name: aarch64-unknown-linux-musl cross: true strip: false @@ -53,7 +48,7 @@ jobs: - os: windows-latest target: x86_64-pc-windows-msvc - artifact_name: target/x86_64-pc-windows-msvc/release/homedisk.exe + artifact_path: target/x86_64-pc-windows-msvc/release/homedisk.exe release_name: x86_64-pc-windows-msvc.exe cross: false strip: true @@ -61,7 +56,7 @@ jobs: - os: macos-latest target: x86_64-apple-darwin - artifact_name: target/x86_64-apple-darwin/release/homedisk + artifact_path: target/x86_64-apple-darwin/release/homedisk release_name: x86_64-apple-darwin cross: false strip: true @@ -69,7 +64,7 @@ jobs: - os: macos-latest target: aarch64-apple-darwin - artifact_name: target/aarch64-apple-darwin/release/homedisk + artifact_path: target/aarch64-apple-darwin/release/homedisk release_name: aarch64-apple-darwin cross: false strip: true @@ -102,27 +97,17 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - args: --release --target=${{ matrix.target }} ${{ matrix.cargo_flags }} + args: --release --target=${{ matrix.target }} ${{ matrix.release_name }} use-cross: ${{ matrix.cross }} + - name: Prepare artifact + shell: bash + run: | + mkdir release + mv ${{ matrix.artifact_path }} release/${{ matrix.artifact_path }} + - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: ${{ matrix.target }} - path: ${{ matrix.artifact_name }} - - - name: Get tag name - id: tag_name - run: | - echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} - shell: bash - if: startsWith(github.ref, 'refs/tags/v') - - - name: Publish - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ${{ matrix.artifact_name }} - tag: ${{ github.ref }} - asset_name: cloud-$tag-${{ matrix.release_name }} - if: startsWith(github.ref, 'refs/tags/v') + name: release-${{ matrix.target }} + path: ./release/* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4fb78a4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,101 @@ +name: Build release binaries (and publish them if this is a tag) + +on: + push: + tags: + - "*" + + # pull_request: + + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build-release: + uses: ./.github/workflows/build_releases.yml + + clippy-and-tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + rust: [stable, nightly] + + name: ${{ matrix.rust }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Rust toolchain + id: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + components: clippy + + - name: Cache + uses: actions/cache@v3 + id: cache + with: + path: | + ~/.cargo/registry/cache/ + target/ + key: clippy-test-${{ runner.os }}-${{ matrix.rust }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }} + + - name: cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --no-deps -- -D warnings + + - name: cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features + + upload-release: + runs-on: ubuntu-latest + needs: [build-release] + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: ./ + + - name: Move artifacts + run: | + mkdir release + mv release-*/* release/ + + - name: Get tag name + id: tag_name + run: | + echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v} + + - name: Upload release files + uses: softprops/action-gh-release@17cd0d34deddf848fc0e7d9be5202c148c270a0a # 0.1.14 + with: + token: ${{ secrets.GITHUB_TOKEN }} + prerelease: false + tag_name: ${{ github.ref }} + draft: true + fail_on_unmatched_files: true + name: ${{ github.ref }} Release + body: | + + --- + ## Features + ## Changes + ## Bug Fixes + ## Internal Changes + files: | + ./release/* diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000..d63dd01 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,53 @@ +name: Nightly + +on: + schedule: + - cron: "0 0 * * *" + + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build-release: + uses: ./.github/workflows/build_releases.yml + + upload-release: + runs-on: ubuntu-latest + needs: [build-release] + + steps: + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: ./ + + - name: Move artifacts + run: | + mkdir release + mv release-*/* release/ + echo "Generated $(ls ./release | wc -l) files:" + du -h -d 0 ./release/* + + - name: Delete tag and release + uses: dev-drprasad/delete-tag-and-release@085c6969f18bad0de1b9f3fe6692a3cd01f64fe5 # 0.2.0 + with: + delete_release: true + tag_name: nightly + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Sleep for a few seconds to prevent timing issues between the deletion and creation of the release + run: sleep 10 + + - name: Upload all release files + uses: softprops/action-gh-release@17cd0d34deddf848fc0e7d9be5202c148c270a0a # 0.1.14 + with: + token: ${{ secrets.GITHUB_TOKEN }} + prerelease: true + tag_name: "nightly" + draft: false + fail_on_unmatched_files: true + files: | + ./release/* diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 8e91dec..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Rust - -on: - push: - branches: - - main - - pull_request: - - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - rust: [stable, nightly] - - name: ${{ matrix.rust }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Rust toolchain - id: rust-toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.rust }} - override: true - components: clippy - - - name: Cache - uses: actions/cache@v3 - id: cache - with: - path: | - ~/.cargo/registry/cache/ - target/ - key: ${{ runner.os }}-${{ matrix.rust }}-${{ steps.rust-toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }} - - - name: cargo build - uses: actions-rs/cargo@v1 - with: - command: build - - - name: cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --no-deps -- -D warnings - - - name: cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features