Inspiration
After being able to accomplish the github Actiions challenge, I had to try this one.
What it does
I consumed actions within a workflow file, created custom JavaScript based actions and published newly created action to the marketplace.
How we built it
step 1:
I initialized a new javascript project. Basically, I used npm to install request, request-promise and @actions/core dependencies and git for my repository updates.
step 2:
I created a action.yml file to enable configuring the action.
step 4:
i created a metadata by updating my action.yml file with the following code:
name: "my joke action"
description: "use an external API to retrieve and display a joke"
outputs: joke-output: description: The resulting joke from the icanhazdadjokes API
runs: using: "node12" main: "main.js"
step 4:
I created joke.js and main.js files for fetching and consuming data via the joke API. For fetching data I had the following code(joke.js)
const request = require("request-promise");
const options = { method: "GET", uri: "https://icanhazdadjoke.com/", headers: { Accept: "application/json", "User-Agent": "Writing JavaScript action GitHub Skills course." }, json: true };
async function getJoke() { const res = await request(options); return res.joke; }
module.exports = getJoke;
To consume the data i had:
const getJoke = require("./joke"); const core = require("@actions/core");
async function run() { const joke = await getJoke(); console.log(joke); core.setOutput("joke-output", joke); }
run();
finnally, I added action to the workflow file and triggered the joke action for testing.
Challenges we ran into
No challenges
Accomplishments that we're proud of
Finishing up the project
What we learned
How to create javascript form action to workflow.
Log in or sign up for Devpost to join the conversation.