name: CD

on: delete

env:
  CI: true
jobs:
  unpublish-npm:
    runs-on: ubuntu-18.04
    if: github.event.ref_type == 'branch'
    steps:
    - name: Prepare for unpublication from npm
      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.event.ref }}" | tr -cd '[:alnum:]-')"
    - name: Remove npm tag for the deleted branch
      run: npm dist-tag rm @solid/lit-pod $TAG_SLUG
      env:
        NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
    - run: echo "Package tag \`$TAG_SLUG\` unpublished."
