Create a JavaScript Action with tests, linting, workflow, publishing, and versioning
Go to file Use this template
Bryan MacFarlane 41775a4da8 rename workflow 2019-09-26 20:34:36 -04:00
.github/workflows rename workflow 2019-09-26 20:34:36 -04:00
node_modules/@actions/core update prod dependencies 2019-09-22 07:10:13 -04:00
.eslintrc.json start readme 2019-09-11 02:21:19 -04:00
.gitignore update gitignore 2019-09-20 07:47:55 -04:00
LICENSE Initial commit 2019-09-10 08:11:44 -04:00
README.md rename workflow 2019-09-26 20:34:36 -04:00
action.yml Rename actions.yml to action.yml 2019-09-11 09:11:33 -04:00
index.js start readme 2019-09-11 02:21:19 -04:00
index.test.js starting... 2019-09-11 01:44:28 -04:00
package-lock.json update deps 2019-09-20 07:52:17 -04:00
package.json update deps 2019-09-20 07:52:17 -04:00
wait.js starting... 2019-09-11 01:44:28 -04:00

GitHub Actions status

Create a JavaScript Action

Use this template to bootstrap the creation of a JavaScript action.🚀

This template includes tests, linting, a validation workflow, publishing, and versioning guidance.

If you are new, there's also a simpler introduction. See the Hello World JavaScript Action

This walk through takes you through creation, testing and publishing the action.

This walk through takes you through creation, testing and publishing the action.

Create an action from this template

Click the Use this Template and provide the new repo details for your action

Code in Master

Install the dependencies

$ npm install

Run the tests ✔️

$ npm test

 PASS  ./index.test.js
  ✓ throws invalid number (3ms)wait 500 ms (504ms)test runs (95ms)

...

Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the documentation

Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

const core = require('@actions/core');
...

async function run() {
  try { 
      ...
  } 
  catch (error) {
    core.setFailed(error.message);
  }
}

run()

See the toolkit documentation for the various packages.

Publish to a distribution branch

Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).

Comment out node_modules in .gitignore and create a releases/v1 branch

# comment this out distribution branches
# node_modules/
$ git checkout -b releases/v1
$ git commit -a -m "prod dependencies"
$ npm prune --production
$ git add node_modules
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1

Your action is now published! 🚀

See the versioning documentation

Validate

You can now validate the action by referencing the releases/v1 branch

uses: actions/javascript-action@releases/v1
with:
  milliseconds: 1000

See the actions tab for runs of this action! 🚀

Usage:

After testing you can create a v1 tag to reference the stable and tested action

uses: actions/javascript-action@v1
with:
  milliseconds: 1000