Run JavaScript instead of shell script in GitHub Actions.
- name: Output current branch name & date
# To use latest action, specify "release-master" instead of "v0.0.2"
uses: satackey/[email protected]
id: getdata
with:
# Edit the following line to install packages required to run your script.
required-packages: axios
script: |
const core = require('@actions/core')
const axios = require('axios')
// branch
const ref = process.env.GITHUB_REF // refs/heads/master
const branch = ref.split('/').slice(-1)[0] // refs/heads/master → master
console.log(`branch: ${branch}`)
core.setOutput('branch', branch)
// date
const dateResponse = await axios('https://ntp-a1.nict.go.jp/cgi-bin/json')
/* {
"id": "ntp-a1.nict.go.jp",
"it": 0.000,
"st": 1585285722.922,
"leap": 36,
"next": 1483228800,
"step": 1
} */
const date = new Date(dateResponse.data.st)
console.log(`date: ${date}`)
core.setOutput('date', date)
# You can use datas as ${{ steps.getdata.outputs.branch }} and ${{ steps.getdata.outputs.date }}
-
package-manager
required, default:npm
The package manager used to install the required packages. Eithernpm
oryarn
. -
required-packages
optional
Line or space separated package names required to execute the scirpt.Info: The following packages are automatically installed even if you do not write them.
-
script
Required The JavaScript snippet to be executed. The await operator is supported.
PRs are accepted.
If you are having trouble or feature request, post new issue.
Execute JavaScript inline is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.