git-anger-management 0.7.0

Count your naughty words in git commit messages
Documentation
name: pipeline

on:
  pull_request:
  push:
    branches:
      - master
    tags:
      - "v*.*.*"

jobs:
  formatting:
    name: Formatting
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: rustfmt
          override: true
      - run: rustup component add rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  linting:
    name: Lints
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable, nightly]

    steps:
      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install ${{ matrix.rust }} toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: rustfmt, clippy

      - name: Run cargo fmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

      - name: Run cargo clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

      - name: Run cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check

  # Run tests on Linux, macOS, and Windows
  # On both Rust stable and Rust nightly
  test:
    name: Test Suite
    needs: [check]
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        rust: [stable, nightly]
    steps:
      - uses: actions/checkout@v2

      - name: Cache cargo registry
        uses: actions/cache@v1
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo index
        uses: actions/cache@v1
        with:
          path: ~/.cargo/git
          key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

  cargo_publish:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Publish Cargo Package
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: cargo login $CRATES_IO_TOKEN
      - run: cargo publish
    env:
      CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

  github_build:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Build release binaries
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - x86_64-unknown-linux-musl
          - x86_64-apple-darwin
          - x86_64-pc-windows-msvc
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: git-anger-management-x86_64-unknown-linux-gnu.tar.gz
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            name: git-anger-management-x86_64-unknown-linux-musl.tar.gz
          - target: x86_64-apple-darwin
            os: macOS-latest
            name: git-anger-management-x86_64-apple-darwin.tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: git-anger-management-x86_64-pc-windows-msvc.zip
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          target: ${{ matrix.target }}

      - name: Install musl tools
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt-get install -y musl-tools libssl-dev

      - name: Build target
        if: matrix.target != 'x86_64-unknown-linux-musl'
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target ${{ matrix.target }}

      - name: Build target (musl)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target ${{ matrix.target }}

      - name: Prepare build artifacts [Windows]
        if: matrix.os == 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          strip git-anger-management.exe
          7z a ../../../${{ matrix.name }} git-anger-management.exe
          cd -
      - name: Prepare build artifacts [-nix]
        if: matrix.os != 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          strip git-anger-management
          tar czvf ../../../${{ matrix.name }} git-anger-management
          cd -
      - name: Upload build artifact
        uses: actions/upload-artifact@v1
        with:
          name: ${{ matrix.name }}
          path: ${{ matrix.name }}

  github_release:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Create GitHub Release
    needs: github_build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Download Linux GNU artifact
        uses: actions/download-artifact@v1
        with:
          name: git-anger-management-x86_64-unknown-linux-gnu.tar.gz
          path: .

      - name: Download Linux MUSL artifact
        uses: actions/download-artifact@v1
        with:
          name: git-anger-management-x86_64-unknown-linux-musl.tar.gz
          path: .

      - name: Download Darwin artifact
        uses: actions/download-artifact@v1
        with:
          name: git-anger-management-x86_64-apple-darwin.tar.gz
          path: .

      - name: Download Windows artifact
        uses: actions/download-artifact@v1
        with:
          name: git-anger-management-x86_64-pc-windows-msvc.zip
          path: .

      - name: Print directory
        run: ls -R

      - name: Create GitHub release ${{ matrix.target }}
        uses: softprops/action-gh-release@v1
        with:
          files: |
            git-anger-management-x86_64-apple-darwin.tar.gz
            git-anger-management-x86_64-pc-windows-msvc.zip
            git-anger-management-x86_64-unknown-linux-gnu.tar.gz
            git-anger-management-x86_64-unknown-linux-musl.tar.gz
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}