Skip to content

merge(#45): fix: add missing checkout #14

merge(#45): fix: add missing checkout

merge(#45): fix: add missing checkout #14

Workflow file for this run

name: PR workflow
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
jobs:
semver-check:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
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
if: github.event_name == 'pull_request'
uses: pr-mpt/actions-merge-branch@v2
with:
from: "origin/main"
- name: Get current prefix
if: github.event_name == 'pull_request'
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)
if: github.event_name == 'pull_request'
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" && ${{ steps.branch-prefix.outputs.prefix }} != "dependabot" ]]; then
echo "Branch prefix is not valid, exiting... allowed prefixes are major, minor, patch, dependabot"
exit 1
fi
echo "Branch prefix is valid"
- name: Set next version number based on prefix
if: github.event_name == 'pull_request'
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" ] || [ "${{ steps.branch-prefix.outputs.prefix }}" == "dependabot" ]; then
echo "Bumping patch version..."
npm --no-git-tag-version version patch
else
echo "Error: working branch prefix not found"
exit 1
fi
- name: Get version number
if: github.event_name == 'push'
id: get-version
run: echo "::set-output name=version::$(git describe --tags --abbrev=0)"
- name: Setup git
if: github.event_name == 'pull_request'
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
if: github.event_name == 'pull_request'
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
if: github.event_name == 'pull_request'
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)(\([a-zA-Z]+\))?!?:\ .*$ ]]; then
echo "error: Pull request title must start with feat/fix/chore/docs/misc, followed by optional ! for breaking changes, followed by an optional scope in parentheses, followed by a colon, followed by a space, followed by a description."
exit 1
fi
gh-release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- semver-check
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: "New release ${{ needs.semver-check.outputs.version }}"
tag_name: ${{ needs.semver-check.outputs.version }}
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- gh-release
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}