Skip to content

Commit

Permalink
Custom target support
Browse files Browse the repository at this point in the history
  • Loading branch information
outring committed Nov 26, 2020
1 parent be01351 commit 48072b9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:12.14.1-alpine

LABEL com.github.actions.name="Arslanbekov Denis"
LABEL com.github.actions.description="Run npm eslint."
LABEL com.github.actions.name="NPM Target"
LABEL com.github.actions.description="Run npm target."
LABEL com.github.actions.icon="toggle-right"
LABEL com.github.actions.color="gray-dark"
LABEL homepage="https://anna.money"

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
# NPM eslint
# NPM Target Action

This GitHub Action is a utility that automatically run npm eslint.
This GitHub Action runs specified target of `package.json`, default is `test`.

## Configuration

(For help storing this see the [GitHub docs](https://help.github.com/en/articles/creating-a-github-action).)
For help storing this see the [GitHub docs](https://help.github.com/en/articles/creating-a-github-action).

Next, create a new Actions workflow in your selected GitHub repository. If you don't already have a workflow file, you'll need to create a new file titled `action.yml` in the `.github/workflows` directory of your repository. Under "Edit new file", paste the following code:
Create a new Actions workflow in your selected GitHub repository. If you don't already have a workflow file,
you'll need to create a new file titled `action.yml` in the `.github/workflows` directory of your repository.
Under "Edit new file", paste the following code:

```yaml
on: push
name: Example Workflow
jobs:
runNpmEslint:
name: Run NPM eslint
runNpmTarget:
name: Run NPM target
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run NPM eslint
uses: anna-money/github-actions-npm@v1
- name: Run NPM target
uses: anna-money/github-actions-npm@v2
with:
target: 'custom-target' # Remove `with` section to run default target `test`
```
We strongly recommend that you update the second `uses` attribute value to reference the latest tag in the [anna-money/github-actions-npm repository](https://github.com/anna-money/github-actions-npm). This will pin your workflow to a particular version of the `anna-money/github-actions-npm` action.
We strongly recommend that you update the `uses: anna-money/github-actions-npm@v2` to reference
the latest tag in the [anna-money/github-actions-npm repository](https://github.com/anna-money/github-actions-npm).
This will pin your workflow to a particular version of the `anna-money/github-actions-npm` action.

If you already have a `action.yml` file, copy and paste the above `runNpmEslint` job declaration into the `jobs` section in your existing `action.yml` file. If you wish to verify that you've pasted the above correctly, you can go into the visual editor and ensure that there are no syntax errors.
If you already have a `action.yml` file, copy and paste the above `runNpmTarget` job declaration
into the `jobs` section in your existing `action.yml` file. If you wish to verify that you've
pasted the above correctly, you can go into the visual editor and ensure that there are no syntax errors.

As shown in the above example, the workflow should run on the `push` event.

## Troubleshooting

Once your workflow has been created, the best way to confirm that the workflow is executing correctly is to create a new pull request with the workflow file and verify that the newly created action succeeds.
Once your workflow has been created, the best way to confirm that the workflow is executing correctly
is to create a new pull request with the workflow file and verify that the newly created action succeeds.

If the action fails, there may be a problem with your configuration. To investigate, dig into the action's logs to view any error messages.
If the action fails, there may be a problem with your configuration. To investigate, dig into the
action's logs to view any error messages.
14 changes: 10 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# action.yml
name: 'NPM Tests'
description: 'Run npm tests'
name: 'NPM Target'
description: 'Run npm target'
inputs:
target:
description: 'package.json target to run'
required: true
default: 'test'
outputs:
time:
description: 'The time'
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.target }}
branding:
icon: 'check-square'
icon: 'check-square'
color: 'orange'
14 changes: 4 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#!/bin/sh -l
set -e

target=$1

time=$(date)
echo "$time Run: npm install"
npm install

time=$(date)
echo "$time Run: npm run eslint"
npm run eslint

time=$(date)
echo "$time Run: npm run build --if-present"
npm run build --if-present

time=$(date)
echo "$time Run: npm test"
npm test
echo "$time Run: npm run $target"
npm run "$target"

0 comments on commit 48072b9

Please sign in to comment.