name: Publish Package to npmjs
on:
  push:
    branches:
    - master
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18.x'
          registry-url: 'https://registry.npmjs.org'
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - run: npm ci
      - name: Check for protoc-gen-js
        run: |
          if [ ! -f bin/protoc-gen-js ]; then
            echo "File not found: bin/protoc-gen-js"
            exit 1
          fi
      - name: Install Protoc
        uses: arduino/setup-protoc@v3
        with:
          repo-token: ${{ secrets.RENOVATE_TOKEN }}
      - name: Test protoc generation
        run: |
          protoc --js_out=import_style=commonjs:. --plugin=protoc-gen-js=bin/protoc-gen-js test/example.proto
      - name: Check for generated JS file
        run: |
          if [ ! -f test/example_pb.js ]; then
            echo "JS File not generated: test/example_pb.js"
            exit 1
          fi
      - name: setup git config
        run: |
          git config user.name "GitHub Actions Bot"
          git config user.email "<>"
      - uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.NPM_TOKEN }}
      - run: echo "🍏 This job's status is ${{ job.status }}."
