Task 03 - Set up a GitHub Actions workflow
- The solution for this task is a YAML file in the solutions folder.
Each GitHub Actions workflow has a certain structure to it, following the GitHub Actions workflow syntax. The following is an annotated breakdown of this structure.
# The name of the job is what will display on the GitHub repository in the Actions tab.
name: First Workflow
# The 'on' section tells GitHub under what conditions we want to run this workflow.
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# Common scenarios include:
# workflow-dispatch (manual execution)
# issues
# push
# pull_request
# schedule
on:
workflow_dispatch:
issues:
types: [opened]
# This section covers the work to perform.
# We include one or more jobs in this section.
jobs:
# Each individual job will include details like execution order,
# pre-requisite jobs, and execution platform.
job1:
# We can run jobs on GitHub hosted VM runners in Windows, Ubuntu, and Mac OS.
# We can also run jobs on self-hosted hardware.
runs-on: ubuntu-latest
# Each job contains one or more steps. A step needs to have at least a name and a command.
steps:
- name: Step one
# The 'run' command executes a shell or command script. Because this is Ubuntu, the
# default run command will be /bin/bash
run: echo "Log from step one"
# This section does not appear in the solution file but demonstrates how to set
# custom variables that will be available in the run script.
env:
VARIABLE_NAME: value
- name: Step two
run: echo "Log from step two"
job2:
# Job 2 will only run after job 1 completes.
# Removing this 'needs' section would make the jobs run simultaneously.
needs: job1
runs-on: ubuntu-latest
steps:
- name: Cowsays
# The 'uses' command executes a remote GitHub action.
# A command like mscoutermarsh/cowsays-action means you can
# find this code at https://github.com/mscoutermarsh/cowsays-action
uses: mscoutermarsh/cowsays-action@master
# The 'with' block includes parameters that the workflow will pass
# to this action. Parameters are all in key-value format.
with:
text: 'Ready for prod--ship it!'
color: 'magenta'