name: tagged-release

on:
  workflow_dispatch:
  push:
    tags:
      - "v*"

jobs:
  tagged-release:
    name: "Tagged Release"
    runs-on: "ubuntu-latest"

    steps:
      - uses: actions/checkout@v2

      - name: Install Rust (Stable)
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: thumbv7em-none-eabihf
          components: llvm-tools-preview
          override: true

      - name: Install Binutils
        uses: actions-rs/cargo@v1
        with:
          command: install
          args: cargo-binutils

      - name: Build Release
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release

      - name: Dump Release Binary
        uses: actions-rs/cargo@v1
        with:
          command: objcopy
          args: --release -- -O binary booster-release.bin

      - name: Generate Release
        env:
          GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
          VERSION_TAG: ${GITHUB_REF##*/}
        run: |
          hub release create -a "target/thumbv7em-none-eabihf/release/booster#booster-release" -a "booster-release.bin" -m "Release ${{env.VERSION_TAG}}" ${{env.VERSION_TAG}}
