name: Test Release Downloads

on:
  release:
    types: [ published ]
  # For manual testing through the Actions UI
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # This workflow breaks on windows-2022: https://github.com/dafny-lang/dafny/issues/1906
        os: [ ubuntu-latest, ubuntu-20.04, macos-13, windows-2019 ]
        include:
        - os:  'ubuntu-latest'
          osn: 'ubuntu-20.04'
        - os:  'ubuntu-20.04'
          osn: 'ubuntu-20.04'
        - os:  'macos-13'
          osn: 'x64-macos-13'
        - os:  'windows-2019'
          osn: 'windows-2019'
    # There is no hosted environment for Ubuntu 14.04 or for debian

    # Java is installed by default, but we need to select 18

    steps:
    - name: OS
      run: echo ${{ runner.os }} ${{ matrix.os }}
    - name: Set up JDK 18
      uses: actions/setup-java@v4
      with:
        java-version: 18
        distribution: corretto
    - name: Download ${{matrix.os}} releases
      uses: dsaltares/fetch-gh-release-asset@master
      with:
        repo: dafny-lang/dafny
        file: "dafny-.*-${{ matrix.osn }}\\.zip"
        regex: true
        target: "./"
    - run: ls
    - if: runner.os != 'Windows'
      run: |
        unzip dafny*.zip && rm dafny*.zip
    - if: runner.os == 'Windows'
      shell: pwsh
      run: |
        Expand-Archive dafny*.zip
        mv dafny*/dafny dafny

    ## Record versions, checking that dafny runs
    - name: Versions
      run: |
        dafny/z3/bin/z3-4.8.5 -version
        dafny/z3/bin/z3-4.12.1 -version
        dafny/dafny -version
    
    ## Check that a simple program compiles and runs on each supported platform
    - name: run quicktests
      run: |
        npm install bignumber.js
        dafny/quicktest.sh > log.txt
        diff log.txt dafny/quicktest.out
