Skip to content

feat: add lefthooks and pr checks #1

feat: add lefthooks and pr checks

feat: add lefthooks and pr checks #1

Workflow file for this run

name: PR workflow
on:
pull_request:
types:
- opened
- synchronize
jobs:
semver-check:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Reattach HEAD
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Merge main branch to PR branch
uses: pr-mpt/actions-merge-branch@v2
with:
from: "origin/main"
- name: Get current prefix
id: branch-prefix
run: echo "::set-output name=prefix::$(echo ${{ github.head_ref }} | cut -d '/' -f 1)"
- name: Check if branch prefix is valid (major, minor, patch)
run: |
echo "Checking branch prefix..."
echo "branch prefix: ${{ steps.branch-prefix.outputs.prefix }}"
if [[ ${{ steps.branch-prefix.outputs.prefix }} != "major" && ${{ steps.branch-prefix.outputs.prefix }} != "minor" && ${{ steps.branch-prefix.outputs.prefix }} != "patch" ]]; then
echo "Branch prefix is not valid, exiting..."
exit 1
fi
echo "Branch prefix is valid"
- name: Set next version number based on prefix
run: |
echo "Getting next version number..."
if [ "${{ steps.branch-prefix.outputs.prefix }}" == "major" ]; then
echo "Bumping major version..."
npm --no-git-tag-version version major
elif [ "${{ steps.branch-prefix.outputs.prefix }}" == "minor" ]; then
echo "Bumping minor version..."
npm --no-git-tag-version version minor
elif [ "${{ steps.branch-prefix.outputs.prefix }}" == "patch" ]; then
echo "Bumping patch version..."
npm --no-git-tag-version version patch
else
echo "Error: working branch prefix not found"
exit 1
fi
- name: Setup git
run: |
echo "Setting up git..."
git config --global user.email "${{ secrets.MY_EMAIL }}"
git config --global user.name "${{ secrets.MY_USERNAME }}"
- name: Commit and push changes to working branch
run: |
echo "Committing changes..."
git add .
git commit -am "chore(release): Bump ${{ steps.branch-prefix.outputs.prefix }} version"
git push origin HEAD
check-naming:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check PR name
run: |
pr_name=$(jq -r .pull_request.title $GITHUB_EVENT_PATH)
if [[ ! $pr_name =~ ^(feat|fix|chore|docs|misc)[!]?: ]]; then
echo "error: Pull request title must start with feat/fix/chore/docs/misc and may have an optional '!' between the word and ':' for breaking changes"
exit 1
fi