# 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: release - Build and Publish

on:
  push:
    branches: [ release ]

jobs:
  publish:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - name: Build and WNS publish
        run: |
          git config --global user.email "npm@dxos.org"
          git config --global user.name "DXOS"
          
          yarn install
          yarn build
          yarn test
          yarn lint

          # Uncomment for NPM publishing.
          VERSION="`cat lerna.json | grep '"version":' | awk '{ print $2 }' | sed 's/[",]//g' | cut -d'-' -f1`"
          git push --delete origin "v$VERSION" || true
          yarn lerna version $VERSION --no-git-tag-version -y
          git commit -am "v$VERSION"
          git push
          git tag -f "v$VERSION"
          git push --tags -f
          yarn lerna publish from-package --force-publish -y

          # Publish to WNS
          yarn wire profile init --name $WIRE_PROFILE --template-url "$WIRE_PROFILE_URL"
          scripts/deploy_apps_to_wns.sh
        env:
          NODE_AUTH_TOKEN: ${{secrets.npm_token}}
          WIRE_WNS_USER_KEY: ${{secrets.wns_user_key}}
          WIRE_WNS_BOND_ID: ${{secrets.wns_bond_id}}
          WIRE_PROFILE_URL: ${{secrets.wire_profile_url}}
          WIRE_PROFILE: ci
