name: CD-preview

on:
  push:
    branches-ignore:
      - dependabot/*

env:
  CI: true
jobs:
  dev-release-npm:
    name: "NPM release under a dev tag"
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2.1.0
      - name: Prepare for publication to GitHub Packages
        uses: actions/setup-node@v1
        with:
          node-version: "12.x"
          registry-url: "https://registry.npmjs.org"
      - name: Determine npm tag
        # Remove non-alphanumeric characters
        # See https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
        run: echo "::set-env name=TAG_SLUG::$(echo ${GITHUB_REF#refs/heads/} | tr -cd '[:alnum:]-')"
      - run: npm ci
      - name: Prepare prerelease version
        run: |
          git config user.name $GITHUB_ACTOR
          git config user.email gh-actions-${GITHUB_ACTOR}@github.com
          # Make sure the prerelease is tagged with the branch name, and that they are sorted by build:
          ./node_modules/.bin/lerna version prerelease --preid=$TAG_SLUG-$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER --yes
      - run: ./node_modules/.bin/lerna bootstrap --ci
      - run: ./node_modules/.bin/lerna run build
      - run: ./node_modules/.bin/lerna publish --dist-tag "$TAG_SLUG"
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
      - run: |
          echo "Package published. To install, run:"
          echo ""
          echo "    npm install @inrupt/solid-client-authn-browser@$TAG_SLUG"
