Skip to content

Commit

Permalink
feat: add nx run-many and deprecated actions
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Mar 13, 2024
1 parent 23872ca commit ea4f6f2
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 14 deletions.
64 changes: 57 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ This is a collection of reusable composite actions for GitHub Actions workflows.
- [pr-validate-title-conventional](#pr-validate-title-conventional)
- [stale](#stale)
- [toggle-label](#toggle-label)
- [Nx](#nx)
- [nx-cache](#nx-cache)
- [nx-run-many](#nx-run-many)
- [Miscellaneous](#miscellaneous)
- [bundlewatch](#bundlewatch)
- [cache-nx](#cache-nx)
- [deprecated](#deprecated)

## General usage

Expand Down Expand Up @@ -819,6 +822,43 @@ with the `pull_request` event.
| true | `label` | The label to toggle. | `failing tests` | – |
| true | `toggle` | Whether to toggle the label on or off. | `true` | `auto` |

### Nx

#### nx-cache

[Source](nx-cache/action.yml)

Save and restore the [Nx](https://nx.dev/) cache.

1. Runs [actions/cache] and caches `./node_modules/.cache/nx`

#### nx-run-many

[Source](nx-run-many/action.yml)

Run `nx run-many` with the provided arguments.

1. Runs [nx-cache]
2. Runs `<prefix> nx run-many <args> --target=<build>`.

##### Example

```yaml
- uses: myparcelnl/actions/nx-run-many@v4
with:
target: 'build'
prefix: 'yarn'
args: '--all --runner=cloud'
```

##### Inputs

| Required | Name | Description | Example | Default |
| -------- | -------- | --------------------------------- | ---------------------- | ------- |
| Yes | `target` | The target to run. | `build` | - |
| No | `prefix` | The prefix to use with `nx`. | `yarn` | - |
| No | `args` | Arguments to pass to the command. | `--all --runner=cloud` | - |

### Miscellaneous

#### bun-install
Expand Down Expand Up @@ -867,20 +907,30 @@ If you don't pass the `config` input, it will look for the `bundlewatch` key in
| No | config | Path to the BundleWatch config file. | `.bundlewatch.json` | – |
| Yes | token | BundleWatch token to use. | `${{ secrets.BUNDLEWATCH_TOKEN }}` | – |

#### cache-nx
#### deprecated

[Source](cache-nx/action.yml)
[Source](deprecated/action.yml)

Save and restore the [Nx](https://nx.dev/) cache.

1. Runs [actions/cache] and caches `./node_modules/.cache/nx`
Mark something as deprecated. This will add a warning to the workflow run.

##### Example

```yaml
- uses: myparcelnl/actions/cache-nx@v4
- uses: myparcelnl/actions/deprecated@v4
with:
name: 'my-name/my-action'
replacement: 'my-name/my-new-action'
reason: 'It is no longer maintained.'
```

##### Inputs

| Required | Name | Description | Example | Default |
| -------- | ------------- | --------------------------------------- | ----------------------------- | ------- |
| Yes | `name` | Name of the thing to mark as deprecated | `my-name/my-action` | – |
| No | `replacement` | The replacement | `my-name/my-new-action` | – |
| No | `reason` | The reason why it is deprecated | `It is no longer maintained.` | – |

[BundleWatch]: https://bundlewatch.io/
[Codecov]: https://codecov.io
[Github app]: https://docs.github.com/en/developers/apps
Expand Down
12 changes: 5 additions & 7 deletions cache-nx/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ description: 'Cache Nx build results'
runs:
using: composite
steps:
- name: 'Cache Nx'
uses: actions/cache@v4
- uses: myparcelnl/actions/deprecated@v4
with:
path: node_modules/.cache/nx
key: ${{ runner.os }}-cache-nx-${{ hashFiles('nx.json') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-nx-${{ hashFiles('nx.json') }}-
${{ runner.os }}-cache-nx-
name: 'cache-nx'
replacement: 'nx-cache'

- uses: myparcelnl/actions/nx-cache@v4
32 changes: 32 additions & 0 deletions deprecated/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Mark as deprecated'
description: 'Mark something as deprecated'

inputs:
name:
description: 'Name of the thing to mark as deprecated'
required: true

replacement:
description: 'The replacement'
required: false

reason:
description: 'The reason why it is deprecated'
required: false

runs:
using: composite
steps:
- name: 'Mark as deprecated'
shell: bash
#language=bash
run: |
msg="${{ inputs.name }} is deprecated and will be removed in the future."
if [ -n "${{ inputs.replacement }}" ]; then
msg="${msg} Use ${{ inputs.replacement }} instead."
fi
if [ -n "${{ inputs.reason }}" ]; then
msg="${msg} Reason: ${{ inputs.reason }}"
fi
21 changes: 21 additions & 0 deletions nx-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Cache Nx'
description: 'Cache Nx build results'

outputs:
cache-hit:
description: 'A boolean value to indicate an exact match was found for the primary key'
value: ${{ steps.cache.outputs.cache-hit}}

runs:
using: composite
steps:
- name: 'Cache Nx'
uses: actions/cache@v4
id: cache
with:
path: |
node_modules/.cache/nx
.nx
key: ${{ runner.os }}-nx-cache-${{ hashFiles('nx.json', '**/project.json') }}
restore-keys: |
${{ runner.os }}-nx-cache-
31 changes: 31 additions & 0 deletions nx-run-many/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'Run many nx actions'
description: 'Run multiple actions in parallel'

inputs:
target:
description: 'The target to run'
required: true

args:
description: 'The arguments to pass to the target'
required: false
default: ''

prefix:
description: 'The prefix to use for the commands'
required: false
default: ''

runs:
using: composite
steps:
- uses: myparcelnl/actions/nx-cache@v4

- name: 'Run'
shell: bash
#language=bash
run: |
${{ inputs.prefix }} nx run-many \
--output-style=static \
--target="${{ inputs.target }}" \
${{ inputs.args }}

0 comments on commit ea4f6f2

Please sign in to comment.