UNPKG

4.25 kBMarkdownView Raw
1# primer/publish
2
3This [GitHub Action][github actions] publishes to npm with the following conventions:
4
51. If we're on the `master` branch, the `version` field is used as-is and we just run `npm publish --access public`.
6 - After publishing a new version on the `master` branch, we tag the commit SHA with `v{version}` via the GitHub API.
7 - If the version in `package.json` is already published, we exit with a `0` code. Previously, we exited with a `78` code, which was Actions v1-speak for "neutral", but this has been [removed from Actions v2](https://twitter.com/ethomson/status/1163899559279497217?s=20).
81. If we're on a `release-<version>` branch, we publish a release candidate to the `next` npm dist-tag with the version in the form: `<version>-rc.<sha>`.
9 - A [status check][status checks] is created with the context `npm version` noting whether the `version` field in `package.json` matches the `<version>` portion of the branch. If it doesn't, the check's status is marked as pending.
101. Otherwise, we publish a "canary" release, which has a version in the form: `0.0.0-<sha>`.
11
12## Status checks
13
14Depending on the branch, a series of [statuses][status checks] will be created by this action in your checks: **publish** is the action's check, and **publish {package-name}** is a [commit status] created by the action that reports the version published and links to `unpkg.com` via "Details":
15
16![image](https://user-images.githubusercontent.com/113896/52375286-23368980-2a14-11e9-8974-062a3e45a846.png)
17
18If you're on a release branch (`release-<version>`) and the `<version>` portion of the branch name doesn't match the `version` field in `package.json`, you'll get a pending status reminding you to update it:
19
20![image](https://user-images.githubusercontent.com/113896/52388530-b63ae800-2a43-11e9-92ef-14ec9459c109.png)
21
22## Usage
23
24**You will need to provide an npm access token with publish permissions via the `NPM_AUTH_TOKEN` secret in the Actions visual editor** if you haven't already. The `GITHUB_TOKEN` secret is also required to create tags after releasing on the master branch.
25
26We suggest that you place this action after any linting and/or testing actions to catch as many errors as possible before publishing.
27
28
29### Actions v2
30To use this in an [Actions v2](https://help.github.com/en/articles/migrating-github-actions-from-hcl-syntax-to-yaml-syntax) workflow, add the following YAML to one or more of your steps:
31
32```yaml
33- uses: primer/publish@master
34 env:
35 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36 NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
37```
38
39You can pass additional [options](#options) via the `args` key:
40
41```diff
42​- uses: primer/publish@master
43 env:
44 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
46+ args: '--dry-run -- --unsafe-perm'
47```
48
49### Actions v1
50To use this in an Actions v1 workflow, add the following snippet to `.github/main.workflow`:
51
52```hcl
53action "publish" {
54 uses = "primer/publish@master"
55 secrets = [
56 "GITHUB_TOKEN",
57 "NPM_AUTH_TOKEN",
58 ]
59}
60```
61
62## Options
63
64### `--dry-run`
65
66Default: `false`
67
68Does everything publish would do except actually publishing to the registry. Reports the details of what would have been published.
69
70#### Example
71
72```hcl
73action "publish" {
74 uses = "primer/publish@master"
75 secrets = ["GITHUB_TOKEN", "NPM_AUTH_TOKEN"]
76 args = "--dry-run"
77}
78```
79
80### `--dir=<path>`
81
82Default: `.`
83
84Accepts a path to the directory that contains the `package.json` to publish.
85
86#### Example
87
88```hcl
89action "publish" {
90 uses = "primer/publish@master"
91 secrets = ["GITHUB_TOKEN", "NPM_AUTH_TOKEN"]
92 args = "--dir=packages/example"
93}
94```
95
96## npm CLI arguments
97
98It's possible to pass additional arguments to `npm` via the `args` field in your workflow action. Because the `primer-publish` CLI accepts options of its own (such as `--dry-run`), you need to prefix any `npm` arguments with `--`:
99
100```diff
101action "publish" {
102 uses = "primer/publish@master"
103+ args = ["--", "--registry=https://registry.your.org"]
104```
105
106[github actions]: https://github.com/features/actions
107[commit status]: https://developer.github.com/v3/repos/statuses/
108[status checks]: https://help.github.com/articles/about-status-checks/