for our github action, we also want to input two configuration options so that we can allow people to actually use their instances and api tokens for this action.
so in our action.yml, they pasted this inputs object which contains the GITHUB_TOKEN that we will use for our action to be allowed to actually add the 'Thank you' comment to every new pull request in Github, as well as the TENOR_TOKEN which allows the action to reach out to the tenor api.
what they did:
inputs:
GITHUB_TOKEN:
description: "Github token"
required: true
TENOR_TOKEN:
description: "Tenor API token"
required: true
we need to set up our environment. so we're gonna use the runs object and pass in "using: node12" which were going to tell them that we want to use the environment of node12, and then "main" which were going to specify as "dist/index.js" which is going to be the ultimate path of our action script that we want to run.
what they did:
runs:
using: "node12"
main: "dist/index.js"
now in order for our action to actually run, we need to create a script.
what they did inside src/action.js:
async function run() {
console.log('Hello, world!');
}
run();
the reason why we are creating an async function and running it is so that we can use the async await syntax within this block. but for now we are gonna leave this console.log just so that we can test that it's working.
we can even test that out by going over back to our terminal then:
that should log "Hello, world!" on our terminal.
now in order to run this action script, we saw that we can do that right from the terminal. but inside of our action.yml file, we described that our main entry point as "dist/index.js". thats because we are gonna compile it from our src directory into that dist folder. to do that were gonna use a tool called "ncc" from vercel
that will allow us to compile our project into a single file. this will be particularly helpful when we want to take dependencies and make them all runnable from one single file.
so to start, inside your terminal, run yarn add @vercel/ncc
which will be add the dependency to our project, while generating our yarn.lock file. you can also use npm install to install the dependency which will make the package-lock.json, either works but what they used in the course we follow hehe.
next we're going to add a new script "build": "ncc build src/action.js -o dist"
inside our package.json. this is how our package.json should somewhat look like, with the newly added script:
{
"name": "colbyfayock-cgaingajt-20210205",
"version": "1.0.0",
"description": "🧩 Colby Fayock - Custom GitHub Actions in Node.js - GitHub Actions JavaScript Tutorial (February 5, 2021) | Link: https://www.youtube.com/watch?v=Ef0gPGUh9oo&ab_channel=ColbyFayock",
"main": "index.js",
"scripts": {
"build": "ncc build src/action.js -o dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/newojima/colbyfayock-cgaingajt-20210205.git"
},
"author": "nellyXinwei",
"license": "MIT",
"bugs": {
"url": "https://github.com/newojima/colbyfayock-cgaingajt-20210205/issues"
},
"homepage": "https://github.com/newojima/colbyfayock-cgaingajt-20210205#readme",
"dependencies": {
"@vercel/ncc": "^0.34.0"
}
}
shet this comment is really long, i think its really better to take documentation notes in our vscode / notion instead of being here but whatever, were just trying anyways right.
similarly, we can see that itll also log "Hello, world!" when we do on terminal node dist/index.js
.
umm ok this is not in the course but i made a new ".gitignore" file in our root of our project repository then added "node_modules" in it so that it doesnt include the node_modules in our commit to github.