Skip to content

Commit 8ce59dd

Browse files
author
Colin Wahl
committed
add Core documentation
1 parent ae1732b commit 8ce59dd

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

docs/02-Core.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Github.Actions.Core
2+
3+
> Core functions for setting results, logging, registering secrets and exporting variables across actions
4+
5+
This module exposes bindings to the [@actions/core module](https://github.com/actions/toolkit/tree/main/packages/core).
6+
7+
## Usage
8+
9+
#### Inputs/Outputs
10+
11+
Action inputs can be read with `getInput`. Outputs can be set with `setOutput` which makes them available to be mapped into inputs of other actions to ensure they are decoupled.
12+
13+
```purescript
14+
void $ runExceptT do
15+
myInput <- Core.getInput' "inputName"
16+
liftEffect $ Core.setOutput "outputKey" "outputVal"
17+
```
18+
19+
#### Exporting variables
20+
21+
Since each step runs in a separate process, you can use `exportVariable` to add it to this step and future steps environment blocks.
22+
23+
```purescript
24+
Core.exportVariable { key: "envVar", val: "Val"}
25+
```
26+
27+
#### Setting a secret
28+
29+
Setting a secret registers the secret with the runner to ensure it is masked in logs.
30+
31+
```purescript
32+
example = do
33+
Core.setSecret "myPassword"
34+
```
35+
36+
#### PATH Manipulation
37+
38+
To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use `addPath`. The runner will prepend the path given to the jobs PATH.
39+
40+
```purescript
41+
example = do
42+
Core.addPath "/path/to/mytool"
43+
```
44+
45+
#### Exit codes
46+
47+
You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.
48+
49+
```purescript
50+
task = do stuff that might fail here
51+
52+
example = do
53+
case runExceptT task of
54+
Left err -> Core.setFailed $ "Action failed with error " <> message err
55+
Right _ -> mempty -- task succeded
56+
```
57+
58+
#### Logging
59+
60+
Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the [Step Debug Logs](../../docs/action-debugging.md#step-debug-logs).
61+
62+
```js
63+
task = do
64+
myInput <- Core.getInput' "input"
65+
Core.debug ""
66+
core.debug('Inside try block');
67+
isDebug <- Core.isDebug
68+
liftEffect $ when isDebug do
69+
-- handle debug messages here
70+
Core.info "output to actions build log"
71+
72+
73+
example = do
74+
case runExceptT task of
75+
Left err -> Core.error $ "task failed with error " <> message err -- Note: action may still succeed
76+
Right _ -> mempty
77+
```
78+
79+
This library can also wrap chunks of output in foldable groups.
80+
81+
```js
82+
example = do
83+
-- manually wrap output
84+
Core.startGroup "do some function"
85+
doSomeFunction
86+
Core.endGroup
87+
88+
-- wrap an asynchronous function call
89+
result <- Core.group
90+
{ name: "do something async"
91+
, fn: do
92+
-- get the result from something asynchronous in the Aff monad
93+
result <- taskInAff
94+
pure result
95+
}
96+
```
97+
98+
#### Action state
99+
100+
You can use this library to save state and get state for sharing information between a given wrapper action:
101+
102+
**action.yml**
103+
```yaml
104+
name: 'Wrapper action sample'
105+
inputs:
106+
name:
107+
default: 'GitHub'
108+
runs:
109+
using: 'node12'
110+
main: 'main.js'
111+
post: 'cleanup.js'
112+
```
113+
114+
In action's `main.js`:
115+
116+
```js
117+
Core.saveState { name: "pidToKill", value: "12345" }
118+
```
119+
120+
In action's `cleanup.js`:
121+
```js
122+
pid <- Core.getState "pidToKill"
123+
-- Do something with pid
124+
```

src/GitHub/Actions/Core.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ foreign import startGroupImpl :: EffectFn1 String Unit
142142
startGroup :: String -> Effect Unit
143143
startGroup = runEffectFn1 startGroupImpl
144144

145-
foreign import endGroupImpl :: EffectFn1 String Unit
145+
foreign import endGroupImpl :: Effect Unit
146146

147147
-- | End an output group.
148-
endGroup :: String -> Effect Unit
148+
endGroup :: Effect Unit
149149
endGroup = runEffectFn1 endGroupImpl
150150

151151
foreign import saveStateImpl :: EffectFn2 String String Unit

0 commit comments

Comments
 (0)