A simple GitHub Action written in JavaScript
name: Hello world!
on:
push:
branches:
- main
jobs:
sayHelloWorld:
runs-on: ubuntu-latest
steps:
- uses: gr2m/[email protected]
Customize greeting
name: Hello world!
on:
push:
branches:
- main
jobs:
sayHelloWorld:
runs-on: ubuntu-latest
steps:
- uses: gr2m/[email protected]
with:
greeting: Gregor
Recommended reading: The official "Creating a JavaScript action" guide.
gr2m/hello-world-js-action
does the following
- It logs a "Hello, world!" to the output
- It uses the
@actions/core
module to showcase how to use dependencies - It supports a
greeting
input - It writes the total greeting to outputs
- It uses
@vercel/ncc
to compile the code and its dependencies to a single file that can be executed as a standalone GitHub Action.
The most important learning of using Node to create a GitHub Action is that you cannot require/import dependencies. When someone uses your action as part of their workflow, your action's dependencies are not automatically installed. Hence the build step using @vercel/ncc
.
Bonus: This action is releasing automatically to GitHub using semantic-release
. It also pushes updates to the v1.x
branch, which you can reliably depend on in your GitHub workflow (uses: gr2m/[email protected]
). If there should ever be a breaking release, I'll create a v2.x
branch, etc.