name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
CARGO_TERM_COLOR: always
jobs:
rust-checks:
name: Rust Checks
runs-on: ubuntu-22.04
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
action:
- command: build
args: --release
- command: fmt
args: --all -- --check --color always
- command: clippy
args: --workspace -- -D warnings
- command: test
args: --workspace --release
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Enable caching
uses: Swatinem/rust-cache@v2
- name: Run command
run: cargo ${{ matrix.action.command }} ${{ matrix.action.args }}
check-version:
name: Check Version
needs: rust-checks
if: ${{ needs.rust-checks.result == 'success' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create Tag
id: create-tag
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
dry_run: true outputs:
release_type: ${{ steps.create-tag.outputs.release_type }}
new_tag: ${{ steps.create-tag.outputs.new_tag }}
new_version: ${{ steps.create-tag.outputs.new_version }}
changelog: ${{ steps.create-tag.outputs.changelog }}
create-release:
name: Create Release
needs: check-version
if: ${{ needs.check-version.outputs.release_type != false }}
runs-on: ubuntu-22.04
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Bump Version
run: ./scripts/bump-version.bash
env:
VERSION: ${{ needs.check-version.outputs.new_version }}
- name: Push verion
uses: EndBug/add-and-commit@v9
with:
committer_name: github-actions[bot]
committer_email: github-actions[bot]@users.noreply.github.com
fetch: false
message: "Bump version: ${{ needs.check-version.outputs.new_tag }}"
new_branch: release/${{ needs.check-version.outputs.new_tag }}
tag: ${{ needs.check-version.outputs.new_tag }}
- name: Create and merge Pull Request
run: |
gh pr create --base ${GITHUB_REF_NAME} --head ${{ env.branch }} -l "bump version" \
--title "Bump version: ${{ needs.check-version.outputs.new_tag }}" --body 'Automated changes by [CI](https://github.com/teruyamato0731/advanced-pid-rs/actions/workflows/ci.yaml) GitHub action'
gh pr merge ${{ env.branch }} --merge --delete-branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
branch: "release/${{ needs.check-version.outputs.new_tag }}"
- name: Publish
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.check-version.outputs.new_tag }}
body: ${{ needs.check-version.outputs.changelog }}