Using GitHub Actions - Part 1
A Step-by-Step Guide to How I Built a Workflow in a GitHub Repository using GitHub Actions.
Lab Scenario:
The goal of this lab was to create an empty workflow file and add events and a job runner. The workflow will not be finished until the next lab, Using GitHub Actions - Part 2. It was important to complete this lab entirely before starting part 2.
Learning Objectives:
After completing this lab, I was able to:
Prerequisites:
The following was needed to complete the exercises in this lab:
Now that I knew the scenario, lab objectives, and prerequisites, it was time to begin!
Task 1: Fork and Clone the Lab Repository
Steps:
Note: As you can see in the screenshot above, the command to clone the repository was unsuccessful for me when copying the command from the lab instructions so I had to use the GitHub CLI command provided in the GitHub browser and it worked!!
领英推荐
Task 2: Create a Workflow, Add Event Triggers, Add a Job, and Target Python 3.9
Step 1: Create a Workflow
Step 2: Add Event Triggers
Event triggers define which events can cause the workflow to run. I used the on: tag to add the following events: run the workflow on every push to the main branch, run the workflow whenever a pull request is created to the main branch. The steps are below:
Step 3: Add a Job
Now I added a job called build to the workflow file. This particular job will run on the the ubuntu-latest runner. A job is a collection of steps that are run on the events that I provided in the previous steps.
Step 4: Target Python 3.9
It's important to consistently use the same version of dependencies and operation systems for all phases of development, including the CI pipeline. Since this lab was developed on Python 3.9, I had to ensure that the CI pipeline also ran on the same version of Python. This was accomplished by running the workflow in a container inside the GitHub Action.
Task 5: Saving My Work
Arguably one of the most important tasks was to save my work!
Note: Git Add prepares the content staged for the next commit. Git commit -m captures a snapshot of the currently staged changes and the -m allows us to enter the commit message prior to the prompt. Lastly, git push loads the local repository content to the remote repository.
Conclusion:
I successfully completed Part 1 of this lab although the GitHub Action was triggered and has failed that is because the workflow is not finished. I will add the remaining steps in Part 2 of the lab so the workflow runs successfully.
Thanks for reading and I look forward to completing Part 2 of this lab and sharing it.