# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: is-valid-domain-extension NPM Package

on:
  push:
    branches: [ master ]
  pull_request:
    branches:
      - master
      - '!dependabot/**'

jobs:
  build:
    runs-on: ubuntu-latest

    # Skip Dependabot PRs for CI/CD
    if: github.actor != 'dependabot[bot]' && !startsWith(github.head_ref, 'dependabot/')

    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: lts/krypton

      - run: npm install
      - run: npm test

  publish-npm:
    needs: build
    runs-on: ubuntu-latest

    # Skip Dependabot PRs
    if: github.actor != 'dependabot[bot]' && !startsWith(github.head_ref, 'dependabot/')

    # Required for OIDC Trusted Publishing
    permissions:
      contents: read
      id-token: write # 👈 REQUIRED for Trusted Publishing

    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: lts/krypton
          registry-url: https://registry.npmjs.org/

      - run: npm install
      - run: npm publish