name: CI

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

jobs:

  build:
    name: Console CI
    runs-on: ubuntu-22.04
    timeout-minutes: 5
    steps:

    - name: Set up Go
      uses: actions/setup-go@v3
      with:
        go-version: 1.19.x
      id: go

    - name: Setup Go binary path
      shell: bash
      run: |
        echo "GOPATH=${{ github.workspace }}" >> $GITHUB_ENV
        echo "${{ github.workspace }}/bin" >> $GITHUB_PATH

    - name: Check out code
      uses: actions/checkout@v3
      with:
        path: src/github.com/containerd/console
        fetch-depth: 25

    - name: Install dependencies
      run: |
        go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1

    - name: Project Checks
      uses: containerd/project-checks@v1.1.0
      with:
        working-directory: src/github.com/containerd/console

    - name: Go Linting
      run: GOGC=75 golangci-lint run
      working-directory: src/github.com/containerd/console

    - name: Build & Test
      working-directory: src/github.com/containerd/console
      run: |
        go test -race
        GOOS=openbsd go build
        GOOS=windows go build
