name: format native

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

permissions:
  contents: read

jobs:
  check-native-format:
    name: ${{ matrix.step-name }}
    runs-on: ${{ matrix.runner }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - step-name: native-format-macos
            runner: macos-13-xlarge
          - step-name: native-format-linux
            runner: ubuntu-22.04
          - step-name: native-format-windows
            runner: windows-2022

    steps:

    - name: Checkout
      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2

    - name: Install Clang tools
      shell: bash
      run: ./scripts/download-clang-tools.sh

    - name: Format native code
      shell: bash
      run: ./scripts/format-native.sh

  check-native-headers:
    runs-on: ubuntu-22.04
    steps:

      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag: v4.2.2

      - name: Setup Go
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag: v5.5.0
        with:
          go-version: '1.23.5'
          cache: false # Suppress a warning given that there are no go.sum files in the repo

      - name: Verify all native files have license headers
        shell: bash
        run: |
          go install github.com/google/addlicense@v1.1.1
          addlicense -v -y "" -l "apache" -c "The OpenTelemetry Authors" -s=only -ignore **/lib/** src/OpenTelemetry.AutoInstrumentation.Native/
          git status
          git diff
          test -z "$(git status --porcelain)"
