name: Build Standalone CLI

on:
  push:
    tags:
      - 'v*'

env:
  CI: true

jobs:
  build_cli:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v2

      - run: git fetch --tags -f

      - name: Resolve version
        id: vars
        run: echo "::set-output name=tag_name::$(git describe --tags --abbrev=0)"

      - name: Use Node.js 16
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          registry-url: 'https://registry.npmjs.org'

      - name: Build tailwindcss
        run: npm run prepublishOnly

      - name: Install standalone cli dependencies
        run: npm install
        working-directory: standalone-cli

      - name: Build standalone cli
        run: npm run build
        working-directory: standalone-cli

      - name: Test
        run: npm test
        working-directory: standalone-cli

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          tag_name: ${{ steps.vars.outputs.tag_name }}
          body: |
            * [Linux (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ steps.vars.outputs.tag_name }}/tailwindcss-linux-arm64)
            * [Linux (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ steps.vars.outputs.tag_name }}/tailwindcss-linux-x64)
            * [macOS (arm64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ steps.vars.outputs.tag_name }}/tailwindcss-macos-arm64)
            * [macOS (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ steps.vars.outputs.tag_name }}/tailwindcss-macos-x64)
            * [Windows (x64)](https://github.com/tailwindlabs/tailwindcss/releases/download/${{ steps.vars.outputs.tag_name }}/tailwindcss-windows-x64.exe)
          files: |
            standalone-cli/dist/tailwindcss-linux-arm64
            standalone-cli/dist/tailwindcss-linux-x64
            standalone-cli/dist/tailwindcss-macos-arm64
            standalone-cli/dist/tailwindcss-macos-x64
            standalone-cli/dist/tailwindcss-windows-x64.exe