name: Build and Test Signer Darwin

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

jobs:

  build:
    runs-on: macos-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: 1.25

    - name: Build
      working-directory: ./internal/signer/darwin
      run: go build -v ./...

      # The binary must be built before creating credentials so it can be added
      # as a trusted application to the keychain.
    - name: Build Test Binary for Signer
      working-directory: ./internal/signer/darwin/keychain
      run: go test -c .

    - name: Create keychain credentials
      run: ./scripts/keychain_cred.sh
      
    - name: Run Test Binary for Signer
      working-directory: ./internal/signer/darwin/keychain
      run: ./keychain.test

    - name: Test Darwin Client
      working-directory: ./darwin
      run: go test -v .
      
    - name: Lint Signer
      uses: golangci/golangci-lint-action@v6
      with:
        version: latest
        working-directory: ./internal/signer/darwin
        args: -E gofmt --max-same-issues 0

    - name: Lint Client
      uses: golangci/golangci-lint-action@v6
      with:
        version: latest
        working-directory: ./darwin
        args: -E gofmt --max-same-issues 0

    - name: Create Binaries
      run: ./build/scripts/darwin_amd64.sh && ./build/scripts/darwin_arm64.sh

    - uses: actions/upload-artifact@v4
      with:
        name: darwin_amd64
        path: ./build/bin/darwin_amd64/*

    - uses: actions/upload-artifact@v4
      with:
        name: darwin_arm64
        path: ./build/bin/darwin_arm64/*
