mic 0.1.0

Facilitates answering to competitive programming problems.
Documentation
name: CI

on:
  schedule:
    - cron: '0 0 * * 0'
  push:
    branches:
      - master
    tags:
      - 'mic**'
  pull_request:

jobs:
  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-20.04

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

      - name: Set up `stable-x86_64-unknown-linux-gnu`
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          components: rustfmt

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

      - name: cargo-fmt (./ui-tests)
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --manifest-path ./ui-tests/Cargo.toml -- --check

  build:
    strategy:
      fail-fast: false
      matrix:
        toolchain:
          - 1.42.0-x86_64-pc-windows-msvc
          - 1.42.0-x86_64-apple-darwin
          - 1.42.0-x86_64-unknown-linux-gnu
          - stable-x86_64-pc-windows-msvc
          - stable-x86_64-apple-darwin
          - stable-x86_64-unknown-linux-gnu
        include:
          - { toolchain: 1.42.0-x86_64-pc-windows-msvc  , os: windows-2019 }
          - { toolchain: 1.42.0-x86_64-apple-darwin     , os: macos-10.15  }
          - { toolchain: 1.42.0-x86_64-unknown-linux-gnu, os: ubuntu-20.04 }
          - { toolchain: stable-x86_64-pc-windows-msvc  , os: windows-2019 }
          - { toolchain: stable-x86_64-apple-darwin     , os: macos-10.15  }
          - { toolchain: stable-x86_64-unknown-linux-gnu, os: ubuntu-20.04 }

    name: Build (${{ matrix.toolchain }})
    runs-on: ${{ matrix.os }}

    steps:
      # https://github.com/actions/checkout/issues/135
      - name: Disable `core.autocrlf`
        run: git config --global core.autocrlf false
        if: matrix.os == 'windows-2019'

      - name: Checkout
        uses: actions/checkout@v2

      - name: 'Set up `${{ matrix.toolchain }}`'
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          override: true
          profile: minimal
          components: clippy

      - name: cargo-clippy (.)
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --workspace --all-targets -- -D warnings
        if: startsWith(matrix.toolchain, 'stable')

      - name: cargo-build (.)
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --workspace --all-targets

      - name: cargo-test (.)
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --workspace --no-fail-fast
        env:
          RUST_BACKTRACE: full

      - name: cargo-clippy (./ui-tests)
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --manifest-path ./ui-tests/Cargo.toml --all-targets -- -D warnings
        if: matrix.toolchain == 'stable-x86_64-apple-darwin' || matrix.toolchain == 'stable-x86_64-unknown-linux-gnu'

      - name: cargo-build (./ui-tests)
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --manifest-path ./ui-tests/Cargo.toml
        if: matrix.toolchain == 'stable-x86_64-apple-darwin' || matrix.toolchain == 'stable-x86_64-unknown-linux-gnu'

      - name: cargo-test (./ui-tests)
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --manifest-path ./ui-tests/Cargo.toml --no-fail-fast
        env:
          RUST_BACKTRACE: full
        if: matrix.toolchain == 'stable-x86_64-apple-darwin' || matrix.toolchain == 'stable-x86_64-unknown-linux-gnu'

  upload-release-notes:
    name: Upload the release notes
    runs-on: ubuntu-20.04
    if: ${{ startsWith(github.ref, 'refs/tags/') }}

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

      - name: Set up Python 3.9
        uses: actions/setup-python@v2
        with:
          python-version: '3.9'
        if: ${{ startsWith(github.ref, 'refs/tags/mic-v') }}

      - name: Prepare release notes
        run: |
          from pathlib import Path
          PATH = Path('./CHANGELOG.md')
          output = ''
          if PATH.exists():
              with open(PATH) as file:
                  changelog = file.read()
              inside_subsection = False
              for line in changelog.splitlines():
                  is_h2 = line.startswith('## ')
                  if not inside_subsection and is_h2:
                      inside_subsection = True
                  elif inside_subsection and not is_h2:
                      output += line + '\n'
                  elif inside_subsection:
                      break
          with open('./release-notes.md', 'w') as file:
              file.write(f'{output.strip()}\n')
        shell: python
        if: ${{ startsWith(github.ref, 'refs/tags/mic-v') }}

      - name: Prepare release notes
        run: touch ./release-notes.md
        shell: bash
        if: ${{ startsWith(github.ref, 'refs/tags/mic_impl-v') }}

      - name: Upload the release notes
        uses: actions/upload-artifact@v2
        with:
          name: release-notes
          path: release-notes.md


  gh-release:
    name: GH Release
    runs-on: ubuntu-20.04
    needs: [rustfmt, build, upload-release-notes]

    steps:
      - name: Download the release notes
        uses: actions/download-artifact@v2
        with:
          name: release-notes
          path: .

      - name: GH Release
        uses: softprops/action-gh-release@v1
        with:
          body_path: ./release-notes.md
          files: ./assets/*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}