Skip to content

Commit 8e5af81

Browse files
Add and enforce a style guide (toltec-dev#96)
* Add and enforce a style guide (fixes toltec-dev#95) * Define an automatically-enforceable style guide by adding an .editorconfig file (configures shfmt). * Replace Vim modelines by Bash shebangs so that shfmt can detect all shell scripts as such, and update docs/package.md accordingly. * Add `make lint` target to run `shellcheck` and report errors. * Add `make format` target to run `shfmt` and report errors. * Add `make format-fix` target to run `shfmt` and automatically fix errors. * Fix existing formatting errors. * Check format and lint conformity in the `pr` workflow. * Mention the style guide in docs/contributing.md Co-authored-by: raisjn <[email protected]>
1 parent 64fd063 commit 8e5af81

File tree

31 files changed

+287
-142
lines changed

31 files changed

+287
-142
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Style guide for Toltec
2+
# See <https://editorconfig.org/>
3+
root = true
4+
5+
[*]
6+
# Options that apply to all source files
7+
indent_style = space
8+
indent_size = 4
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
max_line_length = 80
14+
15+
# Options for shell scripts
16+
shell_variant = bash
17+
binary_next_line = true
18+
switch_case_indent = true
19+
space_redirects = true
20+
keep_padding = false
21+
function_next_line = false
22+
23+
[build/**]
24+
ignore = true

.github/workflows/pr.yml

+42-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,55 @@ name: pr
22
on:
33
pull_request
44
jobs:
5-
pr:
6-
name: Check that a pull request correctly builds
5+
lint:
6+
name: Check that it conforms to the style guide
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout the Git repository
1010
uses: actions/checkout@v2
1111
- name: Install missing tools
1212
run: |
13-
sudo apt-get install bsdtar tree
13+
install_dir=/usr/local/bin
14+
15+
# Install shfmt
16+
shfmt_version=v3.1.2
17+
shfmt_checksum=c5794c1ac081f0028d60317454fe388068ab5af7740a83e393515170a7157dce
18+
sudo curl --location --silent --fail --tlsv1.2 --proto '=https' \
19+
--output "$install_dir"/shfmt \
20+
https://github.com/mvdan/sh/releases/download/"$shfmt_version"/shfmt_"$shfmt_version"_linux_amd64
21+
sha256sum -c <(echo "$shfmt_checksum $install_dir/shfmt") > /dev/null 2>&1
22+
sudo chmod a+x "$install_dir"/shfmt
23+
24+
# Install Shellcheck (Ubuntu’s version is too old)
25+
shellcheck_version=v0.7.1
26+
shellcheck_checksum=64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8
27+
shellcheck_arname=shellcheck.tar.xz
28+
curl --location --silent --fail --tlsv1.2 --proto '=https' \
29+
--output "$shellcheck_arname" \
30+
https://github.com/koalaman/shellcheck/releases/download/"$shellcheck_version"/shellcheck-"$shellcheck_version".linux.x86_64.tar.xz
31+
sha256sum -c <(echo "$shellcheck_checksum $shellcheck_arname") > /dev/null 2>&1
32+
tar -xf "$shellcheck_arname" --strip-components=1 \
33+
shellcheck-"$shellcheck_version"/shellcheck
34+
rm "$shellcheck_arname"
35+
chmod a+x shellcheck
36+
sudo chown root:root shellcheck
37+
sudo mv shellcheck "$install_dir"
38+
- name: Check formatting
39+
run: make format
40+
- name: Check for erroneous constructs
41+
run: make lint
42+
pr:
43+
name: Check that it builds without error
44+
runs-on: ubuntu-latest
45+
needs: lint
46+
steps:
47+
- name: Checkout the Git repository
48+
uses: actions/checkout@v2
49+
- name: Install missing tools
50+
run: sudo apt-get install bsdtar tree
1451
- name: Build packages
15-
run: |
16-
./scripts/repo-build package build https://toltec.delab.re/testing
17-
- name: Save resulting packages as artifacts
52+
run: make repo
53+
- name: Save the build output
1854
uses: actions/upload-artifact@v2
1955
with:
2056
name: repo

Makefile

+29-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Available targets:
1313
RECIPE Build any package individually.
1414
RECIPE-push Push any built package to .cache/opkg on the reMarkable.
1515
(Plug in your reMarkable first!)
16+
format Check that the source code formatting follows
17+
the style guide.
18+
format-fix Automatically reformat the source code to follow
19+
the style guide.
20+
lint Perform static analysis on the source code to find
21+
erroneous constructs.
1622
clean Remove all build artifacts.
1723

1824
Where RECIPE is one of the following available recipes:
@@ -40,7 +46,29 @@ $(PUSH_PACKAGES): %:
4046
ssh root@"${HOST}" mkdir -p .cache/opkg
4147
scp build/packages/"$(@:%-push=%)"/*.ipk root@"${HOST}":.cache/opkg
4248

49+
format:
50+
$(info ==> Checking the formatting of shell scripts)
51+
shfmt -d .
52+
53+
format-fix:
54+
$(info ==> Fixing the formatting of shell scripts)
55+
shfmt -l -w .
56+
57+
lint:
58+
$(info ==> Linting shell scripts)
59+
shellcheck $$(shfmt -f .)
60+
4361
clean:
4462
rm -rf build
4563

46-
.PHONY: help repo repo-local repo-check $(PACKAGES) $(PUSH_PACKAGES) clean
64+
.PHONY: \
65+
help \
66+
repo \
67+
repo-local \
68+
repo-check \
69+
$(PACKAGES) \
70+
$(PUSH_PACKAGES) \
71+
format \
72+
format-fix \
73+
lint \
74+
clean

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ This repository is automatically built and published every time that a commit is
5252
Since all the packaged software in Toltec is free, you can also **build them from source yourself** instead of using the pre-built binaries.
5353
The build process is fully [reproducible](https://reproducible-builds.org/), which means that you can verify that the published packages have not been tampered with during the automated build process.
5454

55-
[Learn how to build the repository from source →](docs/build.md)
55+
[Learn how to build the repository from source →](docs/building.md)
5656

5757
### Improve it
5858

5959
Your contribution is welcome for adding new packages, updating existing ones or improving the build tooling.
6060

61-
[Learn how to contribute to Toltec →](docs/contribute.md)
61+
[Learn how to contribute to Toltec →](docs/contributing.md)
File renamed without changes.

docs/contribute.md

-15
This file was deleted.

docs/contributing.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Contributing to Toltec
2+
3+
Thank you for taking time to contribute to Toltec!
4+
We welcome contributions from anyone, regarding for example [reporting bugs](#reporting-a-bug), [requesting](#request-a-package) or [adding new packages](#adding-a-new-package), [upgrading existing ones](#upgrading-a-package), [improving the docs](#improving-the-documentation), or other topics.
5+
6+
To make a request or report a bug, you simply need to [open a new issue](../../../issues/new/choose).
7+
8+
To directly propose changes, the basic procedure is to fork this repository, make the desired changes in your newly created local copy, and open a pull request.
9+
When proposing changes, please make sure that you follow the [style guide](#style-guide).
10+
After you submit your pull request, a maintainer will take time to review your changes, request modifications and then merge your changes into the repository if they fit.
11+
12+
### Common contributions
13+
14+
#### Requesting a package
15+
16+
**TODO**
17+
18+
#### Reporting a bug
19+
20+
**TODO**
21+
22+
#### Adding a new package
23+
24+
See [instructions for creating a package recipe](package.md).
25+
26+
* clone this repository
27+
* switch to `testing` branch
28+
* edit package/$PACKAGE/package, making sure to bump the version
29+
* build the package (`make $PACKAGE`), making sure everything looks ok in artifacts/package/$PACKAGE/
30+
* install the package to your tablet, verifying things work as expected
31+
* for new packages, submit a pull request with the title: [$PACKAGE][$VERSION] - New Package
32+
* for updating packages, submit a pull request with the title: [$PACKAGE][$VERSION] - Updated Package
33+
34+
#### Upgrading a package
35+
36+
**TODO**
37+
38+
#### Improving the documentation
39+
40+
**TODO**
41+
42+
### Style guide
43+
44+
All contributions must follow the project’s [style guide](../.editorconfig).
45+
Shell scripts must also comply to [Shellcheck](https://github.com/koalaman/shellcheck).
46+
Sticking to a common set of conventions makes it easier for everyone to read the source code and reduces the time spent reviewing little formatting details.
47+
48+
The code style for shell scripts will automatically be checked when you submit your pull request.
49+
You may also check it manually by running `make format` (or `make format-fix` to automatically fix any issues) at the root of the repository (you need to have [shfmt](https://github.com/mvdan/sh) installed on your computer for this to work).
50+
51+
Compliance of shell scripts to Shellcheck will also automatically be checked.
52+
To check it manually, run `make lint` at the root of the repository (you need to have Shellcheck installed on your computer for this to work).

docs/package.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
A **package recipe** is a Bash script containing metadata and instructions for building and installing a package.
44
This recipe is used by the packaging script to generate installable archives for the Opkg package manager.
55

6-
> **Note:** A recipe is not executable and does not start with a shebang line (`#!/…`).
7-
> It is not meant to be executed directly, but rather sourced by the packaging script.
8-
> To enable syntax highlighting, the file should start with the following modeline: `# vim: set ft=sh:`.
6+
> **Note:** Recipes should not be marked as executable because they are not meant to be executed directly, but rather to be sourced by the packaging script.
97
108
Sourcing a package recipe must have no side-effects, i.e. the metadata section can only execute commands which do not modify the system state, and stateful commands must be confined inside functions.
119

package/.shellcheckrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# vim: set ft=sh:
2+
# Configuration for Shellcheck in package recipes
3+
# See <https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md#rc-files>
4+
5+
# Do not warn about unguarded `cd`s since recipes are always executed
6+
# with the -e flag set
7+
disable=SC2164
8+
9+
# Do not warn about unused variables since metadata fields are expected to
10+
# not necessarily be used in the recipes
11+
disable=SC2034
12+
13+
# Do not warn about undeclared variables since recipes may use build variables
14+
# such as `srcdir` or `pkgdir`
15+
disable=SC2154

package/appmarkable/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=appmarkable
33
pkgdesc="Turn your program into a very simple app for draft"
44
url="https://github.com/LinusCDE/appmarkable"

package/calculator/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=calculator
33
pkgdesc="Touch-based calculator"
44
url=https://github.com/reHackable/Calculator

package/draft/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=draft
33
pkgdesc="Launcher which wraps around the standard interface"
44
url=https://github.com/dixonary/draft-reMarkable

package/fingerterm/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=fingerterm
33
pkgdesc="Terminal emulator with an on-screen touch keyboard"
44
url=https://github.com/dixonary/fingerterm-reMarkable

package/harmony/package

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=harmony
33
pkgdesc="Procedural sketching app"
44
url="https://rmkit.dev/apps/harmony"
@@ -15,7 +15,7 @@ sha256sums=(157ad36bc6b345763a504b6d491a47bc3aecc828a99b1bf9fd42dab980f158a4)
1515

1616
build() {
1717
pip3 install okp
18-
make -j$(nproc) harmony
18+
make -j"$(nproc)" harmony
1919
}
2020

2121
package() {

package/koreader/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=koreader
33
pkgdesc="An ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats"
44
url=https://github.com/koreader/koreader

package/mines/package

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=minesweeper
33
pkgdesc="Mine detection game"
44
url=https://rmkit.dev/apps/minesweeper
@@ -15,7 +15,7 @@ sha256sums=(157ad36bc6b345763a504b6d491a47bc3aecc828a99b1bf9fd42dab980f158a4)
1515

1616
build() {
1717
pip3 install okp
18-
make -j$(nproc) minesweeper
18+
make -j"$(nproc)" minesweeper
1919
}
2020

2121
package() {

package/nao/package

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=nao
33
pkgdesc="Nao Package Manager: opkg UI built with SAS"
44
url="https://rmkit.dev/apps/nao"
@@ -16,7 +16,7 @@ sha256sums=(f8e8fce8ef7ef968fda6b4d83fe0d8160534b1bdc808e5960422075f8c8754fe)
1616

1717
build() {
1818
pip3 install okp
19-
make -j$(nproc) nao
19+
make -j"$(nproc)" nao
2020
}
2121

2222
package() {

package/oxide/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=oxide
33
pkgdesc="Launcher application"
44
url=https://github.com/Eeems/oxide

package/plato/package

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=plato
33
pkgdesc="Document reader"
44
url=https://github.com/LinusCDE/plato
@@ -27,7 +27,7 @@ build() {
2727

2828
# 'cargo pkgid' seems to output something different with most
2929
# recent nightly builds. This adjusts the filtering.
30-
sed -i 's/version=.*$/version=$(cargo pkgid | cut -d "#" -f 2 | cut -d ":" -f 2)/g' download.sh
30+
sed -i "s/version=.*$/version=\'$(cargo pkgid | cut -d "#" -f 2 | cut -d ":" -f 2)\'/g" download.sh
3131

3232
# Use our toolchain
3333
export AR=arm-linux-gnueabihf-ar

package/recrossable/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=recrossable
33
pkgdesc="Solve crossword puzzles"
44
url=https://github.com/sandsmark/recrossable

package/remarkable-splash/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=remarkable-splash
33
pkgdesc="show a splashscreen + shutdown replacement that does not clear the screen"
44
url=https://github.com/ddvk/remarkable-splash

package/remux/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=remux
33
pkgdesc="App launcher that supports multi-tasking applications"
44
url="https://rmkit.dev/apps/remux"

package/retris/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=retris
33
pkgdesc="Tetris game"
44
url=https://github.com/LinusCDE/retris

package/rmservewacominput/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=rmservewacominput
33
pkgdesc="Serve pen input on port 33333"
44
url=https://github.com/LinusCDE/rmWacomToMouse

package/simple/package

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=simple
33
pkgdesc="Simple app script for writing scripted applications"
44
url="https://rmkit.dev/apps/sas"
@@ -15,7 +15,7 @@ sha256sums=(f8e8fce8ef7ef968fda6b4d83fe0d8160534b1bdc808e5960422075f8c8754fe)
1515

1616
build() {
1717
pip3 install okp
18-
make -j$(nproc) simple
18+
make -j"$(nproc)" simple
1919
}
2020

2121
package() {

package/xochitl/package

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22
pkgname=xochitl
33
pkgdesc="Read documents and take notes"
44
url=https://remarkable.com

scripts/install-lib

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# vim: set ft=sh:
1+
#!/usr/bin/env bash
22

33
#
44
# install-lib

0 commit comments

Comments
 (0)