name: Pull Request Build

on:
  pull_request:
    branches:
      - master

jobs:
  build:
    name: Build
    runs-on: ubuntu-20.04
    steps:
      - name: Set up Go 1.16
        uses: actions/setup-go@v5.2.0
        with:
          go-version: 1.23
        id: go
      - name: Check out code into the Go module directory
        uses: actions/checkout@v4
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v6.1.0
        with:
          args: release --snapshot --clean
      - name: Upload Artifact for darwin
        uses: actions/upload-artifact@v4
        with:
          name: jcli-darwin-amd64
          path: release/jcli-darwin-amd64.tar.gz
      - name: Upload Artifact for linux
        uses: actions/upload-artifact@v4
        with:
          name: jcli-linux-amd64
          path: release/jcli-linux-amd64.tar.gz
  GoLint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.16
        uses: actions/setup-go@v5.2.0
        with:
          go-version: 1.23
        id: go
      - name: Check out code into the Go module directory
        uses: actions/checkout@v4
      - name: Go-linter-1
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: app/cmd/...
      - name: Go-linter-2
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: app/helper/...
      - name: Go-linter-3
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: app/i18n/i18n.go
      - name: Go-linter-4
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: app/.
      - name: Go-linter-5
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: client/...
      - name: Go-linter-6
        uses: Jerome1337/golint-action@v1.0.2
        with:
          golint-path: util/...
  Security:
    name: Security
    runs-on: ubuntu-latest
    env:
      GO111MODULE: on
    steps:
      - name: Checkout Source
        uses: actions/checkout@v4
      - name: Run Gosec Security Scanner
        uses: securego/gosec@master
        with:
          args: '-exclude=G402,G204,G304,G110 app/cmd/common'

#      - name: SonarCloud Scan
#        uses: LinuxSuRen/sonarcloud-github-action@master
#        env:
#          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

#      - name: Test
#        run: |
#          export PATH=$PATH:${PWD}/bin:$GOPATH/bin:/home/runner/go/bin
#          make test
  UnitTest:
    name: Test
    runs-on: ubuntu-20.04
    steps:
      - name: Set up Go 1.16
        uses: actions/setup-go@v5.2.0
        with:
          go-version: 1.23
        id: go
      - name: Check out code into the Go module directory
        uses: actions/checkout@v4
      - name: Test
        run: |
          make test
