Giter Site home page Giter Site logo

Comments (3)

github-learning-lab avatar github-learning-lab commented on June 3, 2024

Anatomy of an action

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

Remember, an 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?

Docker actions consist of three key components:

Component Description
Action 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
Dockerfile This file defines the environment and dependencies for the action. It is best practice that this file be named Dockerfile

Let's take a look at how those components fit together.

  • The workflow, usually workflow.yml, is the user facing component. It must be housed in .github/workflows/ and doesn't need to be called workflow.yml, but its essence is a workflow. This is what we interact with directly when we want to supply input, or consume the output of a given action. You can think of workflow.yml as a user-interface for the action.yml file.
  • The action's metadata, called action.yml, is the interface between the user and the source code of the action. It is housed in a directory just for the action. This file may contain default values for inputs and outputs that the source code relies on. Those values can be overwritten by the workflow.yml file, but their default values live here and allow the action to execute properly if no values are supplied. This file also defines a high-level environment for the source code, such as whether to use Docker or Node.js and the execution entry point.
  • The action's source code files define the logic of an action. It is housed in a directory just for the action. The user doesn't interact with these files directly. There could be as little as one source code file, but there is no hard rule on how modular an action can be!
  • Dockerfile is only needed when creating Docker based actions and it is responsible for packaging up the environment as well as the source code for the given action. It is housed in a directory just for the action. This file is read and a Docker image is created from it. Once the image is created a container is created from the image and the action is executed.

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

You may be following along on the Actions tab of this repository. If you are, you'll notice that the workflow we set up previously is failing. That is the currently expected behavior: we referenced an action in the hello-world directory, which doesn't yet exist. We will be fixing that as we move forward with the lesson.

from write-docker-actions.

github-learning-lab avatar github-learning-lab commented on June 3, 2024

Action metadata

Since every GitHub Action that we write needs to be accompanied by a metadata file this is the file we will create first.

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

from write-docker-actions.

github-learning-lab avatar github-learning-lab commented on June 3, 2024

Create the action metadata

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

⌨️ Activity: Create an action.yml file and add necessary metadata

πŸ’‘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 knowledge grows.

  1. Create and add the following contents to the .github/actions/hello-world/action.yml file:
    You can use this link to easily create this file.

    name: "my hello action"
    
    description: "say hello with GitHub Actions"
    
    runs:
      using: "docker"
      image: "Dockerfile"
  2. Commit the changes to a new branch named hello-world

  3. Create a pull request titled Add a Hello World action.

  4. Supply the pull request body content and click Create pull request.


I'll respond when you create a new pull request.

from write-docker-actions.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.