From 8f84d1fe4023ef0d1e5e14e748271e80e5556978 Mon Sep 17 00:00:00 2001 From: pchynoweth <24738364+pchynoweth@users.noreply.github.com> Date: Sun, 24 May 2020 10:26:06 +0100 Subject: [PATCH] Initial commit --- README.md | 12 +++-- action.yml | 16 +++---- index.js | 15 +++---- package-lock.json | 110 +++++++++++++++++++++++----------------------- 4 files changed, 74 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 390be26..8709554 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/action.yml b/action.yml index 07218b7..dc43367 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/index.js b/index.js index 723a82e..4cd34e0 100644 --- a/index.js +++ b/index.js @@ -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); } diff --git a/package-lock.json b/package-lock.json index e39bdd2..500c92d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,8 @@ "resolved": "https://registry.npmjs.org/@actions/github/-/github-1.1.0.tgz", "integrity": "sha512-cHf6PyoNMdei13jEdGPhKprIMFmjVVW/dnM5/9QmQDJ1ZTaGVyezUSCUIC/ySNLRvDUpeFwPYMdThSEJldSbUw==", "requires": { - "@octokit/graphql": "2.1.3", - "@octokit/rest": "16.28.9" + "@octokit/graphql": "^2.0.1", + "@octokit/rest": "^16.15.0" } }, "@octokit/endpoint": { @@ -23,8 +23,8 @@ "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-5.3.5.tgz", "integrity": "sha512-f8KqzIrnzPLiezDsZZPB+K8v8YSv6aKFl7eOu59O46lmlW4HagWl1U6NWl6LmT8d1w7NsKBI3paVtzcnRGO1gw==", "requires": { - "is-plain-object": "3.0.0", - "universal-user-agent": "4.0.0" + "is-plain-object": "^3.0.0", + "universal-user-agent": "^4.0.0" }, "dependencies": { "universal-user-agent": { @@ -32,7 +32,7 @@ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz", "integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==", "requires": { - "os-name": "3.1.0" + "os-name": "^3.1.0" } } } @@ -42,8 +42,8 @@ "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-2.1.3.tgz", "integrity": "sha512-XoXJqL2ondwdnMIW3wtqJWEwcBfKk37jO/rYkoxNPEVeLBDGsGO1TCWggrAlq3keGt/O+C/7VepXnukUxwt5vA==", "requires": { - "@octokit/request": "5.1.0", - "universal-user-agent": "2.1.0" + "@octokit/request": "^5.0.0", + "universal-user-agent": "^2.0.3" } }, "@octokit/request": { @@ -51,13 +51,13 @@ "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.1.0.tgz", "integrity": "sha512-I15T9PwjFs4tbWyhtFU2Kq7WDPidYMvRB7spmxoQRZfxSmiqullG+Nz+KbSmpkfnlvHwTr1e31R5WReFRKMXjg==", "requires": { - "@octokit/endpoint": "5.3.5", - "@octokit/request-error": "1.0.4", - "deprecation": "2.3.1", - "is-plain-object": "3.0.0", - "node-fetch": "2.6.0", - "once": "1.4.0", - "universal-user-agent": "4.0.0" + "@octokit/endpoint": "^5.1.0", + "@octokit/request-error": "^1.0.1", + "deprecation": "^2.0.0", + "is-plain-object": "^3.0.0", + "node-fetch": "^2.3.0", + "once": "^1.4.0", + "universal-user-agent": "^4.0.0" }, "dependencies": { "universal-user-agent": { @@ -65,7 +65,7 @@ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz", "integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==", "requires": { - "os-name": "3.1.0" + "os-name": "^3.1.0" } } } @@ -75,8 +75,8 @@ "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.0.4.tgz", "integrity": "sha512-L4JaJDXn8SGT+5G0uX79rZLv0MNJmfGa4vb4vy1NnpjSnWDLJRy6m90udGwvMmavwsStgbv2QNkPzzTCMmL+ig==", "requires": { - "deprecation": "2.3.1", - "once": "1.4.0" + "deprecation": "^2.0.0", + "once": "^1.4.0" } }, "@octokit/rest": { @@ -84,18 +84,18 @@ "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.28.9.tgz", "integrity": "sha512-IKGnX+Tvzt7XHhs8f4ajqxyJvYAMNX5nWfoJm4CQj8LZToMiaJgutf5KxxpxoC3y5w7JTJpW5rnWnF4TsIvCLA==", "requires": { - "@octokit/request": "5.1.0", - "@octokit/request-error": "1.0.4", - "atob-lite": "2.0.0", - "before-after-hook": "2.1.0", - "btoa-lite": "1.0.0", - "deprecation": "2.3.1", - "lodash.get": "4.4.2", - "lodash.set": "4.3.2", - "lodash.uniq": "4.5.0", - "octokit-pagination-methods": "1.1.0", - "once": "1.4.0", - "universal-user-agent": "4.0.0" + "@octokit/request": "^5.0.0", + "@octokit/request-error": "^1.0.2", + "atob-lite": "^2.0.0", + "before-after-hook": "^2.0.0", + "btoa-lite": "^1.0.0", + "deprecation": "^2.0.0", + "lodash.get": "^4.4.2", + "lodash.set": "^4.3.2", + "lodash.uniq": "^4.5.0", + "octokit-pagination-methods": "^1.1.0", + "once": "^1.4.0", + "universal-user-agent": "^4.0.0" }, "dependencies": { "universal-user-agent": { @@ -103,7 +103,7 @@ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-4.0.0.tgz", "integrity": "sha512-eM8knLpev67iBDizr/YtqkJsF3GK8gzDc6st/WKzrTuPtcsOKW/0IdL4cnMBsU69pOx0otavLWBDGTwg+dB0aA==", "requires": { - "os-name": "3.1.0" + "os-name": "^3.1.0" } } } @@ -128,11 +128,11 @@ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "requires": { - "nice-try": "1.0.5", - "path-key": "2.0.1", - "semver": "5.7.1", - "shebang-command": "1.2.0", - "which": "1.3.1" + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" } }, "deprecation": { @@ -145,7 +145,7 @@ "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", "requires": { - "once": "1.4.0" + "once": "^1.4.0" } }, "execa": { @@ -153,13 +153,13 @@ "resolved": "https://registry.npmjs.org/execa/-/execa-1.0.0.tgz", "integrity": "sha512-adbxcyWV46qiHyvSp50TKt05tB4tK3HcmF7/nxfAdhnox83seTDbwnaqKO4sXRy7roHAIFqJP/Rw/AuEbX61LA==", "requires": { - "cross-spawn": "6.0.5", - "get-stream": "4.1.0", - "is-stream": "1.1.0", - "npm-run-path": "2.0.2", - "p-finally": "1.0.0", - "signal-exit": "3.0.2", - "strip-eof": "1.0.0" + "cross-spawn": "^6.0.0", + "get-stream": "^4.0.0", + "is-stream": "^1.1.0", + "npm-run-path": "^2.0.0", + "p-finally": "^1.0.0", + "signal-exit": "^3.0.0", + "strip-eof": "^1.0.0" } }, "get-stream": { @@ -167,7 +167,7 @@ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", "requires": { - "pump": "3.0.0" + "pump": "^3.0.0" } }, "is-plain-object": { @@ -175,7 +175,7 @@ "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-3.0.0.tgz", "integrity": "sha512-tZIpofR+P05k8Aocp7UI/2UTa9lTJSebCXpFFoR9aibpokDj/uXBsJ8luUu0tTVYKkMU6URDUuOfJZ7koewXvg==", "requires": { - "isobject": "4.0.0" + "isobject": "^4.0.0" } }, "is-stream": { @@ -228,7 +228,7 @@ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", "requires": { - "path-key": "2.0.1" + "path-key": "^2.0.0" } }, "octokit-pagination-methods": { @@ -241,7 +241,7 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "requires": { - "wrappy": "1.0.2" + "wrappy": "1" } }, "os-name": { @@ -249,8 +249,8 @@ "resolved": "https://registry.npmjs.org/os-name/-/os-name-3.1.0.tgz", "integrity": "sha512-h8L+8aNjNcMpo/mAIBPn5PXCM16iyPGjHNWo6U1YO8sJTMHtEtyczI6QJnLoplswm6goopQkqc7OAnjhWcugVg==", "requires": { - "macos-release": "2.3.0", - "windows-release": "3.2.0" + "macos-release": "^2.2.0", + "windows-release": "^3.1.0" } }, "p-finally": { @@ -268,8 +268,8 @@ "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", "requires": { - "end-of-stream": "1.4.1", - "once": "1.4.0" + "end-of-stream": "^1.1.0", + "once": "^1.3.1" } }, "semver": { @@ -282,7 +282,7 @@ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "requires": { - "shebang-regex": "1.0.0" + "shebang-regex": "^1.0.0" } }, "shebang-regex": { @@ -305,7 +305,7 @@ "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-2.1.0.tgz", "integrity": "sha512-8itiX7G05Tu3mGDTdNY2fB4KJ8MgZLS54RdG6PkkfwMAavrXu1mV/lls/GABx9O3Rw4PnTtasxrvbMQoBYY92Q==", "requires": { - "os-name": "3.1.0" + "os-name": "^3.0.0" } }, "which": { @@ -313,7 +313,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "requires": { - "isexe": "2.0.0" + "isexe": "^2.0.0" } }, "windows-release": { @@ -321,7 +321,7 @@ "resolved": "https://registry.npmjs.org/windows-release/-/windows-release-3.2.0.tgz", "integrity": "sha512-QTlz2hKLrdqukrsapKsINzqMgOUpQW268eJ0OaOpJN32h272waxR9fkB9VoWRtK7uKHG5EHJcTXQBD8XZVJkFA==", "requires": { - "execa": "1.0.0" + "execa": "^1.0.0" } }, "wrappy": {