name: Publish Repo

on:
  release:
    types: [published]
jobs:
  publish-library:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Setup Node.js 12.x
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install dependencies with yarn
      run: |
        echo "@fortawesome:registry=https://npm.fontawesome.com/" >> .npmrc
        echo "//npm.fontawesome.com/:_authToken=$FORTAWESOME_TOKEN" >> .npmrc
        yarn
      env:
        FORTAWESOME_TOKEN: ${{secrets.FORTAWESOME_TOKEN}}
        NODE_AUTH_TOKEN: ${{ secrets.TOKEN_REG }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This gets generated automatically
    - name: Build Library
      run: yarn build:lib
    - name: Versioning
      run : |
          echo $GITHUB_REF
          TAG=$(echo $GITHUB_REF | cut -c 11-)
          echo $TAG
          git config user.email echo $EMAIL
          git config user.name echo $NAME
          yarn version --new-version  $TAG
      env:
        EMAIL: ${{ secrets.EMAIL }}
        NAME: ${{ secrets.NAME }}
    - name: Publish to Npm Package Registry
      run: yarn publish --access public
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
        NPM_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }} # You need to set this in you
    - name: Setup Node.js 12.x
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: https://npm.pkg.github.com/
        scope: '@modyo'
    - name: Publish to GitHub Package Registry
      run: yarn publish
      env:
        NODE_AUTH_TOKEN: ${{github.token}}
