name: Open release

on:
  push:
    branches:
      - main

concurrency: ${{ github.workflow }}-${{ github.ref }}

#
# TODO
# - Print versions name to commit, for easier Vercel deployments
#
jobs:
  release:
    name: Prepare release with Changesets
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
        # Tags are fetched for Changeset to distinguish from new ones while running `changeset tag`
      - name: Git fetch tags 
        run: git fetch --tags origin
      - name: Setup Node.js 16 # It was default for Changesets action, check if it can be bumped to v18
        uses: actions/setup-node@v3
        with:
          node-version: 16
      - uses: pnpm/action-setup@v2
        name: Install pnpm
      - run: pnpm install
      - name: Create Release Pull Request
        uses: changesets/action@v1
        id: changesets
        with:
          title: 🚀 Release apps
          commit: Release apps
          publish: pnpm github:release
          createGithubReleases: true
        env:
          # Use private access token so Github can trigger another workflow from this one
          GITHUB_TOKEN: ${{ secrets.PAT }}
      - name: print outputs
        run: "echo '${{toJSON(steps.changesets)}}}'"
