Skip to content

Migrate project infrastructure to Task #417

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

Merged
merged 10 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate to Poetry+Task-based version of spell check infrastructure
  • Loading branch information
per1234 committed Oct 7, 2024
commit 26e1a67d2883aa788f0a4ab331d02a7c65df941a
6 changes: 6 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ The **Node.js** version in use is defined in the `engines.node` field of [`packa

[nvm](https://github.com/nvm-sh/nvm) is recommended to easily switch between Node.js versions.

#### Python

**Python**-based tools are used for some project development operations.

The **Python** version in use is defined in the `tool.poetry.dependencies` field of [`pyproject.toml`](../pyproject.toml).

#### Task

The [**Task**](https://taskfile.dev) task runner tool is used for all common development and validation operations.
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/spell-check-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/spell-check-task.md
name: Spell Check

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
pull_request:
schedule:
# Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

spellcheck:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml

- name: Install Task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Spell check
run: |
task \
general:check-spelling
26 changes: 0 additions & 26 deletions .github/workflows/spell-check.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Check Prettier Formatting status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-prettier-formatting-task.yml)
[![Check TypeScript Configuration status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-tsconfig-task.yml)
[![Check npm status](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/check-npm-task.yml)
[![Spellcheck Status](https://github.com/arduino/arduino-lint-action/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/arduino-lint-action/actions?workflow=Spell+Check)
[![Spell Check status](https://github.com/arduino/arduino-lint-action/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/arduino-lint-action/actions/workflows/spell-check-task.yml)

[GitHub Actions](https://docs.github.com/en/free-pro-team@latest/actions) action that uses
[Arduino Lint](https://github.com/arduino/arduino-lint) to check for problems with [Arduino](https://www.arduino.cc/)
Expand Down
77 changes: 77 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tasks:
check:
desc: Check for problems with the project
deps:
- task: general:check-spelling
- task: npm:validate
- task: ts:validate
vars:
Expand All @@ -24,14 +25,36 @@ tasks:
fix:
desc: Make automated corrections to the project's files
deps:
- task: general:correct-spelling
- task: general:format-prettier
- task: markdown:toc
vars:
FILE_PATH: README.md
MAX_DEPTH: 3
- task: npm:install-deps
- task: poetry:sync
- task: ts:build

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
general:check-spelling:
desc: Check for commonly misspelled words
deps:
- task: poetry:install-deps
vars:
POETRY_GROUPS: dev
cmds:
- poetry run codespell

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/spell-check-task/Taskfile.yml
general:correct-spelling:
desc: Correct commonly misspelled words where possible
deps:
- task: poetry:install-deps
vars:
POETRY_GROUPS: dev
cmds:
- poetry run codespell --write-changes

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml
general:format-prettier:
desc: Format all supported files with Prettier
Expand Down Expand Up @@ -150,6 +173,60 @@ tasks:
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
-d "{{.INSTANCE_PATH}}"

poetry:install:
desc: Install Poetry
run: once
vars:
PYTHON_PATH:
sh: task utility:normalize-path RAW_PATH="$(which python)"
cmds:
- |
if ! which pipx &>/dev/null; then
echo "pipx not found or not in PATH."
echo "Please install: https://pipx.pypa.io/stable/installation/#installing-pipx"
exit 1
fi
- |
if ! which yq &>/dev/null; then
echo "yq not found or not in PATH."
echo "Please install: https://github.com/mikefarah/yq/#install"
exit 1
fi
- |
pipx install \
--python "{{.PYTHON_PATH}}" \
"poetry==$( \
yq \
--input-format toml \
--output-format yaml \
'.tool.poetry.group.pipx.dependencies.poetry' \
< pyproject.toml
)"

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
poetry:install-deps:
desc: |
Install dependencies managed by Poetry.
Environment variable parameters:
POETRY_GROUPS: Poetry dependency groups to install (default: install all dependencies).
run: when_changed
deps:
- task: poetry:install
cmds:
- |
poetry install \
{{if .POETRY_GROUPS}} --only {{.POETRY_GROUPS}} {{end}}

poetry:sync:
desc: Sync poetry.lock
deps:
- task: poetry:install
cmds:
- |
poetry lock \
--no-cache \
--no-update

ts:build:
desc: Build the action's TypeScript code.
deps:
Expand Down
Loading