Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lefthooks and pr checks #37

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/eslint-check.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: PR Semver
name: PR workflow

on:
pull_request:
types: [labeled]
branches:
- main
types:
- opened
- synchronize

jobs:
update-version:
if: ${{ github.event.label.name == 'semver' }}
semver-check:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Reattach HEAD
Expand All @@ -29,8 +30,8 @@ jobs:
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..."
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"
Expand All @@ -44,7 +45,7 @@ jobs:
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
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
Expand All @@ -64,3 +65,18 @@ jobs:
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)(\([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
30 changes: 18 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ Thank you for considering contributing to this project! These guidelines provide

We use GitHub's issue tracker to track issues and ideas for the project. If you have a suggestion or have found a bug, please open an issue in the issue tracker.

## Branching
## Versioning

> 🚨 **Do not change the version number manually**; we have workflows in place to automatically update the version number based on the type of the change (based on branch name, *see below*).

We use semantic versioning for this project. You can find more information about it [here](https://semver.org/spec/v2.0.0.html). To determine the version number of your changes, use the following guidelines:

- `major change`: adding functionality or refactoring that **MAY** break all functionality unless appropriate changes are made to the project that uses the package. It'll update version by `1.x.x`.
- `minor change`: adding functionality or refactoring that changes some functionality but does not affect the basic functionality. It'll update version by `x.1.0`.
- `patch change`: fixing a bug that does not affect the basic functionality. It'll update version by `x.x.1`.
- `dependabot change`: *special automatic update*; updating dependencies by GitHub's dependabot. It'll update version by `x.x.1`.

## Branching out

> Following those rules will be checked by **lefthooks** and if you don't follow them, you will not be able to push your changes to the repository.

We encourage you to create a new branch for each new feature or change that you are working on. Please do not create an aggregate branch with multiple changes. When naming your branch, use the following prefixes to indicate the type of change:

Expand All @@ -22,25 +35,18 @@ For example:

## Pull Requests and Commits

> Following those rules will be checked by **workflow** and if you don't follow them, you will not be able to push your changes to the repository.

When creating a pull request (PR) or committing code changes, please use the following prefixes to indicate the type of change:

- `feat:` for new features
- `feat:` for new features (`feat!:` for breaking changes)
- `bug:` for bug fixes
- `docs:` for documentation only changes (e.g. `CONTRIBUTING.md` or `README.md`)
- `chore:` for changes that do not affect the meaning of the code (e.g. build process or package manager updates)
- `misc:` for changes that do not fit into any of the above categories

Before merging a PR, please consider rebasing your branch to clear the commit list, which will leave a cleaner repository after merging.

## Versioning

We use semantic versioning for this project. You can find more information about it [here](https://semver.org/spec/v2.0.0.html). To determine the version number of your changes, use the following guidelines:

- `major change`: adding functionality or refactoring that **MAY** break all functionality unless appropriate changes are made to the project that uses the package
- `minor change`: adding functionality or refactoring that changes some functionality but does not affect the basic functionality
- `patch change`: fixing a bug that does not affect the basic functionality

To set the version number for your changes, use the `semver` label on your PR and base the version number on the prefix of your branch (e.g. `major/new-feature` would result in a major version bump). **Do not change the version number manually**.

## Overall

Thank you again for considering contributing to this project. We appreciate your time and effort in making this project better.
14 changes: 14 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pre-push:
commands:
check-branch-name:
run: |
branch_name=$(git symbolic-ref --short HEAD)
if [[ ! $branch_name =~ ^(major/|minor/|patch/) ]]; then
echo "error: Branch name must start with major/, minor/, or patch/"
exit 1
fi

pre-commit:
commands:
linter:
run: npm run eslint
203 changes: 200 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mochawesome-json-to-md",
"version": "1.1.0",
"version": "1.2.0",
"description": "A repository containing a script to convert JSON reports generated by MochAwesome to Mardown",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -35,6 +35,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^8.8.0"
"eslint": "^8.8.0",
"lefthook": "^1.5.2"
}
}
Loading