Skip to content

Commit

Permalink
Improve CI/CD workflows
Browse files Browse the repository at this point in the history
- Add cargo-nextest instead of cargo test
- Add cargo doc and cargo test --doc
- Add yamlfmt
- Add merge_group and concurrency to CI
- Create check-if-lib workflow
- Add monthly releases workflow
- Remove pre_release workflow and move the jobs to build_and_release.yaml
  • Loading branch information
ameknite committed Jun 15, 2024
1 parent 8e23568 commit f60911b
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/add_notice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:
- name: Run add-notice
if: ${{ inputs.message == '' }}
run: add-notice --notice ${{ inputs.notice_path || './NOTICE' }} -e ${{ inputs.extensions || 'rs' }} -c ${{ inputs.comment_styles || '//' }}

- 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@v5
with:
Expand Down
47 changes: 39 additions & 8 deletions .github/workflows/build_and_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ on:
type: boolean
update-msrv:
type: boolean
workflow_call:
inputs:
version:
type: string
description: "Version: (e.g. -> v3.1.4-alpha+159)"
release_type:
type: string
check-to-publish:
type: boolean
update-msrv:
type: boolean

jobs:
validate-input:
Expand Down Expand Up @@ -102,15 +113,36 @@ jobs:
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
uses: ./.github/workflows/pre_release.yaml
run-ci:
needs: validate-input
uses: ./.github/workflows/ci.yaml

cargo-semver-checks:
needs: [run-ci, get-version]
uses: ./.github/workflows/cargo_semver_checks.yaml
with:
version: ${{ needs.get-version.outputs.crate_version }}
update-msrv: ${{ inputs.update-msrv }}
bump-version: ${{ needs.get-version.outputs.crate_version }}

add-notice:
needs: [run-ci, get-version]
uses: ./.github/workflows/add_notice.yaml
with:
commit_message: ${{ needs.get-version.outputs.crate_version }}

bump-version:
needs: [cargo-semver-checks, get-version]
uses: ./.github/workflows/bump_version.yaml
with:
crate-version: ${{ needs.get-version.outputs.crate_version }}

update-attribution:
needs: [bump-version, get-version]
uses: ./.github/workflows/update_attributions.yaml
with:
commit_message: ${{ needs.get-version.outputs.crate_version }}

create-tag:
needs: [get-version, pre-release]
needs: [get-version, update-attribution]
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down Expand Up @@ -191,10 +223,9 @@ jobs:
- {os: windows-latest, target: x86_64-pc-windows-msvc, cross: false}
- {os: windows-latest, target: x86_64-pc-windows-gnu, cross: true}
- {os: windows-latest, target: aarch64-pc-windows-msvc, cross: false}

- {os: macos-latest, target: x86_64-apple-darwin, cross: false}
- {os: macos-latest, target: aarch64-apple-darwin, cross: false}

steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
29 changes: 2 additions & 27 deletions .github/workflows/cargo_semver_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,7 @@ on:

jobs:
check-if-lib:
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 lib
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 cargo-semver-checks
if: ${{ !contains(steps.searching.outputs.targets, 'lib') }}
run: echo "cargo semver-check only works in libraries"

outputs:
is_lib: ${{ contains(steps.searching.outputs.targets, 'lib') }}
uses: ./.github/workflows/check-if-lib.yaml

get-baseline:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -92,7 +67,7 @@ jobs:
- name: Run cargo bump
if: ${{ inputs.bump-version || inputs.release_type != 'none'}}
run: cargo bump ${{ inputs.bump-version || inputs.release_type}}

- name: Install cargo-semver-checks
uses: taiki-e/install-action@v2
with:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/check-if-lib.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Cargo If Lib

on:
workflow_call:
outputs:
is_lib:
value: ${{ jobs.check-if-lib.outputs.is_lib }}

jobs:
check-if-lib:
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 lib
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 cargo-semver-checks
if: ${{ !contains(steps.searching.outputs.targets, 'lib') }}
run: echo "cargo semver-check only works in libraries"

outputs:
is_lib: ${{ contains(steps.searching.outputs.targets, 'lib') }}
87 changes: 73 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ permissions:
contents: write

on:
merge_group:
workflow_dispatch:
workflow_call:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
cargo-build:
Expand Down Expand Up @@ -56,9 +59,42 @@ jobs:
components: clippy

- name: Clippy Check
run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings
run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings

cargo-doc:
name: Cargo doc
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: Cargo doc test
run: cargo doc --workspace --all-features

check-if-lib:
uses: ./.github/workflows/check-if-lib.yaml

cargo-test-doc:
needs: check-if-lib
if: ${{ needs.check-if-lib.outputs.is_lib == 'true' }}
name: Cargo test doc
runs-on: ubuntu-latest

steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

cargo-test:
- name: Cargo test doc
run: cargo test --doc --workspace --all-features

cargo-next-test:
name: Cargo test
runs-on: ubuntu-latest

Expand All @@ -69,8 +105,13 @@ jobs:
- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest

- name: Cargo test
run: cargo test --workspace --all-targets --all-features
run: cargo nextest run --workspace --all-targets --all-features

cargo-miri-test:
name: Cargo miri
Expand All @@ -95,6 +136,7 @@ jobs:
typos-cli:
name: typos
runs-on: ubuntu-latest

steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -108,9 +150,9 @@ jobs:
run: typos

taplo-toml-fmt:

name: taplo fmt
runs-on: ubuntu-latest

steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -128,14 +170,31 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: markdownlint-cli2-action
uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: '**/*.md'

- name: Fetch Repository
uses: actions/checkout@v4

- name: markdownlint-cli2-action
uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: '**/*.md'

yamlfmt:
runs-on: ubuntu-latest

steps:
- name: Fetch Repository
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: stable

- name: Install yamlfmt
run: go install github.com/google/yamlfmt/cmd/yamlfmt@latest

- name: Run yamlfmt
run: yamlfmt --lint .

cargo-deny:
uses: ./.github/workflows/cargo_deny.yaml

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/mothly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Monthly Releases

on:
schedule:
- cron: "0 0 1 * *"
workflow_dispatch:

permissions:
contents: write

jobs:
build_and_release:
uses: ./.github/workflows/build_and_release.yaml
with:
release_type: patch
check-to-publish: true
49 changes: 0 additions & 49 deletions .github/workflows/pre_release.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
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 }}

Expand Down
Loading

0 comments on commit f60911b

Please sign in to comment.