name: Pre-release

on:
    workflow_dispatch:
    push:
        tags:
            - 'v[0-9]+.[0-9]+.[0-9]+-[a-z]+*' # e.g v1.2.3-alpha.2

jobs:
    checks:
        name: Run code checks
        uses: "./.github/workflows/checks.yml"
        secrets: inherit

    # publish_image:
    # image will be published in e2e-tests.yml workflow
    #     name: Publish Docker image
    #     uses: './.github/workflows/publish-image.yml'
    #     secrets: inherit

    e2e_tests:
        name: Run e2e tests
        needs: checks
        uses: "./.github/workflows/e2e-tests.yml"
        secrets: inherit

    version:
        name: Pre-release version info
        runs-on: ubuntu-latest
        outputs:
            is_initial: ${{ steps.is_initial.outputs.result }}
        steps:
            -   name: Determine if it is the initial version of the pre-release
                id: is_initial
                uses: actions/github-script@v7
                env:
                    TAG: ${{ github.ref_name }}
                with:
                    script: |
                        const tag = process.env.TAG;
                        const REGEXP = /^v[0-9]+.[0-9]+.[0-9]+-[a-z]+((\.|-)\d+)?$/i;
                        const match = tag.match(REGEXP);
                        const isInitial = match && !match[1] ? true : false;
                        core.info('is_initial flag value: ', isInitial);
                        return isInitial;

    label_issues:
        name: Add pre-release label to issues
        uses: './.github/workflows/label-issues-in-release.yml'
        needs: [ version ]
        if: ${{ needs.version.outputs.is_initial == 'true' }}
        with:
            tag: ${{ github.ref_name }}
            label_name: 'pre-release'
            label_description: Tasks in pre-release right now
        secrets: inherit

    # Temporary disable this step because it is broken
    # There is an issue with building web3modal deps
    upload_source_maps:
        name: Upload source maps to Sentry
        if: false
        uses: './.github/workflows/upload-source-maps.yml'
        secrets: inherit
