---
name: CI on Pull Requests

on:
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  #commitlint:
  #  name: Lint Commit Messages
  #  runs-on: ubuntu-latest
  #  steps:
  #    - uses: actions/checkout@v3
  #      with:
  #        fetch-depth: 0
  #    - uses: wagoid/commitlint-github-action@v5

  doc:
    name: Build Doc
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          override: true
      - name: run cargo doc
        run: |
          sudo apt-get -y install musl-tools
          rustup target add x86_64-unknown-linux-musl
          cargo doc

  test:
    name: Test Suite
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: run cargo test
        run: |
          sudo apt-get -y install musl-tools
          rustup target add x86_64-unknown-linux-musl
          cargo test --all-features

  formatting:
    name: Code Formatting
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: running rustfmt
        run: |
          sudo apt-get -y install musl-tools
          rustup target add x86_64-unknown-linux-musl
          files=$(find . -name '*.rs')
          IFS=$'\n'; for file in $files; do
            rustfmt --check "$file"
          done
