In this hands-on lab your will create your first GitHub Actions Workflow and learn how you can use Actions to automate tasks in your software development lifecycle. If you like more background information, please refer to the GitHub Actions pages on GitHub Docs. Good luck! 👍
This hands on lab consists of the following steps:
Go to Code tab of this repository and click Use this template
:
Select your GitHub user as the owner and name the repository. Leave the repo public to have unlimited action minutes:
Continue now in the new repository.
Go to Actions | New Workflow and click on set up a workflow yourself.
- Rename the file
main.yml
in the.github/workflows
directory togithub-actions-demo.yml
.
- Remove the template content - we want to create the workflow from scratch.
- Click Ctrl+Space and select name as the first element:
- Set the workflow name to
GitHub Actions Demo
:
name: GitHub Actions Demo
- Add the triggers to the worklow with the help of Ctrl+Space and the documentation. We want the workflow to trigger:
- on every push to the
main
branch, but not when there are changes to files in the.github
folder. - on every pull request with
main
as the base branch - Every sunday at 6:15 UTC
- Manually
Solution
on:
push:
branches: [ main ]
paths-ignore: [.github/**]
pull_request:
branches: [ main ]
schedule:
- cron: '15 6 * * 0'
workflow_dispatch:
- Create a job
Build
that runs on the latest Ubuntu image on GitHub hosted runners. Check the documentation of the virtual environments what label to use and what version it is. The job should do the following things:
- Output the name of the event that triggered the workflow
- Output the name of the branch that the repository is currently referencing
- List all files in the repository
Solution
jobs:
Build:
runs-on: ubuntu-latest
steps:
- run: |
echo "🎉 The job was triggered by event: ${{ github.event_name }}"
echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ."
- uses: actions/[email protected]
- name: List files in the repository
run: |
echo "The repository ${{ github.repository }} contains the following files:"
tree
- Commit the workflow file - and trigger the workflow manually. It should not run automatically if your path filter works. Got to Action, select GitHub Actions Demo and
Run workflow
:
- Click on your workflow run:
- Click on the job 'Build':
- Expand
Set up job
and note the log with the line number (line numbers are links). Check the information about the virtual environment and included software:
- Expand your jobs and check that the output was correct.
- Verify you other triggers by modifying the README.md file:
- Modify and commit: triggers build (
push
) - Modify and add
[skip ci]
(not triggering the workflow):
- Modify and create pull request (trigger:
pull_request
)
In this hands-on you've learned to create you first workflow with triggers, jobs, steps, and expressions. Next you will write your first GitHub Action.