Skip to content

Commit

Permalink
build: add linting formatting tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsgruk committed Dec 5, 2023
1 parent 9ac9382 commit b5e402f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "monthly"
19 changes: 19 additions & 0 deletions .github/shellcheck-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
info() { echo -e "\e[92m[+] $@\e[0m"; }
error() { echo >&2 -e "\e[31m[!] $@\e[0m"; exit 1; }
warn() { echo -e "\e[33m[-] $@\e[0m"; }
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

export SHELLCHECK_OPTS=(
"-s" "bash"
"-e" "2296"
"-e" "2157"
"-e" "2129"
"-e" "2154"
)

for f in "$DIR"/../**/*.yaml; do
echo $f
yq '.runs.steps[].run' "$f" | grep -v -P "^null$" | shellcheck "${SHELLCHECK_OPTS[@]}" -
done
33 changes: 33 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Lint

on:
pull_request:
push:

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4

- name: Run linters
run: |
make lint
- name: Run formatters
run: |
make format
- name: Check for modifications to generated files
run: |
if [[ -n "$(git status -s)" ]]; then
echo "Please run 'make format' then commit/push changes"
echo
git diff
exit 1
fi
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: help
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

.PHONY: lint
lint:
## lint: Lint the codebase with Prettier
npx prettier --print-width=99 --check .
bash ${CURDIR}/.github/shellcheck-actions.sh

.PHONY: format
format:
## format: Formats both Markdown documents and YAML documents to preferred repository style.
npx prettier --print-width=99 --write .
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ You can see examples of these actions in use in the following repos:
- [signal-desktop](https://github.com/snapcrafters/signal-desktop/main/.github/workflows)
- [mattermost-desktop](https://github.com/snapcrafters/mattermost-desktop/main/.github/workflows)
- [discord](https://github.com/snapcrafters/discord/main/.github/workflows)

## Contributing

If you'd like to contribute to this repository, please feel free to fork and create a pull request.

There are a few style guidelines to keep in mind:

- Code should be linted using [Prettier](https://prettier.io/). You can achieve this with `make
lint` and `make format`. The only requirements are [`npx`](https://www.npmjs.com/package/npx) and
[`shellcheck`](https://github.com/koalaman/shellcheck).
- When defining inputs/outputs in `action.yaml`, or listing them in the tables within `README.md`,
they should be listed in alphabetical order for easy reading and updating.
- Github Action inputs/outputs should be named all lowercase, separated by `-` where needed. The
applies to inputs/outputs to actions themselves, and for individual steps within the actions. For
example: `snap-name` or `token`.
- Environment variables referring to repository level secrets and variables should be named all
uppercase, and separated by `_`. For example: `SNAPCRAFTERS_BOT_COMMIT`.
- Step/job level environment variables should be named all lowercase, and separated by `_`. For
example: `snap_name` or `yaml_path`.
- All `bash` variables should be quoted.
- Scripts of all kinds, including those within actions `run:|` directives should follow the [Google
styleguide](https://google.github.io/styleguide/shellguide.html)

0 comments on commit b5e402f

Please sign in to comment.