Skip to content

Commit

Permalink
Merge pull request #4 from alexdewar/precommit_ci
Browse files Browse the repository at this point in the history
Precommit CI
  • Loading branch information
alexdewar authored May 28, 2024
2 parents 0d7c951 + a2e9edc commit bd46187
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Check links in Markdown files
on:
schedule:
- cron: "0 0 * * 1" # midnight every Monday
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
check-links:
Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ on:
workflow_dispatch:

jobs:
check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gaurav-nelson/github-action-markdown-link-check@v1
name: Check links in markdown files
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"

test:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -51,3 +41,10 @@ jobs:
- name: Run tests
working-directory: my_project
run: poetry run pytest

- name: Run pre-commit hooks for project
working-directory: my_project
run: |
git init
git add .
poetry run pre-commit run -a
6 changes: 4 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"project_name": "My Project",
"project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}",
"project_description": "",
"project_description": "[Description for project.]",
"author": "Jane Doe",
"author_email": "[email protected]",
"use_bsd3_licence": false,
"add_precommit_workflows": true,
"_copy_without_render": [".github"],
"__prompts__": {
"project_name": "Enter a human-readable name for the project",
"project_slug": "Enter a name for the Python package",
"project_description": "Enter a brief description of the project",
"author": "Enter your full name",
"author_email": "Enter your email address",
"use_bsd3_licence": "Whether to use Imperial's default open-source licence (BSD 3-clause)"
"use_bsd3_licence": "Whether to use Imperial's default open-source licence (BSD 3-clause)",
"add_precommit_workflows": "Add Github Actions to run pre-commit hooks (only needed for private repositories)"
}
}
4 changes: 3 additions & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

REMOVE_PATHS = [
"{% if not cookiecutter.use_bsd3_licence %}LICENSE{% endif %}"
"{% if not cookiecutter.use_bsd3_licence %}LICENSE{% endif %}",
"{% if not cookiecutter.add_precommit_workflows %}.github/workflows/pre-commit.yml{% endif %}",
"{% if not cookiecutter.add_precommit_workflows %}.github/workflows/pre-commit_autoupdate.yml{% endif %}"
]

for path in REMOVE_PATHS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Check links in Markdown files
on:
schedule:
- cron: "0 0 * * 1" # midnight every Monday
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
check-links:
Expand Down
23 changes: 5 additions & 18 deletions {{ cookiecutter.project_slug }}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
name: Test and build

on: [push, pull_request, workflow_call]
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pre-commit/[email protected]

check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gaurav-nelson/github-action-markdown-link-check@v1
name: Check links in markdown files
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"

test:
needs: qa
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
15 changes: 15 additions & 0 deletions {{ cookiecutter.project_slug }}/.github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Run pre-commit hooks

on:
push:
branches: [main]
pull_request:

jobs:
pre-commit:
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: pre-commit/[email protected]
- uses: pre-commit-ci/[email protected]
if: always()

0 comments on commit bd46187

Please sign in to comment.