Automate your workflow with GitHub Actions
Create a basic container action by using GitHub Actions
In this lab I’ll be using the GitHub learning Lab to create a GitHub repository, a container action that will print a greeting in the action’s log file, and a workflow that triggers on a push to this repository
The following are the steps I’ll need to create this container action.
GitHub Actions
This action will use a Docker container so it will require a Dockerfile
Add a Dockerfile
I filled my Dockerfile with the content below:
FROM debian:9.5-slim
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Commit my file
Add an entrypoint script
An entry point script MUST exist in my repository so that Docker has something to execute. What I’m doing is outputting the “Hello world” message using a variable called MY_NAME
I used the command below:
#!/bin/sh -l
sh -c “echo Hello world my name is $INPUT_MY_NAME”
Add an action.yml file
Actions require a metadata file that uses YAML syntax. This data file defines inputs, outputs and main entrypoint for my action
name: "Hello Actions"
description: "Greet someone"
author: "octocat@github.com"
inputs:
MY_NAME:
description: "Who to greet"
required: true
default: "World"
runs:
using: "docker"
image: "Dockerfile"
branding:
icon: "mic"
color: "purple"
Start your workflow file
Work flows can execute based on a chosen even. This pieces together my jobs, and my jobs piece together my steps.
name: A workflow for my Hello World file
on: push
Run an action from your workflow file
jobs:
build:
name: Hello world action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./action-a
with:
MY_NAME: "Mona"
Here are some details as to why each part exists and what each part does:
jobs:
is the base component of a workflow run
build:
is the identifier we're attaching to this job
name:
is the name of the job, this is displayed on GitHub when the workflow is running
steps:
the linear sequence of operations that make up a job
uses: actions/checkout@v1
uses a community action calledcheckout
to allow the workflow to access the contents of the repository
uses: ./action-a
provides the relative path the action we've created in theaction-a
directory of the repository
with
: is used to specify the input variables that will be available to your action in the runtime environment. In this case, the input variable isMY_NAME
, and it is currently initialized to"Mona"
Trigger the workflow
Next, I triggered my workflow with results below.
Incorporate the workflow
Merge this pull request into the master branch
Delete your branch