name: Release and Publish

on:
  workflow_run:
    workflows: [eslint-plugin-lob-ci]
    branches: [master]
    types: [completed]

permissions:
  id-token: write # Required for OIDC
  contents: write

jobs:
  release:
    name: Release
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    runs-on: [self-hosted, linux, x64, lob-runner]

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Automatic GitHub Release
        uses: justincy/github-action-npm-release@2.0.2
        id: release

      - uses: actions/setup-node@v4
        if: steps.release.outputs.released == 'true'
        with:
          node-version: "24"
          registry-url: "https://registry.npmjs.org"

      - name: Pin npm version
        if: steps.release.outputs.released == 'true'
        run: npm install -g npm@^11

      - name: Install
        if: steps.release.outputs.released == 'true'
        run: npm install

      - name: Publish
        if: steps.release.outputs.released == 'true'
        uses: JS-DevTools/npm-publish@v4
