Skip to content

Commit

Permalink
Merge pull request #9 from jwillikers/git-hooks.nix
Browse files Browse the repository at this point in the history
Use git-hooks.nix, treefmt-nix, and nix-direnv
  • Loading branch information
jwillikers authored Oct 11, 2024
2 parents 36d5300 + da5d731 commit 8cd7381
Show file tree
Hide file tree
Showing 38 changed files with 984 additions and 892 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
max_line_length = 120
trim_trailing_whitespace = true

[*.adoc]
indent_size = unset

[*.{adoc,envrc,nix,nu}]
max_line_length = off

[{justfile,.justfile,*.just,*.rs}]
indent_size = 4
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

use flake
2 changes: 1 addition & 1 deletion .github/workflows/build-pico.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Rasbperry Pi Pico
name: Build Raspberry Pi Pico

"on":
pull_request:
Expand Down
38 changes: 0 additions & 38 deletions .github/workflows/check-image-metadata.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/clippy-attiny85.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ jobs:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
# - name: Lint Rust code with Clippy
# run: nix develop --command 'cd boards/attiny85; cargo clippy'
1 change: 1 addition & 0 deletions .github/workflows/flake-lock-updater.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ jobs:
pr-labels: |
automated
dependencies
pr-reviewers: ${{ github.repository_owner }}
pr-title: "chore: update flake.lock"
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
28 changes: 0 additions & 28 deletions .github/workflows/format-just.yaml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/link-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Check URLs with Lychee

"on":
pull_request:
branches: [main]
paths:
- .github/workflows/link-checker.yaml
- flake.lock
- '**.adoc'
push:
branches: [main]
paths:
- .github/workflows/link-checker.yaml
- flake.lock
- '**.adoc'
schedule:
# Run once a month on the 14th.
- cron: "0 0 14 * *"
workflow_dispatch:

jobs:
link-checker:
runs-on: ubuntu-latest
steps:
- name: Restore lychee cache
uses: actions/cache@v4
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Convert the Asciidoc files to html
run: nix develop --command asciidoctor ./**/*.adoc
- name: Run lychee on the generated site
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: nix develop --command lychee --cache --no-progress --verbose ./**/*.html
24 changes: 0 additions & 24 deletions .github/workflows/rustfmt.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: Test check-image-metadata.nu
name: Test update-nix-direnv.nu
"on":
pull_request:
branches: ["main"]
paths:
- .github/workflows/test-check-image-metadata.yaml
- .github/workflows/test-update-nix-direnv.yaml
- flake.lock
- check-image-metadata.nu
- check-image-metadata-tests.nu
- update-nix-direnv.nu
- update-nix-direnv-tests.nu
push:
branches: ["main"]
paths:
- .github/workflows/test-check-image-metadata.yaml
- .github/workflows/test-update-nix-direnv.yaml
- flake.lock
- check-image-metadata.nu
- check-image-metadata-tests.nu
- update-nix-direnv.nu
- update-nix-direnv-tests.nu
workflow_dispatch:

jobs:
test-check-image-metadata:
test-update-nix-direnv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Run the Nushell tests
run: nix develop --command nu check-image-metadata-tests.nu
run: nix develop --command nu update-nix-direnv-tests.nu
21 changes: 21 additions & 0 deletions .github/workflows/treefmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check files with treefmt
"on":
pull_request:
branches: ["main"]
push:
branches: ["main"]

jobs:
treefmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Run treefmt
run: nix develop --command treefmt --ci
- uses: reviewdog/action-suggester@v1
with:
fail_on_error: true
github_token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
tool_name: treefmt
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
name: Pre-commit auto-update
name: Update nix-direnv

"on":
schedule:
# Once a month on the 2nd
- cron: "0 0 2 * *"
- cron: "0 0 16 * *"
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
pre-commit-autoupdate:
update-nix-direnv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Update pre-commit hooks
run: nix develop --command pre-commit autoupdate
- name: Run pre-commit hooks
run: nix develop --command pre-commit run --all-files
- name: Update nix-direnv to the latest version
run: nix develop --command nu update-nix-direnv.nu
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
assignees: ${{ github.repository_owner }}
branch: "update/pre-commit-hooks"
commit-message: "chore(deps): Update pre-commit hooks"
title: "chore(deps): Update pre-commit hooks"
branch: "update/nix-direnv"
commit-message: "chore(deps): Update nix-direnv"
title: "chore(deps): Update nix-direnv"
token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ target/

# Nix
result

# git-hooks.nix
/.pre-commit-config.yaml

# Asciidoctor
*.html

# lychee
.lycheecache
48 changes: 34 additions & 14 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ set shell := ["nu", "-c"]

default: build

alias fmt := format

format: just-fmt rustfmt

rustfmt:
^rustfmt **/*.rs
alias c := check

just-fmt:
^just --fmt --unstable
check: && format
#!/usr/bin/env nu
^yamllint .
^asciidoctor '**/*.adoc'
^lychee --cache **/*.html

alias b := build

Expand All @@ -22,6 +20,11 @@ build board="attiny85" profile="dev":
^cargo objcopy -- -O ihex "pwm-fan-controller-{{ board }}.hex"
}

alias fmt := format

format:
treefmt

alias f := run
alias flash := run
alias r := run
Expand All @@ -43,8 +46,21 @@ run board="attiny85" profile="dev" method="": (build board profile)
} else if "{{ method }}" == "elf2uf2-rs" {
^elf2uf2-rs --deploy $"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico"
} else if "{{ method }}" == "probe-rs" {
^probe-rs run --chip RP2040 --protocol swd $"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico"
^probe-rs run \
--chip RP2040 \
--protocol swd \
$"boards/{{ board }}/target/thumbv6m-none-eabi/($build_type)/pwm-fan-controller-pico"
}
} else if "{{ board }}" == "qt-py-ch32v203" {
let build_type = {
if "{{ profile }}" == "dev" {
"debug"
} else {
"{{ profile }}"
}
}
^wchisp flash \
$"boards/{{ board }}target/riscvimac-unknown-none-elf/($build_type)/pwm-fan-controller-qt-py-ch32v203"
}

alias p := package
Expand All @@ -53,16 +69,20 @@ alias pack := package
package board="attiny85":
^nix build ".#pwm-fan-controller-{{ board }}"

alias t := test

test:
nu update-nix-direnv-tests.nu

alias u := update
alias up := package
alias up := update

update:
^nix flake update
cd "{{ justfile_directory() }}/boards/attiny85"
^cargo update
cd "{{ justfile_directory() }}/boards/pico"
^cargo update

strip-image-metadata:
#!/usr/bin/env nu
check-image-metadata --strip
cd "{{ justfile_directory() }}/boards/qt-py-ch32v203"
^cargo update
nu update-nix-direnv.nu
Loading

0 comments on commit 8cd7381

Please sign in to comment.