Loading
Current section: nx 20 exercises
lesson

Automating Package Publishing with GitHub Actions

In our current release script located in the tools folder, we have a process that manages various tasks such as copying packages, versioning, and change generation. However, the actual publishing part has been commented out for testing the GitHub release.

So let's comment this back in and also co

Loading lesson

Transcript

00:00 So right now our release script here in our tools folder manages all the parts from copying the packages, versioning, and change of generation. Now this part here about the actual publishing has been commented out to test the GitHub release. So let's comment this back in and also configure

00:16 it to publish to an npm registry. And so as a registry here we give it the npm registry and we also want to make sure that the access here is set to public. And this part is in particularly important if you use package scopes. A package scope is basically what we have for

00:34 instance here in our core package and all the other packages where here we use this scope in front of it to bundle different packages that are related together. This is actually a pretty common practice. This could also be your actual organization or simply to bundle together

00:48 related packages. Now if you want to publish these to npm you need to make sure the access is public otherwise you basically have to pay for these private packages that are scoped. Now as we're talking about the scope here let me also make some other change. So basically you don't want to

01:04 pollute potentially the npm scope namespace because slate ui maybe someone comes up with a name and kind of likes it. So what I want to do is have a more unique one that is very unlikely someone is going to use in a similar fashion. So let me go and basically replace all slate ui

01:20 with add package demo. And so let me just replace this. Let's make sure to also run an npm install to update our package log file. And then we can actually go ahead and commit this. Now usually you would actually say here

01:43 chore but in this case let's just have feature and say update namespace package. This way we can release a new version. So we can now go to our publish workflow here on github actions and make sure that works as well. Now it already references our release script here locally

02:01 so we don't have to change anything there. The only thing we need to make sure that we add here is the node auth token that allows us to authenticate when we run the npm publish behind the scenes. Now here you can see I'm referencing here that npm token which is something I've added here in my repository under the secrets and variables and have added here the npm token

02:21 which you can generate on npm. So with that we should actually be good to go. Let's push this to our github repo. And so if you go over now and start a new github action

02:33 click here publish run our workflow. This now runs the publishing workflow. So if you scroll up here a little you can see here it pushed everything to npm and we can also go back here to our repository here at the root we should see

02:55 the version 1.8.0. Our github release also got published and now if you go to our epic package demo you can now see all of our packages appear and so our publish to npm was successful.