You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* updated node version from 16 to 20
* chore: update deps to Node v20
* chore: set engines
* ci: build with node v20
* docs: update versions in docs
---------
Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
Copy file name to clipboardExpand all lines: doc/auto-publish-walkthrough.md
+52-57Lines changed: 52 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
-
*Note: the result of all these steps can be found [here][1], in the workflow file I actually used for my package.*
1
+
_Note: the result of all these steps can be found [here][1], in the workflow file I actually used for my package._
2
2
3
3
## 1. Making sure that the "publish" job gets executed on the version that has been just built
4
4
5
-
The easiest way I found was just to put the two jobs in the same workflow, and having them both fire on every `push` event: the publish job was then limited to execute only if on the `master` branch and after the first one.
5
+
The easiest way I found was just to put the two jobs in the same workflow, and having them both fire on every `push` event: the publish job was then limited to execute only if on the `main` branch and after the first one.
6
6
7
-
-**Build job:**
7
+
-**Build job:**
8
8
9
9
It needs to build the new version of the package, then **commit** it to the repository: committing is crucial because that allows the other job to pick the built version. To commit the changes made inside a workflow run, you can use one of my actions, [`add-and-commit`][2]: it will push the changes to the GitHub repository using a "fake" git user.
10
10
You workflow job should look something like this:
@@ -15,61 +15,57 @@ jobs:
15
15
name: Build
16
16
runs-on: ubuntu-latest
17
17
18
-
steps:
19
-
- name: Checkout repository
20
-
uses: actions/checkout@v2
21
-
22
-
- name: Set up Node.js
23
-
uses: actions/setup-node@v1
24
-
with:
25
-
node-version: '10.x'
26
-
27
-
- name: Install dependencies
28
-
run: npm install --only=prod
29
-
30
-
- name: Compile build
31
-
run: npm run build # This can be whatever command you use to build your package
32
-
33
-
- name: Commit changes
34
-
uses: EndBug/add-and-commit@v2
35
-
with: # More info about the arguments on the action page
36
-
author_name: Displayed name
37
-
author_email: Displayed email
38
-
message: "Message for the commit"
39
-
path: local/path/to/built/version
40
-
pattern: "*.js"# Pattern that matches the files to commit
41
-
force: true # Whether to use the --force flag
42
-
env:
43
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This gets generated automatically
44
-
```
18
+
steps:
19
+
- name: Checkout repository
20
+
uses: actions/checkout@v4
21
+
22
+
- name: Set up Node.js
23
+
uses: actions/setup-node@v4
24
+
with:
25
+
node-version: '20.x'
26
+
27
+
- name: Install dependencies
28
+
run: npm install --only=prod
45
29
30
+
- name: Compile build
31
+
run: npm run build # This can be whatever command you use to build your package
32
+
33
+
- name: Commit changes
34
+
uses: EndBug/add-and-commit@v9
35
+
with: # More info about the arguments on the action page
36
+
author_name: Displayed name
37
+
author_email: Displayed email
38
+
message: 'Message for the commit'
39
+
add: local/path/to/built/version/"*.js --force
40
+
```
46
41
47
-
- **Publish job:**
42
+
- **Publish job:**
48
43
49
-
We want it to run only in the `master` branch after `build` is completed, so we can set it like this:
44
+
We want it to run only in the `main` branch after `build` is completed, so we can set it like this:
50
45
51
46
```yml
52
47
publish:
53
48
name: Publish to NPM & GitHub Package Registry
54
49
runs-on: ubuntu-latest
55
-
if: contains(github.ref, 'master') # This sets the branch
50
+
if: contains(github.ref, 'main') # This sets the branch
56
51
needs: build # This makes it wait for the build job
57
52
```
58
53
59
-
## 2. Detecting a version change
54
+
## 2. Detecting a version change
55
+
60
56
I didn't find a good way to do that so I made another action, [`version-check`][3]: this action scans the commits of every push and tries to figure out whether they include a version change. Remeber to set eventual needed arguments/inputs!
61
57
You need to set up these two steps:
62
58
63
59
```yml
64
60
steps:
65
-
- name: Checkout repository
66
-
uses: actions/checkout@v2
67
-
with:
68
-
ref: master
69
-
70
-
- name: Check version changes
71
-
uses: EndBug/version-check@v1 # More info about the arguments on the action page
72
-
id: check # This will be the reference for later
61
+
- name: Checkout repository
62
+
uses: actions/checkout@v4
63
+
with:
64
+
ref: main
65
+
66
+
- name: Check version changes
67
+
uses: EndBug/version-check@v2 # More info about the arguments on the action page
68
+
id: check # This will be the reference for later
73
69
```
74
70
75
71
You could also use the `static-check` and `file-url` option to detect teh version change, but if more checks run at the same time this can make it try to publish it multiple times.
@@ -114,9 +110,9 @@ In this example, I'll assume your secret is called `NPM_TOKEN`:
114
110
As for now, GitHub Package Registry is not very pleasant to work with if you want to keep publishing your existing package to npm: that's why it requires packages to be scoped, and that can mess thing up (your package may not be scoped or be scoped under a different name).
115
111
I found that the easiest way to deal with that is doing this workaround:
116
112
117
-
- In your workflow, re-setup Node.js but adding GPR's registry URL and your name-scope
118
-
- Create an npm script that edits your package.json so that it changes the original name of the package to the one you need to publish to GPR (scope included)
119
-
- After calling that script in your workflow, use `npm publish` as before, but this time using the built-in `GITHUB_TOKEN` as `NODE_AUTH_TOKEN`.
113
+
- In your workflow, re-setup Node.js but adding GPR's registry URL and your name-scope
114
+
- Create an npm script that edits your package.json so that it changes the original name of the package to the one you need to publish to GPR (scope included)
115
+
- After calling that script in your workflow, use `npm publish` as before, but this time using the built-in `GITHUB_TOKEN` as `NODE_AUTH_TOKEN`.
0 commit comments