-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use outputs #8
Use outputs #8
Conversation
jh-kainos it's time to get ready for the third action 🎉As with the other actions we wrote, we are going to need to setup a few directories and files. ⌨️ Activity: Configure your third actionLet's create our final project directory and install all the necessary dependencies. We will take this a step further near the end of this action and we will show you how to avoid needing to check in
I will respond once you have pushed to this branch. |
Create and edit the third actions action.yml fileLike our "hello world" action, this action will require at least one If you recall, in the - name: create-issue
uses: ./.github/actions/issue-maker
with:
joke: ${{steps.jokes.outputs.joke-output}} Because of this, we need to define inputs:
first-greeting:
description: who you would like to greet in the console
required: true
default: Hubot Now, we will do something similar so that our action matches what our workflow expects. ⌨️ Activity: Create the final metadata file💡All of the following steps take place inside of the We will use the joke output, an
I will respond when you commit to this branch. |
Let's write some JavaScript@jh-kainos your joke-action stores a value in an Sometimes going from code-to-cloud requires more automation than CI/CD can provide. Actions can be used for this automation and hopefully after you learn how to interact with this repository through writing this action you'll go on to write many more amazing pieces of automation. Scenario You run an open source repository that is community driven. Every month you are getting tons of contributions from random developers within the community. Sometimes these contributions are amazing because the developers have read your contributing guidelines. Sometimes the opposite occurs. In both events you would like to thank your community for their contribution and ensure that every contributor is aware that you do in fact have guidelines for contributions. How would you do this? You can imagine just how much time would be consumed if we sent a human... if we can call developers human in the first place 😉, to respond to all of our projects first time contributors with the same kind of message. Enter GitHub Actions! We can easily automate this process and many more using what you've learned up to this point. Allow me to show you the final piece and get you started with interacting with your repository through an action. About the issue maker actionOur action Let's take a look at what the source code for this action will look like and I'll explain what is happening before having your write it. Importing packages The first two lines will import packages from the Actions ToolKit. You'll find yourself using these libraries a lot, so its good to get familiar with them. const core = require("@actions/core");
const github = require("@actions/github"); Creating the main function async function run() {
try {
} catch (err) {}
}
run(); Getting input for the issue title Wait a minute... I know what you're thinking. I said read this property from the workflow file, but we never actually defined it in the workflow. You're right, but why does this work? Do you remember what happens when we give a property a default value and enforce that it is required? Since the default value can be overwritten we will include it in our code just in case you decide to provide a different title for your joke issues. async function run() {
try {
const issueTitle = core.getInput("issue-title");
} catch (err) {}
}
run(); Using the other inputs from the metadata
The We also need to define a Where does the We specified a GitHub sets default environment variables that are available to every step in a workflow run. You also have access to any secrets you have setup in your repository, to include this action specific You can read more about using the Its also worth taking a look at the different Contexts and expressions that you can use with GitHub Actions. Adding the octokit client async function run() {
try {
const issueTitle = core.getInput("issue-title");
const jokeBody = core.getInput("joke");
const token = core.getInput("repo-token");
const octokit = github.getOctokit(token);
} catch (err) {}
}
run(); Creating an issue in the repository async function run() {
try {
const issueTitle = core.getInput("issue-title");
const jokeBody = core.getInput("joke");
const token = core.getInput("repo-token");
const octokit = github.getOctokit(token);
const newIssue = await octokit.rest.issues.create({
repo: github.context.repo.repo,
owner: github.context.repo.owner,
title: issueTitle,
body: jokeBody
});
} catch (err) {}
}
run() 💡Octokit makes interacting with the GitHub API easy, but if you are writing actions using a different language, or you prefer to not use a library, the same issue can be created with this API endpoint Let's handle any errors async function run() {
try {
const issueTitle = core.getInput("issue-title");
const jokeBody = core.getInput("joke");
const token = core.getInput("repo-token");
const octokit = github.getOctokit(token);
const newIssue = await octokit.rest.issues.create({
repo: github.context.repo.repo,
owner: github.context.repo.owner,
title: issueTitle,
body: jokeBody
});
} catch (err) {
core.setFailed(err.message);
}
}
run() Don't forget to call the function, |
⌨️ Activity: Create the final JavaScript fileI'm counting on you this time! In the previous steps I have guided you heavily on what to type along the way. This time I ask that you look back on the things you've done in this course and pull from the knowledge you already have to accomplish these tasks.
I'll respond once you push to this branch. View the complete fileconst core = require("@actions/core");
const github = require("@actions/github");
async function run() {
try {
const issueTitle = core.getInput("issue-title");
const jokeBody = core.getInput("joke");
const token = core.getInput("repo-token");
const octokit = new github.getOctokit(token);
const newIssue = await octokit.rest.issues.create({
repo: github.context.repo.repo,
owner: github.context.repo.owner,
title: issueTitle,
body: jokeBody
});
} catch (error) {
core.setFailed(error.message);
}
}
run(); |
Trigger all the things 🎉Let's trigger your new workflow! Add a label to this pull request, it can be any label you choose. After adding a label head over to your Actions tab if you want to watch the workflow. Once your workflow has completed check your issues tab and you should see a new issue with a hilarious joke as the body! Continue experimenting with this workflow for as long as you'd like. Try adding another label and see if you get a new joke! When you have finished experimenting, merge this pull request. I'll open a new issue containing the next steps once I detect you've closed this. |
Great! Go to the final issue. |
No description provided.