# This package only works fully with GopherJS as of 2c06401a, which is not yet
# released, thus we're pulling in `master`. Once GopherJS 1.18 is released with
# this support, we can depend on a proper tag.
name: GopherJS

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:

  build:
    name: Build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        go: [1.18]
    steps:

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: ${{ matrix.go }}
      id: go

    - name: Install GopherJS
      run: |
        mkdir -p $(go env GOPATH)/src/github.com/gopherjs;
        cd $(go env GOPATH)/src/github.com/gopherjs;
        git clone --depth 1 --branch master https://github.com/gopherjs/gopherjs.git;
        cd gopherjs;
        go install;
        npm install source-map-support;
        cd $(go env GOPATH)/src/github.com/gopherjs/gopherjs/node-syscall/;
        npm install --global node-gyp;
        node-gyp rebuild;
        mkdir -p ~/.node_libraries/;
        cp build/Release/syscall.node ~/.node_libraries/syscall.node

    - name: Check out code into the Go module directory
      uses: actions/checkout@v3

    - name: Get dependencies
      run: go get -v -t -d ./...

    - name: Test
      run: $(go env GOPATH)/bin/gopherjs test -v
