name: Test Brew release on Mac

on:
  workflow_dispatch:

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

jobs:
  build:

    runs-on: macos-13

    steps:
    - name: Install dafny
      run: |
        brew install dafny
    - name: Versions
      run: |
        which dafny
        dafny -version
        dotnet --list-sdks
        go version
        node --version
        java -version
        python --version
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.11'
    ## To be consistent, the download should be tested with the quicktest.sh corresponding to
    ## that release. But earlier releases relied on inline tests. So for up through 4.0,
    ## we downliad quicktest.sh from the repo -- which will eventually fail if the quicktest
    ## evolves beyond the capabilities of old versions.
    ## But post-4.0, the script is part of the release and internally checks its results.
    - name: Perform smoke tests on each platform
      run: |
        npm install bignumber.js
        ver=`dafny -version`
        ver=${ver[1]}
        if [[ "$ver" < "4.0.0.99999" ]] ; then \
          echo "4.0 or prior" ;\
          wget https://github.com/dafny-lang/dafny/raw/master/Scripts/quicktest.sh; \
        else \
          echo "Post 4.0" ;\
          cp /usr/local/Cellar/dafny/*/libexec/quicktest.sh . ;\
        fi
        chmod +x quicktest.sh
        ./quicktest.sh `which dafny`
