Skip to content

Commit

Permalink
Merge pull request #417 from per1234/task
Browse files Browse the repository at this point in the history
Migrate project infrastructure to Task
  • Loading branch information
per1234 authored Oct 7, 2024
2 parents 5673b0c + 90d503f commit f68c663
Show file tree
Hide file tree
Showing 23 changed files with 5,226 additions and 465 deletions.
56 changes: 50 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ 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.

Follow the installation instructions here:<br />
https://taskfile.dev/installation/

### 2. Install dependencies

To work on the codebase you have to install all the dependencies:

```
npm install
task npm:install-deps
```

### 3. Coding
Expand All @@ -32,26 +45,25 @@ Make sure to write or update tests for your work when appropriate.
Format the code to follow the standard style for the project:

```
npm run format
task general:format-prettier
```

### 5. Run tests

To run tests set the environment variable `GITHUB_TOKEN` with a valid Personal Access Token and then:

```
npm run test
task js:test
```

See the [official Github documentation][pat-docs] to learn more about Personal Access Tokens.

### 6. Build

It is necessary to compile the code before it can be used by GitHub Actions. Remember to run these commands before committing any code changes:
It is necessary to compile the code before it can be used by GitHub Actions. Remember to run this commands before committing any code changes:

```
npm run build
npm run pack
task build
```

### 7. Commit
Expand All @@ -60,6 +72,38 @@ Everything is now ready to make your contribution to the project, so commit it t

Thanks!

## Common Development Operations

### Running Checks

Checks and tests are set up to ensure the project content is functional and compliant with the established standards.

You can run the full suite of checks by running the following command from a terminal in a path under the repository:

```text
task check
```

### Automatic Corrections

Tools are provided to automatically bring the project into compliance with some of the required checks.

You can make these automatic fixes by running the following command from a terminal in a path under the repository:

```text
task fix
```

### Other Operations

Individual tasks are provided for each specific common validation and automated correction operation. The convenience `check` and `fix` tasks run all of the relevant individual tasks, so it is not necessary for the contributor to use the individual tasks. However, in some cases it may be more efficient to run the single specific task of interest.

You can learn the names of all the available tasks by running the following command from a terminal in a path under the repository:

```text
task --list
```

## Release workflow

Instructions for releasing a new version of the action:
Expand Down
129 changes: 129 additions & 0 deletions .github/workflows/check-npm-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-npm-task.md
name: Check npm

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-npm-task.ya?ml"
- "**/.npmrc"
- "**/package.json"
- "**/package-lock.json"
- "Taskfile.ya?ml"
pull_request:
paths:
- ".github/workflows/check-npm-task.ya?ml"
- "**/.npmrc"
- "**/package.json"
- "**/package-lock.json"
- "Taskfile.ya?ml"
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
- 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
validate:
name: validate (${{ matrix.project.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
- path: .

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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

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

- name: Validate package.json
run: |
task \
--silent \
npm:validate \
PROJECT_PATH="${{ matrix.project.path }}"
check-sync:
name: check-sync (${{ matrix.project.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
matrix:
project:
- path: .

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

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

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

- name: Install npm dependencies
run: |
task \
npm:install-deps \
PROJECT_PATH="${{ matrix.project.path }}"
- name: Check package-lock.json
run: |
git \
diff \
--color \
--exit-code \
"${{ matrix.project.path }}/package-lock.json"
169 changes: 0 additions & 169 deletions .github/workflows/check-npm.yml

This file was deleted.

Loading

0 comments on commit f68c663

Please sign in to comment.