on:
  push:
    branches:
      - main
  workflow_dispatch:
name: release-please
env:
  ACTION_NAME: release-please-action
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: 20
    - name: install
      run: npm ci
    - name: build
      run: npm run build
    - name: Create PR with dist
      uses: googleapis/code-suggester@v4
      with:
        command: pr
        upstream_repo: release-please-action
        upstream_owner: googleapis
        description: Build dist
        title: "chore: build dist"
        message: "chore: build dist"
        labels: automated pr
        branch: build-dist
        force: true
        git_dir: .
        fork: true
      env:
        ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
  release-please-release:
    runs-on: ubuntu-latest
    needs: [build]
    steps:
      - uses: googleapis/release-please-action@main
        id: release
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          release-type: node
          skip-github-pull-request: true
      - uses: actions/checkout@v4
      - name: tag major and patch versions
        run: |
          git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com
          git remote add gh-token "https://${{ secrets.GITHUB_TOKEN}}@github.com/googleapis/release-please-action.git"
          git tag -d v${{ steps.release.outputs.major }} || true
          git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git push origin :v${{ steps.release.outputs.major }} || true
          git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
          git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
          git push origin v${{ steps.release.outputs.major }}
          git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}
        if: ${{ steps.release.outputs.release_created }}
  release-please-pr:
    runs-on: ubuntu-latest
    needs:
      - build
      - release-please-release
    steps:
      - id: release-pr
        uses: googleapis/release-please-action@main
        with:
          token: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
          release-type: node
          fork: true
          skip-github-release: true
