diff --git a/actions/common/pr-evaluations/example.yaml b/actions/common/pr-evaluations/example.yaml new file mode 100644 index 0000000..2563a31 --- /dev/null +++ b/actions/common/pr-evaluations/example.yaml @@ -0,0 +1,49 @@ +--- +name: PR evaluations + +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + - edited + branches: + - main + +jobs: + detect-unresolved-conflicts: + runs-on: ubuntu-latest + needs: semantic-pr-check + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Detect unresolved conflicts + uses: elixir-cloud-aai/actions/common/unresolved-conflicts@main + + pre-commit-check: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Pre-commit check + uses: elixir-cloud-aai/actions/common/pre-commit@main + + semantic-pr-check: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Semantic PR check + uses: elixir-cloud-aai/actions/common/semantic-pr-title@main + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + pr_title: ${{ github.event.pull_request.title }} +... diff --git a/actions/common/pr-evaluations/pre-commit/README.md b/actions/common/pr-evaluations/pre-commit/README.md new file mode 100644 index 0000000..f50e2f5 --- /dev/null +++ b/actions/common/pr-evaluations/pre-commit/README.md @@ -0,0 +1,22 @@ +# Pre-Commit Evaluations + +Uses the `pre-commit` tool to run a series of checks on the repository before a +pull request is created. The checks are defined in the `.pre-commit-config.yaml` +file in the repository's root directory. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Inputs](#inputs) + +## Prerequisites + +Configure pre-commit hooks in root directory of the repository in +`.pre-commit-config.yaml` file. For example, look into [pre-commit config][pcc] +of cookiecutter-python repository. + +## Inputs + +N/A + +[pcc]: https://github.com/elixir-cloud-aai/cookiecutter-python/blob/main/%7B%7B%20cookiecutter.project_name_dashed%20%7D%7D/.pre-commit-config.yaml diff --git a/actions/common/pr-evaluations/pre-commit/action.yaml b/actions/common/pr-evaluations/pre-commit/action.yaml new file mode 100644 index 0000000..b6a57e3 --- /dev/null +++ b/actions/common/pr-evaluations/pre-commit/action.yaml @@ -0,0 +1,17 @@ +--- +name: Pre commit checks +description: Runs all pre-commit checks defined in .pre-commit-config.yaml + +runs: + using: composite + steps: + - name: Install pre-commit + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y pre-commit + + - name: Run pre-commit checks + shell: bash + run: pre-commit run --all-files +... diff --git a/actions/common/pr-evaluations/semantic-pr-title/README.md b/actions/common/pr-evaluations/semantic-pr-title/README.md new file mode 100644 index 0000000..4de46eb --- /dev/null +++ b/actions/common/pr-evaluations/semantic-pr-title/README.md @@ -0,0 +1,23 @@ +# Semantic PR Check + +Checks if the PR title follows semantic guidelines to ensure consistency and +readability. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Inputs](#inputs) + +## Prerequisites + +Ensure that the pull request titles follow semantic guidelines before using this +action. This includes starting the PR title with one of the allowed types (e.g., +`fix`, `feat`, `docs`) and ensuring that the title does not exceed 50 +characters. + +## Inputs + +| Name | Description | Required | Default | +|----------------|-----------------------------------------------|----------|---------| +| `github_token` | The GitHub token to use for authentication | Yes | N/A | | +`pr_title` | The title of the pull request | Yes | N/A | diff --git a/actions/common/pr-evaluations/semantic-pr-title/action.yaml b/actions/common/pr-evaluations/semantic-pr-title/action.yaml new file mode 100644 index 0000000..1eaa3b3 --- /dev/null +++ b/actions/common/pr-evaluations/semantic-pr-title/action.yaml @@ -0,0 +1,48 @@ +--- +name: Semantic PR Check +description: Checks if the PR title follows semantic guidelines. + +inputs: + github_token: + description: The GitHub token to use for authentication + required: true + pr_title: + description: The title of the pull request + required: true + +runs: + using: composite + steps: + - name: Check if the PR title is semantic + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + with: + types: | + fix + feat + docs + style + refactor + perf + test + build + ci + chore + revert + subjectPattern: ^(?![A-Z])(?=.{1,50}$).+$ + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + didn't match the configured pattern. Please ensure that the subject + doesn't start with an uppercase character & not have more than 50 + characters. + + - name: Check length of PR title + shell: bash + run: | + PR_TITLE="${{ inputs.pr_title }}" + if [ ${#PR_TITLE} -gt 50 ]; then + echo "The PR title is too long. Please keep it under 50 characters." + exit 1 + fi +... diff --git a/actions/common/pr-evaluations/unresolved-conflicts/README.md b/actions/common/pr-evaluations/unresolved-conflicts/README.md new file mode 100644 index 0000000..02f5875 --- /dev/null +++ b/actions/common/pr-evaluations/unresolved-conflicts/README.md @@ -0,0 +1,19 @@ +# Detect Unresolved Conflicts + +Detects unresolved merge conflicts in the repository to prevent merging code +with unresolved conflicts. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Inputs](#inputs) + +## Prerequisites + +Ensure that the repository is checked out and the latest changes are fetched +before running this action. This action will scan the repository for unresolved +merge conflict markers (`<<<<<<<`). + +## Inputs + +N/A diff --git a/actions/common/pr-evaluations/unresolved-conflicts/action.yaml b/actions/common/pr-evaluations/unresolved-conflicts/action.yaml new file mode 100644 index 0000000..cb425fe --- /dev/null +++ b/actions/common/pr-evaluations/unresolved-conflicts/action.yaml @@ -0,0 +1,19 @@ +--- +name: Detect Unresolved Conflicts +description: Detects unresolved merge conflicts in the repository. + +runs: + using: composite + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Detect unresolved merge conflicts + shell: bash + run: | + git --no-pager grep "<<<<<<<" ":(exclude).github/" || true + if git grep "<<<<<<<" ":(exclude).github/" | wc --lines; then + echo "Merge conflict markers found!" + exit 1 + fi +...