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

Add question to add pre-commit #238

Merged
merged 2 commits into from
Jun 7, 2024
Merged
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
35 changes: 23 additions & 12 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Essential questions
PackageName:
type: str
help: Package name without '.jl'
Expand Down Expand Up @@ -36,22 +37,18 @@ License:
- MPL-2.0
default: MIT

# Optional
AskAdvancedQuestions:
type: bool
help: Ask further questions? You can stop now with the minimum and use the default values for code of conduct, indentation, and package tests.
default: false

AddAllcontributors:
when: "{{ AskAdvancedQuestions }}"
type: bool
default: true
help: Add allcontributors to the package?

AddCodeOfConduct:
# Formatting and Linting
AddPrecommit:
when: "{{ AskAdvancedQuestions }}"
type: bool
default: true
help: Add a CODE_OF_CONDUCT.md file from Contributor Covenant? {{ AuthorEmail }} will be listed as contact point.
help: Add pre-commit config? (pre-commit runs before every commit fixing your formatting and preventing bad practices)

Indentation:
when: "{{ AskAdvancedQuestions }}"
Expand All @@ -60,6 +57,13 @@ Indentation:
validator: "{% if Indentation <= 0 %}Indentation must be positive{% endif %}"
default: 2

# CI
SimplifiedPRTest:
when: "{{ AskAdvancedQuestions }}"
type: bool
help: (Simplified PR Test) Do you want to limit the Pull Request test to a single configuration (ubuntu + latest stable Julia)? This will make the PR tests run faster, but might miss OS-specific or LTS specific errors.
default: true

AddMacToCI:
when: "{{ AskAdvancedQuestions }}"
type: bool
Expand All @@ -75,16 +79,23 @@ RunJuliaNightlyOnCI:
type: bool
help: Package tests run on Julia version {{ JuliaMinVersion }} and on the latest stable release. Do you also want to run them on the nightly version?

SimplifiedPRTest:
UseCirrusCI:
when: "{{ AskAdvancedQuestions }}"
type: bool
help: Add CirrusCI to run the package tests on FreeBSD?

# General
AddAllcontributors:
when: "{{ AskAdvancedQuestions }}"
type: bool
help: (Simplified PR Test) Do you want to limit the Pull Request test to a single configuration (ubuntu + latest stable Julia)? This will make the PR tests run faster, but might miss OS-specific or LTS specific errors.
default: true
help: Add allcontributors to the package?

UseCirrusCI:
AddCodeOfConduct:
when: "{{ AskAdvancedQuestions }}"
type: bool
help: Add CirrusCI to run the package tests on FreeBSD?
default: true
help: Add a CODE_OF_CONDUCT.md file from Contributor Covenant? {{ AuthorEmail }} will be listed as contact point.

_skip_if_exists:
- "**/*.jl"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% raw %}name: Copier Update
name: Copier Update

on:
schedule:
Expand All @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.COPIER_PAT }}
token: {% raw %}${{ secrets.COPIER_PAT }}{% endraw %}
- uses: julia-actions/setup-julia@v2
with:
version: "1"
Expand All @@ -33,15 +33,17 @@ jobs:
find . -name "*.rej" | xargs rm -f
echo -e '```' >> /tmp/body.md
git diff
{% if AddPrecommit %}
- name: Run pre-commit to run the formatters
run: |
pip install pre-commit
pre-commit run -a || true # Ignore pre-commit errors
{% endif %}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.COPIER_PAT }}
token: {% raw %}${{ secrets.COPIER_PAT }}{% endraw %}
commit-message: ":robot: COPIERTemplate.jl update"
title: "[AUTO] COPIERTemplate.jl update"
body-path: /tmp/body.md
Expand All @@ -50,5 +52,5 @@ jobs:
labels: configuration, automated pr, no changelog
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"{% endraw %}
{% raw %}echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"{% endraw %}
{% raw %}echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"{% endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ on:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
group: {% raw %}${{ github.workflow }}-${{ github.ref }}{% endraw %}
cancel-in-progress: {% raw %}${{ startsWith(github.ref, 'refs/pull/') }}{% endraw %}

jobs:
{% if AddPrecommit %}
lint:
name: Linting
runs-on: ubuntu-latest
Expand All @@ -36,11 +37,12 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
key: {% raw %}${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}{% endraw %}
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: SKIP=no-commit-to-branch pre-commit run -a
{% endif %}
link-checker:
name: Link checker
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
labels: chore
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
{% raw %}echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"{% endraw %}
{% raw %}echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"{% endraw %}
4 changes: 3 additions & 1 deletion template/docs/src/90-developer.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You will create branches and push to `origin`, and you will fetch and update you
Install a plugin on your editor to use [EditorConfig](https://editorconfig.org).
This will ensure that your editor is configured with important formatting settings.

{% if AddPrecommit %}
We use [https://pre-commit.com](https://pre-commit.com) to run the linters and formatters.
In particular, the Julia code is formatted using [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl), so please install it globally first:

Expand Down Expand Up @@ -57,6 +58,7 @@ pre-commit run -a
```

**Now, you can only commit if all the pre-commit tests pass**.
{% endif %}

## Testing

Expand Down Expand Up @@ -114,7 +116,7 @@ We try to keep a linear history in this repo, so it is important to keep your br
Try to create "atomic git commits" (recommended reading: [The Utopic Git History](https://blog.esciencecenter.nl/the-utopic-git-history-d44b81c09593)).

- Make sure the tests pass.
- Make sure the pre-commit tests pass.
{% if AddPrecommit %}- Make sure the pre-commit tests pass.{% endif %}
- Fetch any `main` updates from upstream and rebase your branch, if necessary:

```bash
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ template_options = Dict(
"RunJuliaNightlyOnCI" => true,
"SimplifiedPRTest" => true,
"UseCirrusCI" => true,
"AddPrecommit" => true,
)

function test_diff_dir(dir1, dir2)
Expand Down
Loading