Creating a new workflow

Note: GitHub Actions are currently available as a limited public beta, which means you should avoid using it for high-value workflows and content during this beta period. Creating workflows that use GitHub Actions is limited to private repositories during the limited public beta.

Features and requirements may change at any time during this period. You can request to join the limited public beta on the GitHub Actions page. If you're participating in the beta, please contact support if you have any questions.

Using the visual or file editor, you can create a workflow that contains GitHub Actions, and their relationships to each other. Once you've created a .github/main.workflow file, you need to add workflow and action blocks. You can add content to these blocks using "Workflow configuration options." For more information, see "Creating a workflow with GitHub Actions" in the GitHub Help documentation.

Hello world workflow example

This example manually creates a workflow and an action, rather than using the visual editor. The workflow in this example uses the action created in the "Hello world action example" to write values to standard output (stdout).

The action writes any values passed in the args action attribute to stdout.

Here's an overview of the file hierarchy you'll use:

|-- hello-world (repository)
|   |__ .github
|       |__ main.workflow
|   |__ action-a
|       │__  Dockerfile
|       |__  entrypoint.sh  
|

During the limited public beta, you can only create workflows that use actions in private repositories. You can use any repository name, or you can create a new private repository called hello-world. To create the action, add these two files:

./action-a/Dockerfile

FROM debian:9.5-slim

LABEL "com.github.actions.name"="Hello World"
LABEL "com.github.actions.description"="Write arguments to the standard output"
LABEL "com.github.actions.icon"="mic"
LABEL "com.github.actions.color"="purple"

LABEL "repository"="http://github.com/octocat/hello-world"
LABEL "homepage"="http://github.com/actions"
LABEL "maintainer"="Octocat <octocat@github.com>"

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

./action-a/entrypoint.sh

#!/bin/sh -l

sh -c "echo $*"

Your code must be executable. Make sure the entrypoint.sh file has execute permissions before using it in a workflow. You can modify the permission from your terminal using this command:

chmod +x entrypoint.sh

You'll need one workflow block and one action block for this example.

Your workflow block will execute anytime code is pushed to your repository, using the push event. The workflow selects the action to execute using the resolves attribute.

The action block uses action-a by referencing the path to the action's directory, relative to your hello-world repository.

Use the env action attribute to create an environment variable that will be available to your action in the runtime environment. Finally, you'll pass a string to the action in the args attribute. The args you pass are appended to the echo command in entrypoint.sh and run in a command shell. This allows you to use environment variables in the args attribute. See "ENTRYPOINT" for more about how the entrypoint.sh file works.

main.workflow

workflow "New workflow" {
  on = "push"
  resolves = ["Hello World"]
}

action "Hello World" {
  uses = "./action-a"
  env = {
    MY_NAME = "Mona"
  }
  args = "\"Hello world, I'm $MY_NAME!\""
}

If you add these three files to your repository using the file structure above, an action will run the next time you push code to your repository. To see the action, click the "Actions" tab in your repository. From there you will see the actions that have run, and you can click on the action's "Log" link to view details.

View an action's log

You should see the string "Hello world, I'm Mona!" printed at the bottom to stdout.

Actions successful log file