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 common ci #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions actions/common/pr-evaluations/example.yaml
Original file line number Diff line number Diff line change
@@ -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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider reordering jobs to match execution order

The detect-unresolved-conflicts job depends on semantic-pr-check, but semantic-pr-check is defined later in the file. Consider reordering the jobs to match their execution order for better readability and to avoid potential issues.

  semantic-pr-check:
    runs-on: ubuntu-latest

  detect-unresolved-conflicts:
    runs-on: ubuntu-latest
    needs: semantic-pr-check

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 }}
...
22 changes: 22 additions & 0 deletions actions/common/pr-evaluations/pre-commit/README.md
Original file line number Diff line number Diff line change
@@ -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]
Comment on lines +14 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Add a brief explanation of pre-commit hooks

This would be helpful for users who might not be familiar with the concept.

Suggested change
Configure pre-commit hooks in root directory of the repository in
`.pre-commit-config.yaml` file. For example, look into [pre-commit config][pcc]
Configure pre-commit hooks in the root directory of the repository using a
`.pre-commit-config.yaml` file. Pre-commit hooks are automated checks that run
before each commit, ensuring code quality and consistency. For an example
configuration, refer to the [pre-commit config][pcc] in the cookiecutter-python
repository.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Consider using a shorter reference name for the link

This would improve readability. For example, you could use '[pre-commit-config]' instead of '[pcc]'.

[pre-commit-config]: https://github.com/elixir-cloud-aai/cookiecutter-python/blob/main/%7B%7B%20cookiecutter.project_name_dashed%20%7D%7D/.pre-commit-config.yaml

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it says a shorter reference name and then suggests a longer one - but I do agree that more explicit names are generally better for readability and reusability.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the suggestion does seem a bit contradictory in terms of length. The key point here is about clarity and explicitness rather than just shortening the reference name. Using a more descriptive name like [pre-commit-config] can make the documentation clearer and more intuitive, especially for those who might not be familiar with the abbreviation [pcc]. It's about finding a balance between brevity and clarity, and in this case, a slightly longer but more descriptive name can enhance readability and understanding. Let me know if you have any other questions or need further clarification!

17 changes: 17 additions & 0 deletions actions/common/pr-evaluations/pre-commit/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...
23 changes: 23 additions & 0 deletions actions/common/pr-evaluations/semantic-pr-title/README.md
Original file line number Diff line number Diff line change
@@ -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.,
Comment on lines +4 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Consider adding an example of a well-formatted PR title

This would help users understand exactly what is expected in terms of PR title formatting.

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.

Example of a well-formatted PR title:
`feat: Add user authentication system`

`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 | |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (documentation): Add more information about the use of github_token

Explain briefly what operations this token allows the action to perform.

Suggested change
| `github_token` | The GitHub token to use for authentication | Yes | N/A | |
| `github_token` | GitHub token for authentication. Allows the action to create, update, and manage pull requests. | Yes | N/A |

`pr_title` | The title of the pull request | Yes | N/A |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (documentation): Fix alignment in the Inputs table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, an opening pipe (|) seems to be missing

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, the missing opening pipe (|) is causing the misalignment in the Inputs table. Adding the pipe at the beginning of the pr_title row will fix the alignment issue. Here's how the corrected table should look:

| 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     |

Feel free to update the documentation with this correction. Let me know if you need any further assistance!

48 changes: 48 additions & 0 deletions actions/common/pr-evaluations/semantic-pr-title/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...
19 changes: 19 additions & 0 deletions actions/common/pr-evaluations/unresolved-conflicts/README.md
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions actions/common/pr-evaluations/unresolved-conflicts/action.yaml
Original file line number Diff line number Diff line change
@@ -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
...