name: Publish Crate

on:
  workflow_dispatch:
    inputs:
      release_tag:
        description: 'Tag for the associated GitHub release.'
        required: true

env:
  CARGO_TERM_COLOR: always
  CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Build
      run: cargo build --all-targets --verbose
    - name: Test
      run: cargo test --verbose
    - name: Publish
      run: cargo publish --verbose

    - name: Create Release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.event.inputs.release_tag }}
        release_name: Release ${{ github.event.inputs.release_tag}}
        draft: false
        prerelease: false
