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

build: Add CI and Task for formatting R and Rust code #73

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: format

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Rust
run: rustup component add rustfmt

- name: Install `air`
run: curl -LsSf https://github.com/posit-dev/air/releases/latest/download/air-installer.sh | sh

- name: Check formatting in R
run: air format . --check

- name: Check formatting in Rust
run: cargo fmt --all --check --manifest-path src/rust/Cargo.toml
17 changes: 17 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,20 @@ tasks:
desc: Accept all test snapshots. (Shortcut to accept snapshots after running tests)
cmds:
- Rscript -e 'testthat::snapshot_accept()'

install-air:
desc: Install Air to format R code.
cmds:
- curl -LsSf https://github.com/posit-dev/air/releases/latest/download/air-installer.sh | sh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is downloaded every time task fmt runs, which is bad. @eitsupi do you know why this is executed while other setup tasks are skipped? Is it because this is a curl command and there's no way to know if it's outdated?


fmt:
desc: Format all R and Rust code.
sources:
- "{{.R_SOURCE}}"
- "{{.RUST_SOURCE}}"
- tests/**/*
deps:
- install-air
cmds:
- air format .
- cargo fmt --all --manifest-path src/rust/Cargo.toml
7 changes: 7 additions & 0 deletions air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[format]
line-width = 80
indent-width = 2
indent-style = "space"
line-ending = "auto"
persistent-line-breaks = true
exclude = ["R/000-wrappers.R"]
Loading