Moose0621 / writing-javascript-actions

https://lab.github.com/githubtraining/github-actions:-writing-javascript-actions
0 stars 0 forks source link

Last minute notes #11

Open github-learning-lab[bot] opened 4 years ago

github-learning-lab[bot] commented 4 years ago

Great job!

You did it 🎉

You have successfully written three different JavaScript actions.

Let's take a quick look at all the things you learned in this course:

Workflows Along the way you learned a little about workflows and how to configure them. You managed to accomplish all these things:

That's quite a bit for a course that doesn't cover workflows!

Action metadata

JavaScript actions Wow, what a series of tasks! You started with the traditional hello world in the console, which was then expanded to use the input: parameters specified in the actions metadata. Through the use of that metadata you were able to be flexible with your greeting.

You learned how GitHub Actions behave when consuming external APIs and you also used the response from an external API as an output: parameter for a later step in the workflow.

Lastly you saw how to use actions to interact with a repository by creating an issue containing a joke.

You used multiple packages in your action source code, you consumed inputs: and set outputs:.

You learned how to use the @actions/core package to write errors and terminate a misbehaving action.

At this point you are armed with everything you need to know to go out there and begin creating your own custom JavaScript actions.

We aren't done yet 😉

Throughout this course I have promised to show you how to get rid of the node_modules folder in your repository.

I also want to take a few minutes to point you to the information you need to place your own custom actions on the GitHub Marketplace for others to use.

github-learning-lab[bot] commented 3 years ago

Getting rid of node_modules

We typically don't commit a node_modules folder in a repository. These can often grow to be huge if your project has many dependencies. Because of the way Node works this folder is a necessary evil, but there is a way to get rid of it!

First you need to install a tool called ncc. You'll want to install this tool globally so that you can use as if it's any other CLI tool on your machine.

What ncc does is take all the dependencies within your project and compile them into a single JavaScript file. This allows you to avoid committing the node_modules folder in your actions source code.

Install ncc npm install -g @zeit/ncc

Using ncc When you use ncc:

ncc build <input-file>

A new directory named dist will be created. Within that directory you will find a file named index.js. To tell GitHub Actions that this new index.js file is the one that should run when your action is used a small edit to the action.yml file needs to be made.

before:

runs:
  using: "node12"
  main: "index.js"

after:

runs:
  using: "node12"
  main: "dist/index.js"

Once you make this change you can delete the node_modules folder and commit those changes to the repository that contains your Actions source code.


📖Further help using ncc is in the GitHub Actions documentation.