Skip to content

Commit

Permalink
update and clean up ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ameknite committed Mar 16, 2024
1 parent 3eccd0b commit 2ff3d87
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 91 deletions.
15 changes: 14 additions & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- "*"
71 changes: 62 additions & 9 deletions .github/workflows/add_notice.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/auto_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
65 changes: 50 additions & 15 deletions .github/workflows/build_and_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,16 +83,16 @@ jobs:
- name: Versions using tag
id: full_version
if: inputs.version
if: inputs.version
run: |
tag=${{inputs.version}};
echo $tag;
echo "normal_crate_version=${tag##v} >> GITHUB_OUTPUT";
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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/bump_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
13 changes: 6 additions & 7 deletions .github/workflows/cargo_deny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ 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

- uses: taiki-e/install-action@v2
with:
tool: cargo-audit

- name: Run cargo audit
run: cargo audit
- run: cargo audit
44 changes: 32 additions & 12 deletions .github/workflows/cargo_semver_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
- major

jobs:
check-for-lib:
check-if-lib:
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand All @@ -34,34 +34,52 @@ jobs:
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-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

- name: Install stable toolchain
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
Expand All @@ -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
tool: cargo-semver-checks

- name: Run cargo-semver-checks
run: cargo semver-checks --baseline-rev ${{ needs.get-baseline.outputs.baseline }}

0 comments on commit 2ff3d87

Please sign in to comment.