name: Continuous integration icons

on:
  push:
    branches:
      - main
    paths:
      - icons/**/*.svg

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

jobs:
  create-release:
    if: github.repository == 'lucide-icons/lucide' && startsWith(github.event.head_commit.message, 'feat(icons)')
    runs-on: ubuntu-latest
    outputs:
      VERSION: ${{ steps.new-version.outputs.NEW_VERSION }}

    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
      - uses: actions/setup-node@v6
        with:
          cache: 'pnpm'
          node-version-file: 'package.json'

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Fetch tags
        run: git fetch --all --tags

      - name: Get latest tag
        id: latest-tag
        run: echo "LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT

      - name: Log latest tag
        run: echo '${{ steps.latest-tag.outputs.LATEST_TAG }}'

      - name: Check if we can patch
        run: pnpm semver $LATEST_TAG -i minor
        env:
          LATEST_TAG: ${{ steps.latest-tag.outputs.LATEST_TAG }}

      - name: Create new version
        id: new-version
        run: echo "NEW_VERSION=$(pnpm semver $LATEST_TAG -i minor)" >> $GITHUB_OUTPUT
        env:
          LATEST_TAG: ${{ steps.latest-tag.outputs.LATEST_TAG }}

      - name: Check output
        run: |
          echo '${{ steps.new-version.outputs.NEW_VERSION }}'
          echo '${{ steps.change-log.outputs.CHANGE_LOG }}'

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ steps.new-version.outputs.NEW_VERSION }}
          name: Version ${{ steps.new-version.outputs.NEW_VERSION }}
          generate_release_notes: true

  start-release:
    if: github.repository == 'lucide-icons/lucide'
    needs: create-release
    uses: './.github/workflows/release.yml'
    secrets: inherit
    with:
      version: ${{ needs.create-release.outputs.VERSION }}
