Skip to content

Commit

Permalink
feat: initial version (#1)
Browse files Browse the repository at this point in the history
feat: initial version
  • Loading branch information
gr2m authored Apr 27, 2021
1 parent 8ff3119 commit 1bdd735
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 64 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ jobs:
node-version: 14
- run: "npm ci"
- run: "npm run build"
- name: "Minimal README example"
- name: "README example"
uses: ./
id: hello_world
- name: "README example with custom greeting"
uses: ./
id: hello_world_greeting
with:
greeting: "Gregor"
- run: node -e 'assert.equal("${{ steps.hello_world.outputs.greeting }}", "Hello, world!")'
- run: node -e 'assert.equal("${{ steps.hello_world_greeting.outputs.greeting }}", "Hello, Gregor!")'
text: Hello
53 changes: 17 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Hello World Action
# Cowsay Action

> A simple GitHub Action written in JavaScript
> The cowsay GitHub Action written in JavaScript
[![Build Status](https://github.com/octokit/request-action/workflows/Test/badge.svg)](https://github.com/octokit/request-action/actions)
[![Build Status](https://github.com/octokit/cowsay-action/workflows/Test/badge.svg)](https://github.com/octokit/cowsay-action/actions)

## Usage

Expand All @@ -17,43 +17,24 @@ jobs:
sayHelloWorld:
runs-on: ubuntu-latest
steps:
- uses: gr2m/[email protected]
```
Customize greeting
```yml
name: Hello world!
on:
push:
branches:
- master

jobs:
sayHelloWorld:
runs-on: ubuntu-latest
steps:
- uses: gr2m/[email protected]
- uses: gr2m/[email protected]
with:
greeting: Gregor
text: "Hello"
```
## How it works
Recommended reading: The official "[Creating a JavaScript action](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action)" guide.
Will log
`gr2m/hello-world-js-action` does the following

1. It logs a "Hello, world!" to the output
2. It uses the [`@actions/core`](https://github.com/actions/toolkit/tree/main/packages/core) module to showcase how to use dependencies
3. It supports a `greeting` input
4. It writes the total greeting to outputs
5. 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`](https://github.com/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.
```
_______
< Hello >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
```

## License

[MIT](LICENSE)
[ISC](LICENSE)
18 changes: 7 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
name: Hello, world! (JS)
description: "A simple GitHub Action written in JavaScript"
name: Cowsay
description: "The cowsay GitHub Action written in JavaScript"
branding:
icon: "clipboard"
color: yellow
icon: "message-square"
color: purple
inputs:
greeting:
description: "Custom media type in the Accept header"
required: false
default: "world"
outputs:
greeting:
description: "The full greeting text"
text:
description: "Thing for cow to say"
required: true
runs:
using: "node12"
main: "dist/index.js"
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const core = require("@actions/core");
const cowsay = require("cowsay");

const greeting = core.getInput("greeting");
const output = `Hello, ${greeting}!`;
const text = core.getInput("text");

core.info(output);

core.setOutput("greeting", output);
core.info(
cowsay.say({
text,
})
);
73 changes: 72 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"name": "hello-world-js-action",
"version": "1.0.0",
"private": true,
"description": "A simple GitHub Action written in JavaScript",
"description": "The cowsay GitHub Action written in JavaScript",
"main": "dist/index.js",
"scripts": {
"build": "ncc build index.js -o dist"
},
"repository": "github:gr2m/hello-world-js-action",
"repository": "github:gr2m/cowsay-action",
"keywords": [
"github-action"
],
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.2.7"
"@actions/core": "^1.2.7",
"cowsay": "^1.4.0"
},
"devDependencies": {
"@semantic-release/git": "^9.0.0",
Expand Down

0 comments on commit 1bdd735

Please sign in to comment.