From 4c92207ab61b92f5630befdfc844c93466651630 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 9 Sep 2024 11:47:01 -0400 Subject: [PATCH 1/3] ENH: Add "Commit Message Check" composite action Co-authored-by: James Butler Co-authored-by: Steve Pieper --- action.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..0a8ac47 --- /dev/null +++ b/action.yml @@ -0,0 +1,38 @@ +name: "Commit Message Check" +description: "Check Commit Messages match Slicer style" +inputs: + token: + description: + "GitHub access token used to list and check all pull request commits" + required: true +runs: + using: "composite" + steps: + - name: Check Commit Prefix + uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee # v2.0.0 + with: + pattern: "^(ENH|PERF|BUG|STYLE|DOC|COMP): ([A-Z])+" + flags: "gm" + excludeDescription: "true" # optional: this excludes the description body of a pull request + excludeTitle: "true" # optional: this excludes the title of a pull request + error: + 'The first line has to start with a commit prefix, followed by a colon + and space, and then followed by a message with a capital letter (e.g + "ENH: Add support for awesome feature"). For more details on other + requirements, see + https://slicer.readthedocs.io/en/latest/developer_guide/style_guide.html#commits' + checkAllCommitMessages: "true" # optional: this checks all commits associated with a pull request + accessToken: ${{ inputs.token }} # github access token is only required if checkAllCommitMessages is true + + - name: Check Line Length + uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee # v2.0.0 + with: + pattern: "^[^#].{1,78}$" + error: + "The maximum line length of 78 characters is exceeded. For more + details, see + https://slicer.readthedocs.io/en/latest/developer_guide/style_guide.html#commits" + excludeDescription: "true" # optional: this excludes the description body of a pull request + excludeTitle: "true" # optional: this excludes the title of a pull request + checkAllCommitMessages: "true" # optional: this checks all commits associated with a pull request + accessToken: ${{ inputs.token }} # github access token is only required if checkAllCommitMessages is true From 344366f7a43a0fe220c94dc63416972435c6350d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 9 Sep 2024 11:47:31 -0400 Subject: [PATCH 2/3] DOC: Update README adding "Usage" and "History" sections --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index a61d0bb..ae873e0 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,44 @@ This GitHub composite action verifies that commit messages conform to the [Slicer commit style](https://slicer.readthedocs.io/en/latest/developer_guide/style_guide.html#commits) guidelines. + +## Usage + +To automatically enforce the Slicer commit message style during pull requests or +pushes to the `main` branch, create a workflow file at +`.github/workflows/check-commit-message.yml` with the following content: + +```yaml +name: "Commit Message Check" +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + push: + branches: + - main + +permissions: + contents: read + pull-requests: read + +jobs: + check-commit-message: + name: Check Commit Message + uses: slicer/slicer-check-commit-message-action@v1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} +``` + +This workflow will trigger commit message checks on relevant pull request events +or when changes are pushed to the `main` branch. + +## History + +This action was originally implemented by +[@jamesobutler](https://github.com/jamesobutler), +[@pieper](https://github.com/pieper) and [@jcfr](https://github.com/jcfr) in the +Slicer repository under `.github/workflows/commit-message.yml`. From 2ed60176e4aaab6ec8a98fa505ae2ec67155cf75 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 9 Sep 2024 11:48:54 -0400 Subject: [PATCH 3/3] ENH: Add Continuous Integration infrastructure --- .github/dependabot.yml | 11 +++++++ .github/workflows/check-commit-message.yml | 27 ++++++++++++++++ .github/workflows/ci.yml | 36 ++++++++++++++++++++++ .pre-commit-config.yaml | 27 ++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/check-commit-message.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6c4b369 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + actions: + patterns: + - "*" diff --git a/.github/workflows/check-commit-message.yml b/.github/workflows/check-commit-message.yml new file mode 100644 index 0000000..55c56b6 --- /dev/null +++ b/.github/workflows/check-commit-message.yml @@ -0,0 +1,27 @@ +name: "Commit Message Check" +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + push: + branches: + - main + +permissions: + contents: read + pull-requests: read + +jobs: + check-commit-message: + runs-on: ubuntu-latest + steps: + # Check out the repository to ensure the step below has access to action source code. + - uses: actions/checkout@v4 + + # Run the commit message validation action using the source code checked out in the previous step. + - uses: ./ + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7bfffa3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pre-commit: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - uses: pre-commit/action@v3.0.1 + + test-action: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./ + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..35c5d76 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.5.0" + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.1.0" + hooks: + - id: prettier + types_or: [yaml, markdown, html, css, scss, javascript, json] + args: [--prose-wrap=always] + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: "0.28.0" + hooks: + - id: check-dependabot + - id: check-github-actions + - id: check-github-workflows