Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pchynoweth committed May 24, 2020
1 parent e0fc3db commit 8f84d1f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 79 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Hello world JavaScript action
# Get npm version action

This action prints "Hello World" or "Hello" + the name of a person to greet to the log. To learn how this action was built, see "[Creating a JavaScript action](https://help.github.com/en/articles/creating-a-javascript-action)" in the GitHub Help documentation.
This action extracts the version string from the package.json file.

## Inputs

### `who-to-greet`
### `file`

**Required** The name of the person to greet. Default `"World"`.
**Optional** The package.json file. Default `"package.json"`.

## Outputs

Expand All @@ -17,7 +17,5 @@ The time we greeted you.
## Example usage

```yaml
uses: actions/hello-world-javascript-action@master
with:
who-to-greet: 'Mona the Octocat'
uses: action-get-npm-version@master
```
16 changes: 8 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: 'Hello World'
description: 'Greet someone and record the time'
name: 'Gte npm version action'
description: 'Extracts the version string from the package.json file'
inputs:
who-to-greet: # id of input
description: 'Who to greet'
required: true
default: 'World'
file:
description: 'package.json file'
required: false
default: 'package.json'
outputs:
time: # id of output
description: 'The time we we greeted you'
version:
description: 'The version string from the package.json file'
runs:
using: 'node12'
main: 'index.js'
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
const fs = require('fs');
const core = require('@actions/core');
const github = require('@actions/github');

try {
// `who-to-greet` input defined in action metadata file
const nameToGreet = core.getInput('who-to-greet');
console.log(`Hello ${nameToGreet}!`);
const time = (new Date()).toTimeString();
core.setOutput("time", time);
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
const file = core.getInput('file') || 'package.json';
console.log(`Using ${file}`);
const version = JSON.parse(fs.readFileSync(file)).version;
console.log(version);
core.setOutput("version", version);
} catch (error) {
core.setFailed(error.message);
}
110 changes: 55 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f84d1f

Please sign in to comment.