From 2ff3d872e501e2dc92df578d2760d731e4be0e1e Mon Sep 17 00:00:00 2001 From: AmeKnite <104745335+ameknite@users.noreply.github.com> Date: Fri, 15 Mar 2024 22:05:57 -0600 Subject: [PATCH] update and clean up ci --- .github/dependabot.yaml | 15 ++++- .github/workflows/add_notice.yaml | 71 +++++++++++++++++++--- .github/workflows/auto_merge.yaml | 2 +- .github/workflows/build_and_release.yaml | 65 +++++++++++++++----- .github/workflows/bump_version.yaml | 4 +- .github/workflows/cargo_deny.yaml | 13 ++-- .github/workflows/cargo_semver_checks.yaml | 44 ++++++++++---- .github/workflows/ci.yaml | 21 ++++--- .github/workflows/msrv.yaml | 29 ++++----- .github/workflows/pre_release.yaml | 13 ++-- .github/workflows/publish.yaml | 19 ++++++ .github/workflows/update_attributions.yaml | 12 ++-- .github/workflows/weekly.yaml | 9 ++- 13 files changed, 226 insertions(+), 91 deletions(-) diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 0e698cc..09f4923 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -12,10 +12,23 @@ updates: patterns: - "*" update-types: - - "minor" - "patch" + minor-updates: + patterns: + - "*" + update-types: + - "minor" + major-updates: + patterns: + - "*" + update-types: + - "major" - package-ecosystem: github-actions directory: / schedule: interval: weekly + groups: + github-actions-updates: + patterns: + - "*" diff --git a/.github/workflows/add_notice.yaml b/.github/workflows/add_notice.yaml index 2afaa26..7b83152 100644 --- a/.github/workflows/add_notice.yaml +++ b/.github/workflows/add_notice.yaml @@ -1,17 +1,65 @@ -name: Publish +name: Add Notice + +permissions: + contents: write on: workflow_call: inputs: message: type: string + description: Replace notice with this message + notice_path: + type: string + description: Path to the notice file + extensions: + type: string + description: Apply notice by extensions, e.g. rs,js,kt. + comment_styles: + type: string + description: Comment Styles, e.g. //,#,// + commit_message: + type: string workflow_dispatch: - + inputs: + message: + type: string + description: Replace notice with this message + notice_path: + type: string + description: Path to the notice file + extensions: + type: string + description: Apply notice by extensions, e.g. rs,js,kt. + comment_styles: + type: string + description: Comment Styles, e.g. //,#,// jobs: + check-notice-existence: + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: "Check file existence" + id: check-files + uses: andstor/file-existence-action@v3 + with: + files: ${{ inputs.notice_path || './NOTICE' }} + + - name: print if skip add-notice + if: steps.check-files.outputs.files_exists + run: echo "add-notice needs a ${{ inputs.notice_path || './NOTICE'}} file" + + outputs: + notice_exist: ${{ steps.check-files.outputs.files_exists }} + add-notice: + needs: check-notice-existence + if: ${{ needs.check-notice-existence.outputs.notice_exist == 'true'}} runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -20,15 +68,20 @@ jobs: - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install cargo-attribution + - name: Install add-notice uses: taiki-e/install-action@v2 with: - tool: add-header + tool: add-notice + + - name: Run add-notice + if: ${{ inputs.message == '' }} + run: add-notice --notice ${{ inputs.notice_path || './NOTICE' }} -e ${{ inputs.extensions || 'rs' }} -c ${{ inputs.comment_styles || '//' }} - - name: Run cargo attribution - run: add-header + - name: Replace notice + if: ${{ inputs.message }} + run: add-notice --notice ${{ inputs.notice_path || './NOTICE' }} --replace-with-string ${{ inputs.message }} -e ${{ inputs.extensions || 'rs' }} -c ${{ inputs.comment_styles || '//' }} - name: Commit and Push - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "[${{ inputs.message || 'Manual run' }}]: Add Notice to New Files" + commit_message: "[${{ inputs.commit_message || 'Manual run' }}] Add Notice to New Files" diff --git a/.github/workflows/auto_merge.yaml b/.github/workflows/auto_merge.yaml index 7a0917a..0d1e89e 100644 --- a/.github/workflows/auto_merge.yaml +++ b/.github/workflows/auto_merge.yaml @@ -22,4 +22,4 @@ jobs: run: gh pr merge --auto --merge "$PR_URL" env: PR_URL: ${{github.event.pull_request.html_url}} - GH_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/build_and_release.yaml b/.github/workflows/build_and_release.yaml index 505d344..1817fed 100644 --- a/.github/workflows/build_and_release.yaml +++ b/.github/workflows/build_and_release.yaml @@ -20,26 +20,24 @@ on: - major update-msrv: type: boolean - + jobs: - validate-input: + validate-input: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions-ecosystem/action-regex-match@v2 id: regex-match with: text: ${{ inputs.version }} regex: '^v(\d+)\.(\d+)\.(\d+)-?(\w*)\+?(\d*)$' - + - name: Fail if don't match regex if: ${{ inputs.version && steps.regex-match.outputs.match == '' }} - run: exit 1; - - - name: print-info - failure() - if: failure() - run: echo "${{inputs.version}} doesn't match regex. Use a version similar to v3.1.4-alpha+159" + run: | + echo "${{inputs.version}} doesn't match regex. Use a version similar to v3.1.4-alpha+159" + exit 1; get-version: needs: validate-input @@ -85,7 +83,7 @@ jobs: - name: Versions using tag id: full_version - if: inputs.version + if: inputs.version run: | tag=${{inputs.version}}; echo $tag; @@ -93,8 +91,8 @@ jobs: echo ${tag##v}; outputs: - tag_version: ${{ inputs.version || steps.new_version.outputs.normal_tag_version || steps.current_version.outputs.normal_tag_version }} - crate_version: ${{ steps.full_version.outputs.normal_crate_version || steps.new_version.outputs.new_version || steps.current_version.outputs.current_version }} + tag_version: ${{ inputs.version || steps.new_version.outputs.normal_tag_version || steps.current_version.outputs.normal_tag_version }} + crate_version: ${{ steps.full_version.outputs.normal_crate_version || steps.new_version.outputs.new_version || steps.current_version.outputs.current_version }} pre-release: needs: get-version @@ -139,8 +137,37 @@ jobs: allow-missing-changelog: true ref: refs/tags/${{ needs.get-version.outputs.tag_version }} + check-if-bin: + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Install jql + uses: taiki-e/install-action@v2 + with: + tool: jql + + - name: Searching for bin + id: searching + run: | + result=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"targets"<|[0]|>"kind"' | jql '..' -i); + echo "targets=$result" >> "$GITHUB_OUTPUT"; + echo kind of targets $result; + + - name: print if skip upploading binaries to github release + if: ${{ !contains(steps.searching.outputs.targets, 'bin') }} + run: echo "This job avoid publishing binaries to github releases for libraries crates" + + outputs: + is_bin: ${{ contains(steps.searching.outputs.targets, 'bin') }} + build-and-release: - needs: [get-version, create-release] + needs: [get-version, create-release, check-if-bin] + if: ${{ needs.check-if-bin.outputs.is_bin == 'true' }} name: ${{ matrix.target }} (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: @@ -159,8 +186,16 @@ jobs: - {os: macos-latest, target: x86_64-apple-darwin, cross: false} - {os: macos-latest, target: aarch64-apple-darwin, cross: false} steps: + - name: Get sha-commit from tag + id: get_baseline_sha + run: | + latest_sha=$(git rev-list --tags --max-count=1) + echo "sha_tag=$latest_sha" >> "$GITHUB_OUTPUT"; + - name: Checkout source code uses: actions/checkout@v4 + with: + ref: ${{ steps.get_baseline_sha.outputs.sha_tag }} - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -182,8 +217,8 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} ref: refs/tags/${{ needs.get-version.outputs.tag_version }} checksum: sha256 - + publish-crate: needs: [create-tag] uses: ./.github/workflows/publish.yaml - secrets: inherit \ No newline at end of file + secrets: inherit diff --git a/.github/workflows/bump_version.yaml b/.github/workflows/bump_version.yaml index cc2a85b..3107c03 100644 --- a/.github/workflows/bump_version.yaml +++ b/.github/workflows/bump_version.yaml @@ -31,11 +31,11 @@ jobs: uses: taiki-e/install-action@v2 with: tool: cargo-bump - + - name: Run cargo bump run: cargo bump ${{ inputs.crate-version }} - name: Commit and Push - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Bump version: ${{ inputs.crate-version }}" diff --git a/.github/workflows/cargo_deny.yaml b/.github/workflows/cargo_deny.yaml index e62ca30..0e1c991 100644 --- a/.github/workflows/cargo_deny.yaml +++ b/.github/workflows/cargo_deny.yaml @@ -9,22 +9,22 @@ on: jobs: cargo-deny: runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 - + - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 - - name: Install Cargo deny + - name: Cargo deny uses: EmbarkStudios/cargo-deny-action@v1 cargo-audit: runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 - + - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -32,5 +32,4 @@ jobs: with: tool: cargo-audit - - name: Run cargo audit - run: cargo audit + - run: cargo audit diff --git a/.github/workflows/cargo_semver_checks.yaml b/.github/workflows/cargo_semver_checks.yaml index 10d9a8a..97776e6 100644 --- a/.github/workflows/cargo_semver_checks.yaml +++ b/.github/workflows/cargo_semver_checks.yaml @@ -21,7 +21,7 @@ on: - major jobs: - check-for-lib: + check-if-lib: runs-on: ubuntu-latest steps: - name: Fetch Repository @@ -34,7 +34,7 @@ jobs: uses: taiki-e/install-action@v2 with: tool: jql - + - name: Searching for lib id: searching run: | @@ -42,18 +42,36 @@ jobs: echo "targets=$result" >> "$GITHUB_OUTPUT"; echo kind of targets $result; - - name: print-info - skip cargo-semver-checks + - name: print if skip cargo-semver-checks if: ${{ !contains(steps.searching.outputs.targets, 'lib') }} run: echo "cargo semver-check only works in libraries" - outputs: + outputs: is_lib: ${{ contains(steps.searching.outputs.targets, 'lib') }} + get-baseline: + runs-on: ubuntu-latest + steps: + - name: Fetch Repository + uses: actions/checkout@v4 + + - name: Get latest sha-commit from previous tag + id: get_baseline_sha + run: | + latest_sha=$(git rev-list --tags --max-count=1) + echo "baseline=$latest_sha" >> "$GITHUB_OUTPUT"; + + - name: print if skip cargo-semver-checks + if: ${{ steps.get_baseline_sha.outputs.baseline == '' }} + run: echo "semver-checks needs a baseline. The baseline is the latest commit of the previous tag" + outputs: + baseline: ${{ steps.get_baseline_sha.outputs.baseline }} + cargo-semver-checks: - needs: check-for-lib - if: ${{ needs.check-for-lib.outputs.is_lib == 'true' }} + needs: [check-if-lib, get-baseline] + if: ${{ needs.check-if-lib.outputs.is_lib == 'true' && needs.get-baseline.outputs.baseline != ''}} runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -61,7 +79,7 @@ jobs: uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Install cargo-bump - if: ${{ inputs.bump-version || inputs.release_type != 'none'}} + if: ${{ inputs.bump-version || inputs.release_type != 'none' }} uses: taiki-e/install-action@v2 with: tool: cargo-bump @@ -70,8 +88,10 @@ jobs: if: ${{ inputs.bump-version || inputs.release_type != 'none'}} run: cargo bump ${{ inputs.bump-version || inputs.release_type}} - - name: Check semver - uses: obi1kenobi/cargo-semver-checks-action@v2 + - name: Install cargo-semver-checks + uses: taiki-e/install-action@v2 with: - rust-toolchain: manual - shared-key: my-workspace-semver \ No newline at end of file + tool: cargo-semver-checks + + - name: Run cargo-semver-checks + run: cargo semver-checks --baseline-rev ${{ needs.get-baseline.outputs.baseline }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 93ef56a..8e5b0b1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,13 +1,16 @@ name: CI +permissions: + contents: write + on: workflow_dispatch: workflow_call: - pull_request: + pull_request: push: branches: - main - + jobs: cargo-build: name: Cargo Build @@ -33,7 +36,7 @@ jobs: - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 - with: + with: components: rustfmt - name: Rustfmt Check @@ -46,10 +49,10 @@ jobs: steps: - name: Fetch Repository uses: actions/checkout@v4 - + - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 - with: + with: components: clippy - name: Clippy Check @@ -62,7 +65,7 @@ jobs: steps: - name: Fetch Repository uses: actions/checkout@v4 - + - name: Install stable toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 @@ -76,7 +79,7 @@ jobs: - name: Fetch Repository uses: actions/checkout@v4 - - name: Install Typos + - name: Install Typos uses: taiki-e/install-action@v2 with: tool: typos-cli @@ -102,4 +105,6 @@ jobs: cargo-deny: uses: ./.github/workflows/cargo_deny.yaml - \ No newline at end of file + + check-msrv: + uses: ./.github/workflows/msrv.yaml diff --git a/.github/workflows/msrv.yaml b/.github/workflows/msrv.yaml index a9c37e6..567f417 100644 --- a/.github/workflows/msrv.yaml +++ b/.github/workflows/msrv.yaml @@ -5,9 +5,6 @@ permissions: on: workflow_call: - inputs: - update-msrv: - type: boolean workflow_dispatch: inputs: update-msrv: @@ -15,9 +12,9 @@ on: jobs: check-msrv: - if: ${{ !inputs.update-msrv }} + if: ${{ !inputs.update-msrv }} runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -27,9 +24,9 @@ jobs: - uses: cargo-bins/cargo-binstall@main - name: Install cargo-msrv - # waiting for the stable release - run : cargo binstall cargo-msrv --version 0.16.0-beta.20 -y --force - + # waiting for the stable release + run: cargo binstall cargo-msrv --version 0.16.0-beta.20 -y --force + - name: Get current msrv id: data-msrv run: | @@ -37,7 +34,7 @@ jobs: echo "current msrv: $current_msrv"; echo "current=$current_msrv" >> "$GITHUB_OUTPUT"; - - name: Run cargo msrv + - name: Run cargo msrv run: cargo msrv verify --min ${{ steps.data-msrv.outputs.current }} - name: echo msrv info @@ -48,7 +45,7 @@ jobs: echo "new msrv: $new_msrv"; update-msrv: - if: inputs.update-msrv && always() + if: inputs.update-msrv runs-on: ubuntu-latest steps: - name: Fetch Repository @@ -62,8 +59,8 @@ jobs: - uses: cargo-bins/cargo-binstall@main - name: Install cargo-msrv - # waiting for the stable release - run : cargo binstall cargo-msrv --version 0.16.0-beta.20 -y --force + # waiting for the stable release + run: cargo binstall cargo-msrv --version 0.16.0-beta.20 -y --force - name: Get msrv data id: data-msrv @@ -71,7 +68,7 @@ jobs: current_msrv=$(cargo msrv show --output-format minimal); echo "current msrv: $current_msrv"; echo "current=$current_msrv" >> "$GITHUB_OUTPUT"; - new_msrv=$(cargo msrv --output-format minimal); + new_msrv=$(cargo msrv --output-format minimal --min $current_msrv); echo "new msrv: $new_msrv"; echo "new=$new_msrv" >> "$GITHUB_OUTPUT"; @@ -79,13 +76,13 @@ jobs: run: cargo msrv set ${{ steps.data-msrv.outputs.new }} - name: Update readme msrv - uses: jacobtomlinson/gha-find-replace@v3 + uses: jacobtomlinson/gha-find-replace@v3 with: find: ${{ steps.data-msrv.outputs.current }} replace: ${{ steps.data-msrv.outputs.new }} regex: false - name: Commit and Push - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "Update MSRV from [${{steps.data-msrv.outputs.current}}] to [${{steps.data-msrv.outputs.new}}]" \ No newline at end of file + commit_message: "Update MSRV from [${{steps.data-msrv.outputs.current}}] to [${{steps.data-msrv.outputs.new}}]" diff --git a/.github/workflows/pre_release.yaml b/.github/workflows/pre_release.yaml index 9bbadf1..b7e29dc 100644 --- a/.github/workflows/pre_release.yaml +++ b/.github/workflows/pre_release.yaml @@ -17,27 +17,22 @@ on: update-msrv: type: boolean -permissions: +permissions: contents: write jobs: run-ci: uses: ./.github/workflows/ci.yaml - update-msrv: - uses: ./.github/workflows/msrv.yaml - with: - update-msrv: ${{ inputs.update-msrv }} - cargo-semver-checks: uses: ./.github/workflows/cargo_semver_checks.yaml with: bump-version: ${{ inputs.version }} add-notice: - uses: ./.github/workflows/add_notice.yaml + uses: ./.github/workflows/add_notice.yaml with: - message: ${{ inputs.version }} + commit_message: ${{ inputs.version }} bump-version: needs: [cargo-semver-checks] @@ -49,4 +44,4 @@ jobs: needs: [bump-version] uses: ./.github/workflows/update_attributions.yaml with: - message: ${{ inputs.version }} \ No newline at end of file + commit_message: ${{ inputs.version }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c32ce47..285930a 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -5,7 +5,26 @@ on: workflow_dispatch: jobs: + check-secret-existence: + runs-on: ubuntu-latest + steps: + - name: Get secret + id: secret + run: | + token=${{ secrets.CARGO_REGISTRY_TOKEN != '' }}; + echo "token_exists=$token" >> "$GITHUB_OUTPUT"; + + - name: print if skip publish-crate + if: ${{ steps.secret.outputs.token_exists == 'false' }} + run: | + echo "add secrets.CARGO_REGISTRY_TOKEN to your github repo"; + + outputs: + secret_exists: ${{ steps.secret.outputs.token_exists }} + publish-crate: + needs: [check-secret-existence] + if: ${{ needs.check-secret-existence.outputs.secret_exists == 'true' }} runs-on: ubuntu-latest steps: - name: Fetch Repository diff --git a/.github/workflows/update_attributions.yaml b/.github/workflows/update_attributions.yaml index 02f1fef..38935c1 100644 --- a/.github/workflows/update_attributions.yaml +++ b/.github/workflows/update_attributions.yaml @@ -3,14 +3,14 @@ name: Update Attributions on: workflow_call: inputs: - message: + commit_message: type: string workflow_dispatch: jobs: update-attributions: runs-on: ubuntu-latest - steps: + steps: - name: Fetch Repository uses: actions/checkout@v4 @@ -23,11 +23,11 @@ jobs: uses: taiki-e/install-action@v2 with: tool: cargo-attribution - + - name: Run cargo attribution run: cargo attribution - + - name: Commit and Push - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "[${{ inputs.message || 'Manual run' }}]: Update Attributions" + commit_message: "[${{ inputs.commit_message || 'Manual run' }}]: Update Attributions" diff --git a/.github/workflows/weekly.yaml b/.github/workflows/weekly.yaml index 6876942..2db0ce2 100644 --- a/.github/workflows/weekly.yaml +++ b/.github/workflows/weekly.yaml @@ -4,8 +4,7 @@ on: schedule: - cron: "0 0 * * 0" - -permissions: +permissions: contents: write jobs: @@ -13,11 +12,11 @@ jobs: uses: ./.github/workflows/ci.yaml add-notice: - uses: ./.github/workflows/add_notice.yaml + uses: ./.github/workflows/add_notice.yaml with: - message: Weekly Checks + commit_message: "Weekly run" update-attribution: uses: ./.github/workflows/update_attributions.yaml with: - message: Weekly Checks \ No newline at end of file + commit_message: "Weekly run"