Skip to content

Hello action #4

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Hello action #4

wants to merge 1 commit into from

Conversation

github-learning-lab[bot]
Copy link
Contributor

Anatomy of an action

Earlier you learned how the different pieces of the GitHub Actions feature work together. Now you will learn about the components that make up an individual action.

Remember, and action is the unit of work that a workflow file executes when it reaches that task. They are called by referencing them as the value to the uses: key in a workflow step.

What makes up an action?

JavaScript actions are consist of two key components:

Component Description
JavaScript source code files These files contain the logic of your action. This includes any dependencies or custom modules that your main logic may need.
Action metadata file This file contains information that the actions source code can use. An example of this is allowing a developer to specify an API key as an input variable for your action to consume. This file MUST be named action.yml

Let's take a look at how those components fit in with the workflow file.

Screenshot depicting the interaction between the JavaScript files, action metadata file and workflow file.

Although the workflow file is used to allow us to set the inputs and outputs using the with: keyword it is not a required component of an individual action.

The failing workflow

Before we jump into the details of action metadata, it might be helpful to examine our workflow to understand the order that things happen. I have attached a screenshot below of the most recent workflow run, you can also follow along by clicking on the Actions tab for your repository.

This screenshot shows the results of a failing workflow run.  These result can be found by clicking the actions tab of this repository

Notice that our third workflow step, the one that is looking for our action is failing. We expect this, but the magic ✨is in the error message!

That step is looking for a file named action.yml.

Because action.yml is non-existent in the hello-world directory we see this error. So let's start by talking about, and creating, the missing action.yml file.

@github-learning-lab github-learning-lab bot mentioned this pull request Nov 4, 2020
3 tasks
@github-learning-lab
Copy link
Contributor Author

Action metadata

Every GitHub Action that we write needs to be accompanied by a metadata file. This file has a few rules to it, lets outline those now:

  • Filename must be action.yml
  • Required for both Docker container and JavaScript actions
  • Written in YAML syntax

This file defines the following information about your action:

Parameter Description Required
Name The name of your action. Helps visually identify the actions in a job.
Description A summary of what your action does.
Inputs Input parameters allow you to specify data that the action expects to use during runtime. These parameters become environment variables in the runner.
Outputs Specifies the data that subsequent actions can use later in the workflow after the action that defines these outputs has run.
Runs The command to run when the action executes.
Branding You can use a color and Feather icon to create a badge to personalize and distinguish your action in GitHub Marketplace.

📖Read more about Action metadata

@github-learning-lab
Copy link
Contributor Author

Enough talk, lets do this!

Now that we know what action metadata is, let's create the metadata for our current hello-world action.

⌨️ Activity: Create the metadata file

💡All of the following steps take place inside of the .github/actions/hello-world directory.

We will start with using the parameters that are required and later implement some optional parameters as our action evolves.

  1. Create a new file in: .github/actions/hello-world/action.yml
  2. Add the following contents to the .github/actions/hello-world/action.yml file:
    name: "my hello action"
    
    description: "say hello with GitHub Actions"
    
    runs:
      using: "node12"
      main: "main.js"
  3. Save the action.yml file
  4. Commit the changes and push them to the hello-world branch:
    git add action.yml
    git commit -m 'create action.yml'
    git push

I'll respond here once I notice that you've pushed your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants