name: CD

on:
  push:
    tags:
    - 'v*'

jobs:
  build:
    runs-on: windows-latest
    steps:
      - name: Checkout keynavish
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Install dmd and dub
        uses: dlang-community/setup-dlang@v1
        with:
          compiler: dmd-2.100.2
      - name: Build keynavish (x86_64)
        run: dub build -b=release -a=x86_64
      - name: Create release
        id: create-release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: ${{ github.ref }}
          draft: false
          prerelease: false
      - name: Get release version
        id: get-release-version
        uses: little-core-labs/get-git-tag@v3.0.1
      - name: Upload release asset (x86_64)
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create-release.outputs.upload_url }}
          asset_path: ./out/keynavish.exe
          asset_name: keynavish-${{ steps.get-release-version.outputs.tag }}-x86_64.exe
          asset_content_type: application/octet-stream
      - name: Build keynavish (x86)
        run: dub build -b=release -a=x86
      - name: Upload release asset (x86)
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create-release.outputs.upload_url }}
          asset_path: ./out/keynavish.exe
          asset_name: keynavish-${{ steps.get-release-version.outputs.tag }}-x86.exe
          asset_content_type: application/octet-stream
