name: Development

on:
  workflow_call:

env:
  PACKAGE_NAME: 'makaira/oxid-connect-essential'
  MODULE_PATH: 'makaira/oxid-connect-essential'

jobs:
  release:
    name: Create a new release
    runs-on: ubuntu-latest
    steps:
      - name: Clone code repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Get Composer Cache Directory
        id: composer-cache
        run: |
          echo "::set-output name=dir::$(composer config cache-files-dir)"

      - uses: actions/cache@v3
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-nodev-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-nodev-composer-

      - name: Install dependencies
        uses: php-actions/composer@v6
        with:
          command: install
          dev: no
          php_version: 8.0
          version: 2
          args: --ignore-platform-reqs --prefer-dist -no --no-progress

      - name: Import GPG key
        uses: crazy-max/ghaction-import-gpg@v2
        with:
          git_user_signingkey: true
          git_commit_gpgsign: true
        env:
          GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
          PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

      - name: Install npm dependencies
        run: yarn

      - name: Semantic release
        run: yarn semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
          GIT_AUTHOR_NAME: ${{ secrets.GIT_USERNAME }}
          GIT_AUTHOR_EMAIL: ${{ secrets.GIT_EMAIL }}
          GIT_COMMITTER_NAME: ${{ secrets.GIT_USERNAME }}
          GIT_COMMITTER_EMAIL: ${{ secrets.GIT_EMAIL }}
          GIT_CREDENTIALS: ${{ secrets.GIT_CREDENTIALS }}
