From e971b462c47441cfb6d2e66e0694a1d9f97a8429 Mon Sep 17 00:00:00 2001 From: djkato Date: Thu, 8 Sep 2022 21:07:25 +0200 Subject: [PATCH] Update rust.yml --- .github/workflows/rust.yml | 302 ++++++++++++++++++++++++++++++------- 1 file changed, 250 insertions(+), 52 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 190a08f..e5f3df3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,79 +1,277 @@ -# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md -# -# While our "example" application has the platform-specific code, -# for simplicity we are compiling and testing everything on the Ubuntu environment only. -# For multi-OS testing see the `cross.yml` workflow. - -on: [push, pull_request] - -name: Quickstart - +'on': + push: + branches: + - '*' + pull_request: null jobs: check: - name: Check - runs-on: windows-latest + runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: '${{ runner.os }}-cargo-registry-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: '${{ runner.os }}-cargo-index-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - - - name: Run cargo check - uses: actions-rs/cargo@v1 - continue-on-error: true # WARNING: only for this example, remove it! + - uses: actions-rs/cargo@v1 with: command: check - test: - name: Test Suite - runs-on: windows-latest + runs-on: '${{ matrix.os }}' + strategy: + matrix: + include: + - os: macos-latest + - os: ubuntu-latest + - os: windows-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: '${{ runner.os }}-cargo-registry-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: '${{ runner.os }}-cargo-index-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - - - name: Run cargo test - uses: actions-rs/cargo@v1 - continue-on-error: true # WARNING: only for this example, remove it! + - uses: actions-rs/cargo@v1 with: command: test - + - uses: actions-rs/cargo@v1 + with: + command: run + args: '-- -h' lints: - name: Lints - runs-on: windows-latest + runs-on: ubuntu-latest steps: - - name: Checkout sources - uses: actions/checkout@v2 - - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: '${{ runner.os }}-cargo-registry-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: '${{ runner.os }}-cargo-index-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - components: rustfmt, clippy - - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - continue-on-error: true # WARNING: only for this example, remove it! + components: 'rustfmt, clippy' + - uses: actions-rs/cargo@v1 with: command: fmt - args: --all -- --check - - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - continue-on-error: true # WARNING: only for this example, remove it! + args: '--all -- --check' + - uses: actions-rs/cargo@v1 with: command: clippy - args: -- -D warnings + args: '-- -D warnings' + version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + lfs: true + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - id: get_previous_version + run: echo ::set-output name=PREVIOUS_VERSION::$(git describe --tags "$(git rev-list --tags --max-count=1)") + shell: bash + - id: semvers + uses: WyriHaximus/github-action-next-semvers@master + with: + version: '${{ steps.get_previous_version.outputs.PREVIOUS_VERSION }}' + - run: mkdir -p ./version + - if: "!contains(github.event.head_commit.message, 'BC BREAK') && !contains(github.event.head_commit.message, 'Signed-off-by: dependabot-preview[bot] ')" + run: echo "$VERSION" >./version/version + env: + VERSION: ${{ steps.semvers.outputs.v_minor }} + - if: "contains(github.event.head_commit.message, 'Signed-off-by: dependabot-preview[bot] ')" + run: echo "$VERSION" >./version/version + env: + VERSION: ${{ steps.semvers.outputs.v_patch }} + - run: echo "$VERSION" > ./version/version + env: + VERSION: ${{ steps.semvers.outputs.v_major }} + if: "contains(github.event.head_commit.message, 'BC BREAK')" + - uses: actions/upload-artifact@master + with: + name: version + path: ./version/version + build: + needs: + - version + - lints + - test + - check + runs-on: '${{ matrix.os }}' + strategy: + matrix: + include: + - os: macos-latest + target: x86_64-apple-darwin + suffix: '' + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + suffix: '' + - os: windows-latest + target: x86_64-pc-windows-msvc + suffix: .exe + steps: + - uses: actions/checkout@master + with: + lfs: true + - id: get_repository_name + run: echo ::set-output name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") + shell: bash + - uses: actions/download-artifact@master + with: + name: version + - id: get_version + run: 'echo ::set-output "name=VERSION::$(cat ./version/version)"' + shell: bash + - uses: actions/cache@v1 + with: + path: ~/.cargo/registry + key: '${{ runner.os }}-cargo-registry-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: '${{ runner.os }}-cargo-index-${{ hashFiles(''**/Cargo.lock'') }}' + - uses: actions/cache@v1 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: install + args: 'toml-cli' + - shell: bash + env: + VERSION: '${{ steps.get_version.outputs.VERSION }}' + run: | + TEMP_FILE="$(mktemp)" + toml set Cargo.toml package.version "${VERSION:1}" > "$TEMP_FILE" + mv "$TEMP_FILE" Cargo.toml + - uses: actions-rs/cargo@v1 + env: + VERSION: '${{ steps.get_version.outputs.VERSION }}' + REPOSITORY_NAME: '${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}' + with: + command: build + args: '--release' + - uses: actions/upload-artifact@master + with: + name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-${{ matrix.target }} + path: ./target/release/${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}${{ matrix.suffix }} + release: + if: github.ref == 'refs/heads/master' + needs: + - build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + with: + lfs: true + - id: get_repository_name + run: echo ::set-output name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") + shell: bash + - uses: actions/download-artifact@master + with: + name: version + - id: get_version + run: 'echo ::set-output name=VERSION::$(cat ./version/version)' + shell: bash + - uses: actions/download-artifact@master + with: + name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-unknown-linux-gnu + - uses: actions/download-artifact@master + with: + name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-apple-darwin + - uses: actions/download-artifact@master + with: + name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-pc-windows-msvc + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: actions-rs/cargo@v1 + with: + command: install + args: 'toml-cli' + - run: | + TEMP_FILE="$(mktemp)" + toml set Cargo.toml package.version "${VERSION:1}" > "$TEMP_FILE" + mv "$TEMP_FILE" Cargo.toml + shell: bash + env: + VERSION: '${{ steps.get_version.outputs.VERSION }}' + - uses: stefanzweifel/git-auto-commit-action@v4.1.3 + with: + commit_message: Bump cargo version + branch: ${{ github.head_ref }} + file_pattern: Cargo.toml + - id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: '${{ secrets.COMMITTER_TOKEN }}' + with: + tag_name: '${{ steps.get_version.outputs.VERSION }}' + release_name: 'Release ${{ steps.get_version.outputs.VERSION }}' + draft: false + prerelease: false + - uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + with: + upload_url: '${{ steps.create_release.outputs.upload_url }}' + asset_path: ./${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-unknown-linux-gnu/${{ steps.get_repository_name.outputs.REPOSITORY_NAME }} + asset_name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-unknown-linux-gnu + asset_content_type: application/octet-stream + - uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + with: + upload_url: '${{ steps.create_release.outputs.upload_url }}' + asset_path: ./${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-apple-darwin/${{ steps.get_repository_name.outputs.REPOSITORY_NAME }} + asset_name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-apple-darwin + asset_content_type: application/octet-stream + - uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + with: + upload_url: '${{ steps.create_release.outputs.upload_url }}' + asset_path: ./${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-pc-windows-msvc/${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}.exe + asset_name: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-x86_64-pc-windows-msvc.exe + asset_content_type: application/octet-stream