name: 🚀⚡ Liberando versiones

on:
    push:
        branches:
            - release/production
jobs:
    ############ RELEASE ############
    release-prod:
        if: ${{ !github.event.act }}
        name: Release
        runs-on: ubuntu-latest
        steps:
            - name: Checkout
              uses: actions/checkout@v3

            - name: Set output
              id: vars
              run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT

            - name: Setup Node
              uses: actions/setup-node@v3
              with:
                  node-version: 16.x
                  cache: 'yarn'
                  registry-url: https://registry.npmjs.org/

            - run: corepack enable

            - name: Set User
              run: git config --global user.email "leifer.contacto@gmail.com" && git config --global user.name "Leifer Mendez"

            - name: Install NPM Dependencies
              run: yarn install --immutable --network-timeout 300000

            - name: Set CHANGELOG
              run: yarn release

            - name: get-npm-version
              id: package-version
              uses: martinbeentjes/npm-get-version-action@main

            - name: Build Package
              run: yarn build:full

            - name: Release @bot-whatsapp/bot
              run: yarn node ./scripts/release.js --name=bot --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/cli
              run: yarn node ./scripts/release.js --name=cli --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/create-bot-whatsapp
              run: yarn node ./scripts/release.js --name=create-bot-whatsapp --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/database
              run: yarn node ./scripts/release.js --name=database --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/provider
              run: yarn node ./scripts/release.js --name=provider --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/contexts
              run: yarn node ./scripts/release.js --name=contexts --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release @bot-whatsapp/portal
              run: yarn node ./scripts/release.js --name=portal --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.NPM_TOKEN }}"

            - name: Release Github
              run: yarn node ./scripts/github.js --version="${{ steps.package-version.outputs.current-version}}" --token="${{ secrets.OCTO_TOKEN }}"

            - name: Commit Versioning & Push changes
              if: github.event_name == 'push'
              uses: stefanzweifel/git-auto-commit-action@v4
              with:
                  commit_message: 'chore(version): launch release 🚀 "${{ steps.package-version.outputs.current-version}}"'
                  branch: dev
