# SPDX-FileCopyrightText: 2023 - 2024 Ali Sajid Imami
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT

---
name: Next semantic-release version
on:
    workflow_call:
        outputs:
            new-release-published:
                description: Indicates whether a new release will be published. The value is a string, either 'true' or 'false'.
                value: ${{ jobs.get-next-version.outputs.new-release-published }}
jobs:
    get-next-version:
        name: Get next release version
        runs-on: ubuntu-latest
        outputs:
            new-release-published: ${{ steps.get-next-version.outputs.new-release-published }}
        steps:
            - name: Checkout
              uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
              with:
                fetch-depth: 0
                persist-credentials: false
            - name: Configure Node.js
              uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
              with:
                node-version: lts/*
            - name: Cache action npm dependencies
              uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
              id: cache-node-modules
              with:
                path: ${{ runner.temp }}/.semantic-release-action_next-release-version/node_modules
                key: |
                    semantic-release-action/next-release-version-${{ runner.os }}-node-${{ hashFiles('${{ github.action_path }}/package-lock.json') }}
            - name: Install dependencies on cache miss
              if: steps.cache-node-modules.outputs.cache-hit != 'true'
              run: |
                npm install -g semantic-release semantic-release-export-data
              shell: bash
            - name: Get next release version
              id: get-next-version
              env:
                GITHUB_TOKEN: ${{secrets.ACTIONS_PAT_GITHUB}}
              run: |
                : calculate next semantic-release version
                semantic-release \
                --dry-run \
                --plugins semantic-release-export-data \
                --verify-conditions semantic-release-export-data \
                --verify-release '' \
                --generate-notes semantic-release-export-data \
                --prepare '' \
                --publish '' \
                --success '' \
                --fail ''
              shell: bash
