Version: 0.1.0
Last Updated: Unknown
| Var | Description |
|---|---|
| job_name | Job name |
| job_description | Job description |
| dirname | Name for the folder it is stored in |
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}`); } catch (error) { core.setFailed(error.message); }
In .github/workflows/main.yml:
on: [push] jobs: hello_world_job: runs-on: ubuntu-latest name: A job to say hello steps: - name: Hello world action step id: hello uses: actions/hello-world-javascript-action@v1 with: who-to-greet: 'Mona the Octocat' # Use the output from the `hello` step - name: Get the output time run: echo "The time was ${{ steps.hello.outputs.time }}"
In .github/workflows/main.yml:
on: [push] jobs: hello_world_job: runs-on: ubuntu-latest name: A job to say hello steps: # To use this repository's private action, # you must check out the repository - name: Checkout uses: actions/checkout@v2 - name: Hello world action step uses: ./ # Uses an action in the root directory id: hello with: who-to-greet: 'Mona the Octocat' # Use the output from the `hello` step - name: Get the output time run: echo "The time was ${{ steps.hello.outputs.time }}"
name: 'build-test' on: # rebuild any PRs and main branch changes pull_request: push: branches: - master - 'releases/*' jobs: build: # make sure build/ci work properly runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - run: | npm install npm run all - uses: ./ env: GITHUB_TOKEN: ${{ secrets.GithubToken }} REPO: ${{github.repository}} with: jsonFile: example.json myToken: ${{ secrets.GithubToken }} repo: ${{github.repository}}
1name: <%= job_name %>2description: <%= job_description %>3inputs:4 milliseconds: # id of input5 description: 'number of milliseconds to wait'6 required: true7 default: '1000'8outputs:9 time: # output will be available to future steps10 description: 'The message to output'11runs:12 using: 'node12'13 main: 'bundle.js'
1const core = require('@actions/core');2const github = require('@actions/github');34try {5 // Remove the following code and begin6 // `who-to-greet` input defined in action metadata file7 const nameToGreet = core.getInput('who-to-greet');8 console.log(`Hello ${nameToGreet}!`);9 const time = new Date().toTimeString();10 core.setOutput('time', time);11 // Get the JSON webhook payload for the event that triggered the workflow12 const payload = JSON.stringify(github.context.payload, undefined, 2);13 console.log(`The event payload: ${payload}`);14} catch (error) {15 core.setFailed(error.message);16}
1#!/usr/bin/env node2const path = require('path');3const fs = require('fs');4const dir = __dirname;5const cwd = process.cwd();67let filesErr = [];89const build = ({ dependencies, data, file, output, basedir }) => {10 dependencies.ejs.renderFile(file, data, {}, function (err, str) {11 // str => Rendered HTML string12 if (err) {13 filesErr.push(output);14 throw err;15 }1617 const outputFilePath = `${basedir}/${output}`;18 dependencies.fs.outputFileSync(outputFilePath, str);19 });20};2122module.exports = async function (options) {23 console.log('Bridging JavaScript Action');24 try {25 const files = await options.dependencies.recursiveReaddir(dir, ['!*.ejs']);26 const basedir = options.data.basedir27 ? path.resolve(cwd, options.data.basedir)28 : cwd;2930 // READ JSON map and replace map values dynamically31 let mapStr = fs.readFileSync(path.resolve(dir, './map.json'), 'utf-8');32 const dataKeys = Object.keys(options.data);33 for (const key of dataKeys) {34 // not trying too hard here for now35 mapStr = mapStr.replace(36 new RegExp(`{{\\s*${key}\\s*}}`, 'g'),37 options.data[key],38 );39 }4041 const map = JSON.parse(mapStr);4243 for (const file of files) {44 let filepath = file.replace(dir + '/', '');45 console.log(`\t - Scaffolding: ${filepath}`);46 build({ ...options, file, output: map[filepath], basedir });47 }4849 return options;50 } catch (err) {51 console.error(err);52 }53};
1#! /bin/bash2yarn add @actions/core @actions/github
1{2 "index.ejs": "actions/{{ dirname }}/index.js",3 "readme.ejs": "actions/{{ dirname }}/README.md",4 "action.yml.ejs": "actions/{{ dirname }}/action.yml",5 "install.sh.ejs": "actions/{{ dirname }}/bin/install.sh"6}
1# JavaScript GitHub Action23## Resources451. [Creating a JavaScript GitHub Action](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action)67## Example Action89```js10const core = require('@actions/core');11const github = require('@actions/github');1213try {14 // `who-to-greet` input defined in action metadata file15 const nameToGreet = core.getInput('who-to-greet');16 console.log(`Hello ${nameToGreet}!`);17 const time = new Date().toTimeString();18 core.setOutput('time', time);19 // Get the JSON webhook payload for the event that triggered the workflow20 const payload = JSON.stringify(github.context.payload, undefined, 2);21 console.log(`The event payload: ${payload}`);22} catch (error) {23 core.setFailed(error.message);24}25```2627## Public action2829In `.github/workflows/main.yml`:3031```yml32on: [push]3334jobs:35 hello_world_job:36 runs-on: ubuntu-latest37 name: A job to say hello38 steps:39 - name: Hello world action step40 id: hello41 uses: actions/hello-world-javascript-action@v142 with:43 who-to-greet: 'Mona the Octocat'44 # Use the output from the `hello` step45 - name: Get the output time46 run: echo "The time was ${{ steps.hello.outputs.time }}"47```4849## Private action5051In `.github/workflows/main.yml`:5253```yml54on: [push]5556jobs:57 <%= job_name %>:58 runs-on: ubuntu-latest59 name: <%= job_description %>60 steps:61 # To use this repository's private action,62 # you must check out the repository63 - name: Checkout64 uses: actions/checkout@v265 - name: <%= dirname %>66 uses: ./actions/<%= dirname %> # Uses an action in the root directory67 env:68 GITHUB_TOKEN: ${{ secrets.GithubToken }}69 REPO: ${{github.repository}}70 # Use the output from the `hello` step71 - name: Get the output time72 run: echo "The time was ${{ steps.<%= dirname %>.outputs.time }}"73```