Skip to content

Commit

Permalink
add check for branch name in CI and with git hooks (#150)
Browse files Browse the repository at this point in the history
* add pre-commit hooks in .githooks folder

* test branch name validation github action

* correction of github action because of no on action and no jobs

* add mandatory runs-on

* Update CONTRIBUTING.md for description of supported branch names

* Make pre-commit executable

* correction of installer because of CONTRIBUTING.txt rename to CONTRIBUTING.md

Co-authored-by: Florian Omnes <[email protected]>
  • Loading branch information
jmkerloch and flomnes authored Mar 1, 2021
1 parent 6e0659e commit 1e1122e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 31 deletions.
16 changes: 16 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
LC_ALL=C

local_branch="$(git rev-parse --abbrev-ref HEAD)"

valid_branch_regex="^(feature|features|fix|release)\/[a-z0-9._-]+$"

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
fi

exit 0
16 changes: 16 additions & 0 deletions .github/workflows/branchNameValidation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Branch name validation

on:
push:

jobs:

valid-branch-name:
runs-on: ubuntu-latest

steps:
- uses: deepakputhraya/action-branch-name@master
with:
regex: '([a-z])+\/([a-z])+' # Regex the branch should match. This example enforces grouping
allowed_prefixes: 'feature,features,fix,release' # All branches should start with the given prefix
ignore: master,develop # Ignore exactly matching branch names from convention
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to contribute to Antares Simulator

## Reporting bug
- Make sure that the bug was not already reported by searching on GitHub under [Issues](https://github.com/AntaresSimulatorTeam/Antares_Simulator/issues).

- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/AntaresSimulatorTeam/Antares_Simulator/issues/new). You must provide :
- description of bug and unexpected behavior
- expected behavior
- small antares study to reproduce unexpected behavior
- Antares Simulator version and OS used


## Developpement
Antares Simulator team will be pleased to have some developpers join our project.

You can find all steps needed for compilation and installation of Antares Simulator in [INSTALL.md](INSTALL.md).

### Branch names
Currently CI is runned only for specific branch names :
- `feature/*`
- `features/*`
- `fix/*`
- `release/*`

If you create a branch with a different name no CI will be runned but you should receive an email indicating that your branch name is incorrect.

In order to avoid pushing with invalid branch name, a git hooks is provided for pre-commit check. This hooks is available in `.githooks` directory.

By default git use hooks in `.git/hooks` directory which is not under version control. You can define a new hooks directory with this command in Antares Simulator root directory :
```
git config core.hooksPath .githooks
```

### Code formatting
We're using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) to format code. Rules are defined in [.clang-format](src/.clang-format) file.
30 changes: 0 additions & 30 deletions CONTRIBUTING.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/distrib/win32/sourcefiles.inc.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ File /nonfatal /r /x build_deps ${ANTARES_SRC_DIR}\..\src\*.*
${SetOutPath} "$INSTDIR\Sources"
File ${ANTARES_SRC_DIR}\..\AUTHORS.txt
File ${ANTARES_SRC_DIR}\..\CERTIFICATE.txt
File ${ANTARES_SRC_DIR}\..\CONTRIBUTING.txt
File ${ANTARES_SRC_DIR}\..\CONTRIBUTING.md
File ${ANTARES_SRC_DIR}\..\COPYING.txt
File ${ANTARES_SRC_DIR}\..\NEWS.txt
File ${ANTARES_SRC_DIR}\..\ROADMAP.txt
Expand Down

0 comments on commit 1e1122e

Please sign in to comment.