name: Upload Technical Debt Metrics to Google Sheets

on:
  push:
    branches:
      - master
      - "[0-9].[0-9]*"

jobs:
  config:
    runs-on: "ubuntu-22.04"
    outputs:
      has-secrets: ${{ steps.check.outputs.has-secrets }}
    steps:
      - name: "Check for secrets"
        id: check
        shell: bash
        run: |
          if [ -n "${{ (secrets.GSHEET_KEY != '' ) || '' }}" ]; then
            echo "has-secrets=1" >> "$GITHUB_OUTPUT"
          fi

  process-and-upload:
    needs: config
    if: needs.config.outputs.has-secrets
    runs-on: ubuntu-22.04
    name: Generate Reports
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install Dependencies
        run: npm install
        working-directory: ./superset-frontend

      - name: Run Script
        env:
          SPREADSHEET_ID: "1oABNnzxJYzwUrHjr_c9wfYEq9dFL1ScVof9LlaAdxvo"
          SERVICE_ACCOUNT_KEY: ${{ secrets.GSHEET_KEY }}
        run: npm run lint-stats
        continue-on-error: true
        working-directory: ./superset-frontend
