Skip to content

Commit

Permalink
Create a shared action for running a node script
Browse files Browse the repository at this point in the history
This creates a new reusable GitHub workflow that can be used to run a
node JS script from a repository. By script I expect it to be something that
is defined inside a package.json scripts object (e.g. yarn run lint:js).

It then utilises this workflow on the standardx and stylelint workflows
to simplify them.

The motivation for adding this was due to on govuk-chat deviating from
standardx to standard and then having to define our own workflow [1]. I
looked and saw other repos had also defined their own near identical
workflows [2] [3] so felt the govuk-chat need was not unique.

A demo of this working from a branch is available at: alphagov/govuk-chat#236

[1]: alphagov/govuk-chat@fbb629e
[2]: https://github.com/alphagov/whitehall/blob/main/.github/workflows/lintjs.yml
[3]: https://github.com/alphagov/whitehall/blob/main/.github/workflows/lintprettier.yml
  • Loading branch information
kevindew committed Jul 2, 2024
1 parent 82180f9 commit 541aa44
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/node-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run Node.js Script
run-name: Run ${{ inputs.script }}

on:
workflow_call:
inputs:
script:
description: 'Script to execute (typically `yarn run <script>`)'
required: true
type: string

jobs:
run-script:
name: Run Node.js Script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Run script
run: ${{ inputs.script }}
14 changes: 3 additions & 11 deletions .github/workflows/standardx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ on:
jobs:
run-standardx:
name: Run Standardx
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Run Standardx
run: yarn run standardx ${{ inputs.files }}
uses: alphagov/govuk-infrastructure/.github/workflows/node-script.yml@main
with:
script: yarn run standardx ${{ inputs.files }}
14 changes: 3 additions & 11 deletions .github/workflows/stylelint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ on:
jobs:
run-stylelint:
name: Run Stylelint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Node
uses: alphagov/govuk-infrastructure/.github/actions/setup-node@main

- name: Run Stylelint
run: yarn run stylelint ${{ inputs.files }}
uses: alphagov/govuk-infrastructure/.github/workflows/node-script.yml@main
with:
script: yarn run stylelint ${{ inputs.files }}

0 comments on commit 541aa44

Please sign in to comment.