name: Auto Release DuckDB Bleeding Edge

on: workflow_dispatch

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: release/duckdb-bleeding-edge
          token: ${{secrets.BRANCH_PROTECTION_TOKEN}}
      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: "@deepcrawl"
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - name: Restore keys from cache
        uses: actions/cache@v1
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Temporarily disable "include administrators" branch protection
        uses: benjefferies/branch-protection-bot@master
        if: always()
        with:
          access_token: ${{ secrets.BRANCH_PROTECTION_TOKEN }}
          enforce_admins: false
          branch: release/duckdb-bleeding-edge
      - name: Install modules with frozen lockfile and build
        run: |
          echo -e "always-auth=true\n//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
          cat ~/.npmrc
          yarn config set username $USERNAME
          yarn config set email $EMAIL
          yarn config set version-git-message "Release: v%s"
          git config --global user.name "github-actions[bot]"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
          yarn install --frozen-lockfile
          yarn standard-version
          git push --follow-tags
          yarn publish --tag provisional-release --access public
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
          GITHUB_TOKEN: ${{ secrets.UPLOAD_ARTIFACTS_TOKEN }}
          USERNAME: ${{secrets.USERNAME}}
          EMAIL: ${{secrets.EMAIL}}
          GH_TOKEN: ${{secrets.BRANCH_PROTECTION_TOKEN}}
          AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
          AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
      - name: Enable "include administrators" branch protection
        uses: benjefferies/branch-protection-bot@master
        if: always() # Force to always run this step to ensure "include administrators" is always turned back on
        with:
          access_token: ${{ secrets.BRANCH_PROTECTION_TOKEN }}
          enforce_admins: true
          branch: release/duckdb-bleeding-edge
