name: test
on:
  - push
  - pull_request
jobs:
  vars:
    name: Validate commit message pattern
    runs-on: ubuntu-latest
    steps:
      - name: validate commit message to allow PR
        run: |
          TITLE="${{github.event.head_commit.message}}"
          if [[ `echo $TITLE | grep -Eo "^\[[a-z]+\]"` ]]; then
            TAGNN=`echo $TITLE | grep -Eo "^\[[a-z]+\]"`
            if [ "$TAGNN" == "[major]" ]; then
              echo "::set-output name=versioning::major"
            elif [ "$TAGNN" == "[minor]" ]; then
              echo "::set-output name=versioning::minor"
            elif [ "$TAGNN" == "[patch]" ]; then
              echo "::set-output name=versioning::path"
            fi
          else
            echo "message out of pattern. needs [[major], [minor], [patch]]";
            exit 1
          fi
  # test:
  #   runs-on: ubuntu-latest
  #   needs:
  #     - vars
  #   permissions:
  #     contents: write
  #     packages: write
  #   strategy:
  #     matrix:
  #       node-version: [16.x]
  #   steps:
      
  #     - name: Git Checkout
  #       uses: actions/checkout@v3
      
  #     - name: Verify permissions
  #       run: chmod 777 package.json
      
  #     - name: Configure Node.js ${{ matrix.node-version }}
  #       uses: actions/setup-node@v1
  #       with:
  #         node-version: ${{ matrix.node-version }}
      
  #     - name: Cache node_modules
  #       id: cache-modules
  #       uses: actions/cache@v2
  #       with:
  #         path: node_modules
  #         key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
      
  #     - name: Install npm in version ${{ matrix.node-version }}
  #       if: steps.cache-modules.outputs.cache-hit != 'true'
  #       run: npm install
      
  #     - name: Run test in version ${{ matrix.node-version }}
  #       run: npm run test
  #       env:
  #         CI: true

  #     - name: "Automated Version Bump"
  #       uses: "phips28/gh-action-bump-version@master"
  #       env:
  #         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  #       with:
  #         skip-tag: "true"

  #     - name: Publish on NPM
  #       uses: mikeal/merge-release@master
  #       env:
  #         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  #         NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

  #     - name: Create release
  #       run: |
  #         RELEASE_TAG=`git describe --tags`
  #         echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
  #         gh release create ${RELEASE_TAG} --title "${RELEASE_TAG}"
