# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: publish-casper-js-sdk

on:
  release:
    types: [created]

jobs:
  publish:

    runs-on: ubuntu-20.04

    strategy:
      matrix:
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
        node-version: [16.x]

    steps:
    - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@5b949b50c3461bbcd5a540b150c368278160234a #v3.4.0
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: 'https://registry.npmjs.org'
    - run: npm install
    - name: Publish to NPM
      run: npm publish --access public
      env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
    - name: Get latest release version number
      id: get_version
      uses: battila7/get-version-action@d97fbc34ceb64d1f5d95f4dfd6dce33521ccccf5 #v2.3.0
    - run: cp dist/lib.js casper-js-sdk.v${{ steps.get_version.outputs.version }}.js
    - uses: meeDamian/github-release@7ae19492500104f636b3fee4d8103af0fed36c8e #v2.0.3
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        files: casper-js-sdk.v${{ steps.get_version.outputs.version }}.js
        allow_override: true
