Skip to content

Version Packages

Version Packages #148

Workflow file for this run

name: "Check branch rules"
on:
pull_request:
jobs:
check-changesets:
name: Check if changeset release
runs-on: ubuntu-latest
outputs:
status: ${{ steps.is-changeset-release.outcome }}
steps:
- name: Skip on changeset releases
if: ${{ startsWith( github.head_ref, 'changeset-release' ) }}
id: is-changeset-release
run: exit 1
continue-on-error: true
check_branch:
name: Check branch rules
runs-on: ubuntu-latest
needs: check-changesets
if: needs.check-changesets.outputs.status == 'success' || needs.check-changesets.outputs.status == 'skipped'
steps:
- name: Throw error if wrong branch
if: ${{ github.base_ref == 'main' && github.head_ref != 'pre-release' && (!startsWith(github.head_ref,'tests/') && !startsWith(github.head_ref,'monorepo/')) }}
run: |
echo "ERROR: You can only merge to main from pre-release or from a branch starting with tests/ or monorepo/."
exit 1
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Setup Node.js 20
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: npm
- run: npm ci
- name: Ensure if merging directly into main from a non-pre-release branch it has no changesets
if: github.base_ref == 'main' && github.head_ref != 'pre-release' && (startsWith(github.head_ref,'tests/') || startsWith(github.head_ref,'monorepo/'))
run: |
npx changeset status --since=origin/main &>/dev/null && if npx changeset status --since=origin/main | grep "Packages to be bumped" &>/dev/null; then echo "Found changesets. Changesets are not allowed on direct merges, you must merge into pre-release first." && exit 1; else exit 0; fi
- name: Ensure pre-release branch is in pre-release mode
if: github.base_ref == 'pre-release' && (startsWith(github.head_ref,'release/') != true)
run: |
! npx changeset pre enter beta &>/dev/null || (echo "Pre-release branch must be in pre-release mode, please run \`npx changeset pre enter beta\` and commit the changes" && exit 1)
- name: Ensure main branch is not in pre-release mode
if: github.base_ref == 'main' || (github.base_ref == 'pre-release' && startsWith(github.head_ref, 'release/'))
run: |
npx changeset pre enter beta &>/dev/null || (echo "Main branch must not be in pre-release mode, please run \`npx changeset pre exit\` and commit the changes" && exit 1)
conclusion:
needs: check_branch
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- if: needs.check_branch.result == 'failure' || needs.check_branch.result == 'cancelled'
run: exit 1
- run: exit 0