name: Go
on:
  push:
    branches:
      - master
  pull_request:
jobs:
  lint:
    name: lint
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: setup Go
        uses: actions/setup-go@v4
        with:
          go-version: "1.24"
      - name: run linters
        run: |
          make lint

  race-test:
    name: Test with -race
    strategy:
      matrix:
        os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
        go-version: [ "1.21", "1.22", "1.23", "1.24" ]
    runs-on: ${{ matrix.os }}
    steps:
    - name: checkout
      uses: actions/checkout@v4
    - name: setup Go ${{ matrix.go-version }}
      uses: actions/setup-go@v4
      with:
        go-version: ${{ matrix.go-version }}
    - name: test
      run: |
        make test

  i386-test:
    name: Test in i386
    strategy:
      matrix:
        os: [ "ubuntu-latest", "windows-latest" ]
        go-version: [ "1.21", "1.22", "1.23", "1.24" ]
    runs-on: ${{ matrix.os }}
    env:
      GOARCH: "386"
    steps:
    - name: checkout
      uses: actions/checkout@v4
    - name: setup Go ${{ matrix.go-version }}
      uses: actions/setup-go@v4
      with:
        go-version: ${{ matrix.go-version }}
    - name: test
      run: |
        make simple-test

  fuzz:
    name: Fuzzing Test
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: setup Go
        uses: actions/setup-go@v4
        with:
          go-version: "1.24"
      - name: run
        run: |
          make fuzz

  ycat:
    name: ycat
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: setup Go
        uses: actions/setup-go@v4
        with:
          go-version: "1.24"
      - name: build
        run: |
          make ycat/build
      - name: run
        run: |
          ./bin/ycat .github/workflows/go.yml

  page:
    name: page
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
          cache-dependency-path: docs/playground/package-lock.json
      - name: install dependencies
        run: make -C ./docs/playground deps
      - name: build
        run: make -C ./docs/playground build

  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: setup Go
        uses: actions/setup-go@v4
        with:
          go-version: "1.24"
      - name: measure coverage
        run: |
          make cover
      - uses: codecov/codecov-action@v4
        with:
          fail_ci_if_error: true
          verbose: true
          token: ${{ secrets.CODECOV_TOKEN }}
