Skip to content

Commit

Permalink
feat: 🎸 Add question to add pre-commit
Browse files Browse the repository at this point in the history
βœ… Closes: #231
  • Loading branch information
abelsiqueira committed Jun 7, 2024
1 parent 4f75835 commit 67c13cb
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ AskAdvancedQuestions:
default: false

# Formatting and Linting
AddPrecommit:
when: "{{ AskAdvancedQuestions }}"
type: bool
default: true
help: Add pre-commit config? (pre-commit runs before every commit fixing your formatting and preventing bad practices)

Indentation:
when: "{{ AskAdvancedQuestions }}"
type: int
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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

0 comments on commit 67c13cb

Please sign in to comment.