diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ac22b57 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every week + interval: "monthly" diff --git a/.github/shellcheck-actions.sh b/.github/shellcheck-actions.sh new file mode 100644 index 0000000..d44381e --- /dev/null +++ b/.github/shellcheck-actions.sh @@ -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 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..f8cf312 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..afd3da6 --- /dev/null +++ b/Makefile @@ -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 . diff --git a/README.md b/README.md index f72c539..738e83b 100644 --- a/README.md +++ b/README.md @@ -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)