Time to publish. Fork this repo to get started. Then, go to the Actions
tab on your repo and enable Github Actions.
Make sure you have Node and NPM installed.
First, look around you and find a partner (or two)! Y'all will publish separate repos, but work together to try and figure out why things are or aren't working.
For this demo, you're going to be publishing your own Node.js application! This app will be a simple CLI command that you can customize to say whatever you want. Before going any further, check out index.js
! Add whatever functionality/message you want, and move on.
Next, open up package.json
. We've got some 1912-specific configuration in there - specifically the repository and name. Change these to reflect that this is now under your user, not the cis1912
organization.
Finally, run npm install
to install your dependencies and node .
to make sure your app will actually print something out.
As we mentioned in lecture, Github lets you define some jobs to run when a push to a repo happens. We've given you a very basic config in .github/workflows/publish.yaml
that just echoes "todo"
whenever you push. Change this step so that it will install your packages with npm install
and check that your package passes linting with npm run lint
.
Once you've added this config, commit and push up your code. Go to the Actions
tab and see if your job succeeds! If it does, feel free to move on. If it doesn't, check the CI output and try to debug.
Now that you've checked that your package lints automatically, it's time to automatically publish it! In this case, we're going to publish to the Github NPM registry.
You need to add a job named publish
that:
- Needs
lint
to complete before starting - Checks out the code
- Publishes your npm package
We'll tell you how to do 3, but 1 and 2 you've gotta figure out! 3:
- uses: JS-DevTools/npm-publish@v1
with:
registry: https://npm.pkg.github.com
token: ${{ secrets.GITHUB_TOKEN }}
Once you've gotten the config figured out, push up and see if CI works.
Make yourself a Github Personal Access token and save it. This token needs the write:packages
permission. We'll use this to pull down our NPM package now that it's published.
We're in the home stretch now. Edit the file ~/.npmrc
if it exists, and create it if it doesn't already exist. In the file, add the following config, replacing OWNER with your Github username and PAT with your Github personal access token.
//npm.pkg.github.com/:_authToken=PAT
@OWNER:registry=https://npm.pkg.github.com
After editing this file, cross your fingers and try to install your package.
$ npm install -g @OWNER/ci-demo
$ ci-demo
Hello World: 6aa43f18-4d3c-4f05-a29a-4c25907c8f7b
If this worked, then you've successfully automated publishing for your own npm app! Once you're done, call over Jordan and ask him about how many "murders" he witnessed today.