Back to home

github-actions/

js

Version: 0.1.0

Last Updated: Unknown


JavaScript GitHub Action

Requires

VarDescription
job_nameJob name
job_descriptionJob description
dirnameName for the folder it is stored in

Resources

  1. Creating a JavaScript GitHub Action

Example Action

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); }

Public action

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 }}"

Private action

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 }}"

Secrets and other useful vars

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}}

Module files

1name: <%= job_name %>
2description: <%= job_description %>
3inputs:
4 milliseconds: # id of input
5 description: 'number of milliseconds to wait'
6 required: true
7 default: '1000'
8outputs:
9 time: # output will be available to future steps
10 description: 'The message to output'
11runs:
12 using: 'node12'
13 main: 'bundle.js'

Install


Lift generate


Repository

https://github.com/okeeffed/pkg-lift-github-actions

Sections