name: CE Windows Build
run-name: Build CE Windows version ${{ inputs.buildnumber }}

on:
  workflow_dispatch:
    inputs:
      buildnumber:
        description: 'Build number'
        default: ''
        required: true

jobs:
  build_dist:
    runs-on: windows-2022
    outputs:
      release_name: ${{ steps.build_dist.outputs.release_name }}
      branch: ${{ steps.build_dist.outputs.branch }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ github.event.inputs.buildnumber }}
      - name: Use Node.js 22.13.1
        uses: actions/setup-node@v4
        with:
          node-version: 22.13.1
          cache: npm
      - name: Build distribution
        id: build_dist
        run: powershell -File etc/scripts/build-dist-win.ps1
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: out/dist-bin

  deploy:
    needs: [build_dist]
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Use Node.js 22.x
        uses: actions/setup-node@v4
        with:
          node-version: 22.x
          check-latest: true
          cache: npm
      - name: Download the built distribution
        uses: actions/download-artifact@v4
        with:
          name: dist
          path: out/dist-bin
      - name: Deploy
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --acl public-read --follow-symlinks
        env:
          AWS_S3_BUCKET: compiler-explorer
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          SOURCE_DIR: out/dist-bin
          DEST_DIR: dist/gh/${{ needs.build_dist.outputs.branch }}
