|
1 |
| -# Create a JavaScript Action using TypeScript |
| 1 | +# JSON array values prefixer |
2 | 2 |
|
3 |
| -Use this template to bootstrap the creation of a TypeScript action.:rocket: |
| 3 | +Prefix all values of a JSON array |
4 | 4 |
|
5 |
| -This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance. |
| 5 | +See [action.yml](./action.yml) for the list of `inputs` and `outputs`. |
6 | 6 |
|
7 |
| -If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) |
8 |
| - |
9 |
| -## Create an action from this template |
10 |
| - |
11 |
| -Click the `Use this Template` and provide the new repo details for your action |
12 |
| - |
13 |
| -## Code in Main |
14 |
| - |
15 |
| -> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance. |
16 |
| -
|
17 |
| -Install the dependencies |
18 |
| -```bash |
19 |
| -$ yarn install |
20 |
| -``` |
21 |
| - |
22 |
| -Build the typescript and package it for distribution |
23 |
| -```bash |
24 |
| -$ yarn build && yarn package |
25 |
| -``` |
26 |
| - |
27 |
| -Run the tests :heavy_check_mark: |
28 |
| -```bash |
29 |
| -$ yarn test |
30 |
| - |
31 |
| - PASS ./index.test.js |
32 |
| - ✓ throws invalid number (3ms) |
33 |
| - ✓ wait 500 ms (504ms) |
34 |
| - ✓ test runs (95ms) |
35 |
| - |
36 |
| -... |
37 |
| -``` |
38 |
| - |
39 |
| -## Change action.yml |
40 |
| - |
41 |
| -The action.yml contains defines the inputs and output for your action. |
42 |
| - |
43 |
| -Update the action.yml with your name, description, inputs and outputs for your action. |
44 |
| - |
45 |
| -See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) |
46 |
| - |
47 |
| -## Change the Code |
48 |
| - |
49 |
| -Most toolkit and CI/CD operations involve async operations so the action is run in an async function. |
50 |
| - |
51 |
| -```javascript |
52 |
| -import * as core from '@actions/core'; |
53 |
| -... |
54 |
| - |
55 |
| -async function run() { |
56 |
| - try { |
57 |
| - ... |
58 |
| - } |
59 |
| - catch (error) { |
60 |
| - core.setFailed(error.message); |
61 |
| - } |
62 |
| -} |
63 |
| - |
64 |
| -run() |
65 |
| -``` |
66 |
| - |
67 |
| -See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. |
68 |
| - |
69 |
| -## Publish to a distribution branch |
70 |
| - |
71 |
| -Actions are run from GitHub repos so we will checkin the packed dist folder. |
72 |
| - |
73 |
| -Then run [ncc](https://github.com/zeit/ncc) and push the results: |
74 |
| -```bash |
75 |
| -$ yarn package |
76 |
| -$ git add dist |
77 |
| -$ git commit -a -m "prod dependencies" |
78 |
| -$ git push origin releases/v1 |
79 |
| -``` |
80 |
| - |
81 |
| -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. |
82 |
| - |
83 |
| -Your action is now published! :rocket: |
84 |
| - |
85 |
| -See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) |
86 |
| - |
87 |
| -## Validate |
88 |
| - |
89 |
| -You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)) |
| 7 | +## Example usage |
90 | 8 |
|
91 | 9 | ```yaml
|
92 |
| -uses: ./ |
93 |
| -with: |
94 |
| - milliseconds: 1000 |
| 10 | +prefix-secrets: |
| 11 | + name: Format secrets |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout |
| 15 | + uses: actions/checkout@v2 |
| 16 | + |
| 17 | + - name: Format secrets |
| 18 | + id: task-definition |
| 19 | + |
| 20 | + with: |
| 21 | + file_path: secrets/app.json |
| 22 | + key: key |
| 23 | + prefix: prefix |
95 | 24 | ```
|
96 |
| -
|
97 |
| -See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket: |
98 |
| -
|
99 |
| -## Usage: |
100 |
| -
|
101 |
| -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 |
102 |
| -
|
103 |
| -## Helpers |
104 |
| -
|
105 |
| -If you created helpers that you consider could benefit to other actions, please consider contributing by adding them to the `helpers` folder. |
0 commit comments