Skip to content

Commit 19a4078

Browse files
author
Colin Wahl
committed
update readme
1 parent 61f49fb commit 19a4078

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,68 @@ spago install github-actions-toolkit
1717

1818
## Quick start
1919

20-
There is a template for defining your own actions with found [here](https://github.com/colinwahl/hello-world-purescript-action). The template provides a starting point in order to define your own actions with these bindings!
20+
An Action is an `action.yml` file pair with a Node script.
21+
22+
This library provides PureScript bindings to [Github's Actions Toolkit](https://github.com/actions/toolkit), which provides useful tools for writing Actions.
23+
24+
To write your own Action, create an `action.yml` file which specifies the inputs, outputs, and metadata which will be used by your Action. See [GitHub's docs](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions) on the syntax of this file. Then you can use this library to write a Node script which will execute the Action based on the `action.yml` file.
25+
26+
You can use the [Hello World PureScript Action template](https://github.com/colinwahl/hello-world-purescript-action) to get started defining your own Action. The template provides a starting point in order to define your own actions with these bindings!
27+
28+
Here are some common functions which are used when defining Actions:
29+
30+
Get an input with key `username` specified by the `action.yml` file for use in the script, then log it:
31+
32+
```purescript
33+
main :: Effect Unit
34+
main = void $ runExceptT do
35+
username <- Core.getInput { name: "username", options: Just { required: true }}
36+
liftEffect $ Core.info username
37+
```
38+
39+
Use `which` to check that a tool is installed, and set the job to failed if it isn't.
40+
41+
```purescript
42+
main :: Effect Unit
43+
main = do
44+
result <- runExcaptT (IO.which { tool: "spago", check: true })
45+
case result of
46+
Left err ->
47+
Core.error "spago not found"
48+
Core.setFailed "Required tool spago is not available for this job."
49+
Right spagoPath ->
50+
Core.info $ "spago found at path " <> spagoPath
51+
pure unit -- If your job ends without failing, then it succeeded.
52+
```
53+
54+
Run an arbitrary command with `exec`.
55+
56+
```purescript
57+
main :: Effect Unit
58+
main = do
59+
result <- runExceptT (Exec.exec' "spago build")
60+
case result of
61+
Left err ->
62+
-- Something bad happened, log error and set failed
63+
Core.error $ message err
64+
Core.setFailed "Exception was thrown during spago build"
65+
Right returnCode | returnCode == 0.0 ->
66+
Core.info "spago build succeeded"
67+
Right returnCode ->
68+
Core.warning $ "spago build failed with ruturn code" <> returnCode
69+
Core.setFailed "spago exited with nonzero return code"
70+
```
71+
72+
You can find documentation for all of the functions in this library in [the docs directory](./docs).
2173

2274
## Documentation
2375

2476
GitHub Actions Toolkit documentation is stored in a few places:
2577

2678
1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-github-actions-toolkit).
2779
2. Written documentation and [the changelog](./docs/CHANGELOG.md) are kept in [the docs directory](./docs).
28-
3. Usage examples can be found in [the test suite](./test).
80+
81+
For a usage example, see the [Hello World PureScript Action template](https://github.com/colinwahl/hello-world-purescript-action). For a real-world action that uses these bindings, see [Setup PureScript](https://github.com/purescript-contrib/setup-purescript).
2982

3083
If you get stuck, there are several ways to get help:
3184

docs/01-What-Is-An-Action.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### What is an Action?
2+
3+
A [GitHub Action](https://github.com/features/actions) is a script which allows you to automate your GitHub workflows.
4+
5+
Specifically, an Action is an `action.yml` file paired with a Node script (found in `dist/index.js`). The `action.yml` file defines the inputs, outputs, and other metadata used by the Action, which the user can control in their own project. GitHub will execute your Node script with the parameters from the `action.yml` file after various events such as pushing to a branch or creating a pull request. Once you publish a GitHub Action, it can be used in other repositories to automate their workflows.
6+
7+
### What is GitHub's Actions Toolkit?
8+
9+
[GitHub's Actions Toolkit](https://github.com/actions/toolkit) is a set of Node modules which provide useful tools for creating Actions. For example:
10+
11+
`GitHub.Actions.Core` provides bindings to the [core](https://github.com/actions/toolkit/tree/main/packages/core) package, which allows you to

0 commit comments

Comments
 (0)