Skip to content
Permalink
Newer
Older
100644 93 lines (61 sloc) 2.17 KB
July 21, 2021 12:59
1
## Setup
June 4, 2021 09:44
2
3
> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
4
July 21, 2021 12:59
5
Install the dependencies
6
June 4, 2021 09:44
7
```bash
8
$ npm install
9
```
10
11
Build the typescript and package it for distribution
July 21, 2021 12:59
12
June 4, 2021 09:44
13
```bash
July 21, 2021 12:59
14
$ npm run package
June 4, 2021 09:44
15
```
16
July 21, 2021 12:59
17
Run the tests :heavy_check_mark:
18
June 4, 2021 09:44
19
```bash
20
$ npm test
21
22
PASS ./index.test.js
23
✓ throws invalid number (3ms)
24
wait 500 ms (504ms)
25
test runs (95ms)
26
27
...
28
```
29
30
## Change action.yml
31
32
The action.yml contains defines the inputs and output for your action.
33
34
Update the action.yml with your name, description, inputs and outputs for your action.
35
36
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
37
38
## Change the Code
39
40
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
41
42
```javascript
43
import * as core from '@actions/core';
44
...
45
46
async function run() {
July 21, 2021 12:59
47
try {
June 4, 2021 09:44
48
...
July 21, 2021 12:59
49
}
June 4, 2021 09:44
50
catch (error) {
51
core.setFailed(error.message);
52
}
53
}
54
55
run()
56
```
57
58
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
59
60
## Publish to a distribution branch
61
July 21, 2021 12:59
62
Actions are run from GitHub repos so we will checkin the packed dist folder.
June 4, 2021 09:44
63
64
Then run [ncc](https://github.com/zeit/ncc) and push the results:
July 21, 2021 12:59
65
June 4, 2021 09:44
66
```bash
67
$ npm run package
68
$ git add dist
69
$ git commit -a -m "prod dependencies"
70
$ git push origin releases/v1
71
```
72
73
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
74
July 21, 2021 12:59
75
Your action is now published! :rocket:
June 4, 2021 09:44
76
77
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
78
79
## Validate
80
81
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
82
83
```yaml
84
uses: ./
85
with:
86
milliseconds: 1000
87
```
88
89
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
90
91
## Usage:
92
93
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action