# Workflow allows you to install / uninstall dependency.
# After executing, select the action and the dependency.

name: Install or uninstall dependency

on:
  workflow_dispatch:
    inputs:
      action:
        type: choice
        description: Action
        required: true
        options: 
        - install
        - uninstall
      dependency:
        description: Dependency
        required: true
      

jobs:
  create-release:
    name: Install or uninstall
    runs-on: ubuntu-latest

    steps:
      - name: Check out repository
        uses: actions/checkout@v4
        #with:
         # token: ${{ secrets.PAT }}

      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'
          registry-url: 'https://registry.npmjs.org'

      # Configure Git
      - name: Git configuration
        run: |
          git config user.email "83647248+github-actions[bot]@users.noreply.github.com"
          git config user.name "GitHub Actions"

      - name: NPM
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
        run: |
          npm ${{ github.event.inputs.action }} ${{ github.event.inputs.dependency }}

      # Commit changes
      - name: Commit
        run: |
          git add "package.json"
          git add "package-lock.json"
          git commit -m "${{ github.event.inputs.action }} ${{ github.event.inputs.dependency }} dependency"
          
      # Push git repository changes
      - name: Push changes to repository
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git push origin HEAD:master && git push --tags
