Skip to content

Commit a719362

Browse files
committed
feat: alternative starter action
1 parent 5538178 commit a719362

File tree

17 files changed

+8880
-4733
lines changed

17 files changed

+8880
-4733
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/test.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
name: "units-test"
1+
##
2+
# Run unit test and the action itself
3+
##
4+
name: Unit Test
25
on:
36
pull_request:
47
push:
58
branches:
69
- main
7-
- 'releases/*'
10+
- feature/**
811

912
jobs:
1013
# unit tests
11-
units:
14+
unit:
1215
runs-on: ubuntu-latest
1316
steps:
1417
- uses: actions/checkout@v2
@@ -20,6 +23,7 @@ jobs:
2023
runs-on: ubuntu-latest
2124
steps:
2225
- uses: actions/checkout@v2
26+
- run: npm ci
2327
- uses: ./
2428
with:
2529
milliseconds: 1000

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
# Dependencies
12
node_modules/
23

4+
# Compiled project files
5+
dist/
6+
37
# Editors
48
.vscode/
59
.idea/

CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
11
# Create a JavaScript Action
2+
> An opinionated alternative template to [`actions/javascript-action`](https://github.com/actions/javascript-action) to bootstrap the creation of a JavaScript action. 🚀
23
3-
<p align="center">
4-
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a>
5-
</p>
4+
<a href="https://github.com/github-developer/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/github-developer/javascript-action/actions/workflows/test.yml/badge.svg"></a>
5+
<a href="https://img.shields.io/github/v/release/github-developer/javascript-action"><img alt="release" src="https://img.shields.io/github/v/release/github-developer/javascript-action"></a>
6+
<a href="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg"><img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg"></a>
67

7-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
8+
Use this template to bootstrap the creation of a JavaScript action. :rocket: Alternative to [`actions/javascript-action`](https://github.com/actions/javascript-action).
89

9-
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
10+
This template includes [release automation](.github/workflows), [tests](tests), linting, publishing, starter docs, and versioning guidance.
1011

11-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
12-
13-
## Create an action from this template
14-
15-
Click the `Use this Template` and provide the new repo details for your action
16-
17-
## Code in Main
12+
## Usage
1813

19-
Install the dependencies
14+
Reference the published major/minor/patch tag, e.g. `v1`:
2015

21-
```bash
22-
npm install
16+
```yaml
17+
uses: github-developer/javascript-action@v1
18+
with:
19+
milliseconds: 1000
2320
```
2421
25-
Run the tests :heavy_check_mark:
26-
27-
```bash
28-
$ npm test
29-
30-
PASS ./index.test.js
31-
✓ throws invalid number (3ms)
32-
wait 500 ms (504ms)
33-
test runs (95ms)
34-
...
35-
```
22+
See the [actions tab](https://github.com/github-developer/javascript-action/actions) for runs of this action! :rocket:
3623
37-
## Change action.yml
24+
## Update your action metadata in `action.yml`
3825

39-
The action.yml defines the inputs and output for your action.
26+
[`action.yml`](action.yml) defines the inputs and output for your action.
4027

4128
Update the action.yml with your name, description, inputs and outputs for your action.
4229

43-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
30+
See the [documentation](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
4431

45-
## Change the Code
32+
## Write your action code in `lib`
4633

4734
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
4835

@@ -64,53 +51,42 @@ run()
6451

6552
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
6653

67-
## Package for distribution
54+
## Test your action in `tests`
6855

69-
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
56+
[Jest](https://jestjs.io/) and [Nock](https://github.com/nock/nock) are included as suggestions for test and mocking frameworks.
7057

71-
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
58+
A sample [Unit Test workflow](.github/workflows/test.yml) is provided which runs on every pull request and push to the `main` branch.
7259

73-
Run prepare
60+
## Automate releases with GitHub Actions
7461

75-
```bash
76-
npm run prepare
77-
```
62+
The entrypoint to your action is defined by `runs.using` in `action.yml`.
7863

79-
Since the packaged index.js is run from the dist folder.
64+
This project uses a `prepare` script leveraging `@vercel/ncc` to compile and package the code into one minified `dist/index.js` file, enabling fast and reliable execution and preventing the need to check in the whole dependency tree in `node_modules`.
8065

81-
```bash
82-
git add dist
83-
```
84-
85-
## Create a release branch
86-
87-
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
66+
Here, `dist` is intentionally _not_ committed to Git branches for three reasons:
67+
1. Encourage users to reference your action using [semantically versioned](https://semver.org/) tags like `v1`, `v1.1.5`, etc. instead of branches ([docs](https://docs.github.com/en/actions/creating-actions/about-actions#using-tags-for-release-management)).
68+
2. Avoid a security vulnerability attack vector by encouraging community contributions to source code only, ignoring proposed compiled release assets.
69+
3. Let automation do the hard part 🤖.
8870

89-
Checkin to the v1 release branch
71+
A sample [Publish workflow](.github/workflows/publish.yml) is provided which runs on a `release` event to compile and package source code into `dist`, and force push major and minor tag versions according to the semantic version of the release. You can kick off this workflow and publish to GitHub Marketplace simply by [using the GitHub UI](https://docs.github.com/en/actions/creating-actions/publishing-actions-in-github-marketplace#publishing-an-action) to create a new semantically versioned release like `v1.0.3`.
9072

91-
```bash
92-
git checkout -b v1
93-
git commit -a -m "v1 release"
94-
```
73+
## Commit to open source maintainership
9574

96-
```bash
97-
git push origin v1
98-
```
75+
A healthy open source community starts with communication. Either in this repository or in your organization's `.github` repository, we recommend reviewing, editing, and adopting:
76+
- `CODE_OF_CONDUCT.md` for how to engage in community
77+
- `CONTRIBUTING.md` for how to contribute to this project
78+
- `LICENSE.md` for how to legally use and contribute to the project
79+
- `SECURITY.md` for responsibly disclosing vulnerabilities
80+
- [Issue and pull request templates](https://docs.github.com/en/github/building-a-strong-community/about-issue-and-pull-request-templates)
9981

100-
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+
Issues and pull requests from the open source community should be attended to in a prompt, friendly, and proactive manner. Two sample workflows, [stale](.github/workflows/stale.yml) and [labeler](.github/workflows/labeler.yml) are provided to help with two small repetitious tasks.
10183

102-
Your action is now published! :rocket:
84+
See [Open Source Guides](https://opensource.guide/best-practices/) for more guidance on maintaining a strong community.
10385

104-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
86+
## License
10587

106-
## Usage
88+
[MIT](LICENSE.md)
10789

108-
You can now consume the action by referencing the v1 branch
109-
110-
```yaml
111-
uses: actions/javascript-action@v1
112-
with:
113-
milliseconds: 1000
114-
```
90+
## Contributing
11591

116-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
92+
Pull requests are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for more.

0 commit comments

Comments
 (0)