Skip to content

Commit c612c17

Browse files
Initial commit
0 parents  commit c612c17

20 files changed

+787
-0
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"

.github/script/merge-branch.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# Make sure this file is executable
3+
# chmod a+x .github/script/merge-branch.sh
4+
5+
# USAGE: This script is used to merge a branch into another branch
6+
7+
# BACKGROUND: This operation is required to avoid conflicts between branches.
8+
9+
# Setup committer identity
10+
git config user.name github-actions[bot]
11+
git config user.email github-actions[bot]@users.noreply.github.com
12+
13+
# Merge branch
14+
echo "If branch $branch2 exists, merge branch $branch1 into branch $branch2"
15+
if git show-ref --quiet refs/heads/$branch2
16+
then
17+
git checkout $branch2
18+
git merge $branch1
19+
git push origin $branch2
20+
else
21+
echo "Branch $branch2 does not exist"
22+
fi

.github/steps/-step.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

.github/steps/0-welcome.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- readme -->
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--
2+
<<< Author notes: Step 1 >>>
3+
Choose 3-5 steps for your course.
4+
The first step is always the hardest, so pick something easy!
5+
Link to docs.github.com for further explanations.
6+
Encourage users to open new tabs for steps!
7+
-->
8+
9+
## Step 1: Add a test workflow
10+
11+
_Welcome to "GitHub Actions: Continuous Integration"! :wave:_
12+
13+
**What is _continuous integration_?**: [Continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) can help you stick to your team’s quality standards by running tests and reporting the results on GitHub. CI tools run builds and tests, triggered by commits. The quality results post back to GitHub in the pull request. The goal is fewer issues in `main` and faster feedback as you work.
14+
15+
![An illustration with a left half and a right half. On the left: illustration of how GitHub Actions terms are encapsulated. At the highest level: workflows and event triggers. Inside workflows: jobs and definition of the build environment. Inside jobs: steps. Inside steps: a call to an action. On the right: the evaluated sequence: workflow, job, step, action.](https://user-images.githubusercontent.com/6351798/88589835-f5ce0900-d016-11ea-8c8a-0e7d7907c713.png)
16+
17+
- **Workflow**: A workflow is a unit of automation from its start to finish, including the definition of what triggers the automation, what environment or other aspects should be taken into account during the automation, and what should happen as a result of the trigger.
18+
- **Job**: A job is a section of the workflow, and is made up of one or more steps. In this section of our workflow, the template defines the steps that make up the `build` job.
19+
- **Step**: A step represents one _effect_ of the automation. A step could be defined as a GitHub Action, or another unit, like printing something to the console.
20+
- **Action**: An action is a piece of automation written in a way that is compatible with workflows. Actions can be written by GitHub, by the open source community, or you can write them yourself!
21+
22+
To learn more, check out [Workflow syntax for GitHub Actions](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions) in the GitHub Docs.
23+
24+
First, let's add a workflow to lint (clean, like a lint roller) our Markdown files in this repository.
25+
26+
### :keyboard: Activity: Add a test workflow
27+
28+
1. Open a new browser tab, and work through the following steps in that tab while you read the instructions in this tab.
29+
1. Go to the **Actions tab**.
30+
1. Click **New workflow**.
31+
1. Search for "Simple workflow" and click **Configure**.
32+
1. Name your workflow `ci.yml`.
33+
1. Update the workflow by deleting the last two steps.
34+
1. Add the following step at the end of your workflow:
35+
```yml
36+
- name: Run markdown lint
37+
run: |
38+
npm install remark-cli remark-preset-lint-consistent
39+
npx remark . --use remark-preset-lint-consistent --frail
40+
```
41+
> Even after the code is indented properly in `ci.yml`, you will see a build error in GitHub Actions. We'll fix this in the next step.
42+
1. Click **Commit changes...**, and choose to make a new branch named `ci`.
43+
1. Click **Propose changes**.
44+
1. Click **Create pull request**.
45+
1. Wait about 20 seconds and then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/actions) will automatically update to the next step.

.github/steps/2-fix-the-test.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!--
2+
<<< Author notes: Step 2 >>>
3+
Start this step by acknowledging the previous step.
4+
Define terms and link to docs.github.com.
5+
-->
6+
7+
## Step 2: Fix the test
8+
9+
_Great job adding the templated workflow! :tada:_
10+
11+
Adding that file to this branch is enough for GitHub Actions to begin running CI on your repository.
12+
13+
When a GitHub Actions workflow is running, you should see some checks in progress, like the screenshot below.
14+
15+
<img alt="checks in progress in a merge box" src=https://user-images.githubusercontent.com/16547949/66080348-ecc5f580-e533-11e9-909e-c213b08790eb.png width=400 />
16+
17+
You can follow along as GitHub Actions runs your job by going to the **Actions** tab or by clicking "Details" in the merge box below.
18+
19+
When the tests finish, you'll see a red X :x: or a green check mark :heavy_check_mark: in the merge box. At that point, you can access the logs for the build job and its associated steps.
20+
21+
_By looking at the logs, can you identify which tests failed?_ To find it, go to one of the failed builds and scroll through the log. Look for a section that lists all the unit tests. We're looking for the name of the test with an "x".
22+
23+
<img alt="screenshot of a sample build log with the names of the tests blurred out" src=https://user-images.githubusercontent.com/16547949/65922013-e740a200-e3b1-11e9-8151-faf52c30201e.png width=400 />
24+
25+
If the checks don't appear or if the checks are stuck in progress, there's a few things you can do to try and trigger them:
26+
27+
- Refresh the page, it's possible the workflow ran and the page just hasn't been updated with that change.
28+
- Try making a commit on this branch. Our workflow is triggered with a `push` event, and committing to this branch will result in a new `push`.
29+
- Edit the workflow file on GitHub and ensure there are no red lines indicating a syntax problem.
30+
31+
### :keyboard: Activity: Fix the test
32+
33+
1. Update the contents in the `ci` branch to get the test to pass. You need to look at the logs to see what caused the test to fail.
34+
1. **Commit changes**.
35+
1. Wait about 20 seconds and then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/actions) will automatically update to the next step.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
<<< Author notes: Step 3 >>>
3+
Start this step by acknowledging the previous step.
4+
Define terms and link to docs.github.com.
5+
-->
6+
7+
## Step 3: Upload test reports
8+
9+
_The workflow has finished running! :sparkles:_
10+
11+
So what do we do when we need the work product of one job in another? We can use the built-in [artifact storage](https://docs.github.com/actions/advanced-guides/storing-workflow-data-as-artifacts) to save artifacts created from one job to be used in another job within the same workflow.
12+
13+
To upload artifacts to the artifact storage, we can use an action built by GitHub: [`actions/upload-artifacts`](https://github.com/actions/upload-artifact).
14+
15+
### :keyboard: Activity: Upload test reports
16+
17+
1. Edit your workflow file.
18+
1. Update the `Run markdown lint` step in your `build` job to use `vfile-reporter-json` and output the results to `remark-lint-report.json`.
19+
1. Add a step to your `build` job that uses the `upload-artifact` action. This step should upload the `remark-lint-report.json` file generated by the updated `Run markdown lint` step.
20+
1. Your new `build` should look like this:
21+
22+
```yml
23+
build:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Run markdown lint
29+
run: |
30+
npm install remark-cli remark-preset-lint-consistent vfile-reporter-json
31+
npx remark . --use remark-preset-lint-consistent --report vfile-reporter-json 2> remark-lint-report.json
32+
33+
- uses: actions/upload-artifact@v3
34+
with:
35+
name: remark-lint-report
36+
path: remark-lint-report.json
37+
```
38+
39+
1. Commit your change to this branch.
40+
1. Wait about 20 seconds and then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/actions) will automatically update to the next step.
41+
42+
Like the upload action to send artifacts to the storage, you can use the download action to download these previously uploaded artifacts from the `build` job: [`actions/download-artifact`](https://github.com/actions/download-artifact). For brevity, we'll skip that step for this course.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
<<< Author notes: Step 4 >>>
3+
Start this step by acknowledging the previous step.
4+
Define terms and link to docs.github.com.
5+
-->
6+
7+
## Step 4: Add branch protections
8+
9+
_Great job uploading test reports! :partying_face:_
10+
11+
Take a look at the merge box, you'll notice you can merge this even though the review process hasn't been met.
12+
13+
Protected branches ensure that collaborators on your repository cannot make irrevocable changes to branches. Enabling protected branches also allows you to enable other optional checks and requirements, like required status checks and required reviews.
14+
15+
### :keyboard: Activity: Add branch protections
16+
17+
1. Go to **Branches** settings. You can navigate to that page manually by selecting the right-most tab in the top of the repository called **Settings** and then clicking **Branches**.
18+
1. Click **Add branch protection rule** under "Branch protection rules".
19+
1. Type `main` in **Branch name pattern**.
20+
1. Check **Require a pull request before merging**.
21+
1. Uncheck **Require approvals**.
22+
1. Check **Require status checks to pass before merging**.
23+
1. Check all build and test jobs that you'd like to see in the newly visible gray box.
24+
1. Click **Create**.
25+
1. _Once you turn on branch protection, Actions can no longer push directly to the `main` branch. Wait about 20 seconds and then go to the `ci` branch. [GitHub Actions](https://docs.github.com/actions) will automatically update to the next step on the `ci` branch. You'll need to follow instructions on this branch._
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
<<< Author notes: Step 5 >>>
3+
Start this step by acknowledging the previous step.
4+
Define terms and link to docs.github.com.
5+
-->
6+
7+
## Step 5: Merge your pull request
8+
9+
_Almost there! :heart:_
10+
11+
You can now [merge](https://docs.github.com/get-started/quickstart/github-glossary#merge) your pull request!
12+
13+
### :keyboard: Activity: Merge your pull request
14+
15+
1. Go to the **Pull requests** tab.
16+
1. Click **Merge pull request**.
17+
1. _Once you turn on branch protection, Actions can no longer push directly to the `main` branch. Make sure that you're on the `ci` branch in the page you're following instructions from._ Wait about 20 seconds and then refresh the page. [GitHub Actions](https://docs.github.com/actions) will automatically update to the next step.

.github/steps/X-finish.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
<<< Author notes: Finish >>>
3+
Review what we learned, ask for feedback, provide next steps.
4+
-->
5+
6+
## Finish
7+
8+
_Congratulations friend, you've completed this course!_
9+
10+
<img src=https://octodex.github.com/images/Fintechtocat.png alt=celebrate width=300 align=right>
11+
12+
Here's a recap of all the tasks you've accomplished in your repository:
13+
14+
- We created an Actions workflow to lint our Markdown files.
15+
- You caught an issue in a file and fixed the issue before it could make it to `main`.
16+
- You learned how to use build artifacts for test reports.
17+
- You enabled branch protections to require the workflow to pass before merging.
18+
19+
### What's next?
20+
21+
- Get more ideas of what you can do with [awesome actions](https://github.com/sdras/awesome-actions).
22+
- We'd love to hear what you thought of this course [in our discussion board](https://github.com/orgs/skills/discussions/categories/test-with-actions).
23+
- [Take another GitHub Skills course](https://github.com/skills).
24+
- [Read the GitHub Getting Started docs](https://docs.github.com/get-started).
25+
- To find projects to contribute to, check out [GitHub Explore](https://github.com/explore).

.github/workflows/0-welcome.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Step 0, Welcome
2+
3+
# This step triggers after the learner creates a new repository from the template.
4+
# This workflow updates from step 0 to step 1.
5+
6+
# This will run every time we create push a commit to `main`.
7+
# Reference: https://docs.github.com/actions/learn-github-actions/events-that-trigger-workflows
8+
on:
9+
workflow_dispatch:
10+
push:
11+
branches:
12+
- main
13+
14+
# Reference: https://docs.github.com/actions/security-guides/automatic-token-authentication
15+
permissions:
16+
# Need `contents: read` to checkout the repository.
17+
# Need `contents: write` to update the step metadata.
18+
contents: write
19+
20+
jobs:
21+
# Get the current step to only run the main job when the learner is on the same step.
22+
get_current_step:
23+
name: Check current step number
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- id: get_step
29+
run: |
30+
echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT
31+
outputs:
32+
current_step: ${{ steps.get_step.outputs.current_step }}
33+
34+
on_start:
35+
name: On start
36+
needs: get_current_step
37+
38+
# We will only run this action when:
39+
# 1. This repository isn't the template repository.
40+
# 2. The step is currently 0.
41+
# Reference: https://docs.github.com/actions/learn-github-actions/contexts
42+
# Reference: https://docs.github.com/actions/learn-github-actions/expressions
43+
if: >-
44+
${{ !github.event.repository.is_template
45+
&& needs.get_current_step.outputs.current_step == 0 }}
46+
47+
# We'll run Ubuntu for performance instead of Mac or Windows.
48+
runs-on: ubuntu-latest
49+
50+
steps:
51+
# We'll need to check out the repository so that we can edit the README.
52+
- name: Checkout
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0 # Let's get all the branches.
56+
57+
# In README.md, switch step 0 for step 1.
58+
- name: Update to step 1
59+
uses: skills/action-update-step@v2
60+
with:
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
from_step: 0
63+
to_step: 1
64+
branch_name: ci
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Step 1, Add a test workflow
2+
3+
# This step triggers after push to the ci.yml file on the ci branch.
4+
# This workflow updates from step 1 to step 2.
5+
6+
# This will run every time we push to the ci.yml file on the ci branch.
7+
# Reference: https://docs.github.com/actions/learn-github-actions/events-that-trigger-workflows
8+
on:
9+
workflow_dispatch:
10+
push:
11+
branches:
12+
- ci
13+
paths:
14+
- .github/workflows/ci.yml
15+
16+
# Reference: https://docs.github.com/actions/security-guides/automatic-token-authentication
17+
permissions:
18+
# Need `contents: read` to checkout the repository.
19+
# Need `contents: write` to update the step metadata.
20+
contents: write
21+
22+
jobs:
23+
# Get the current step to only run the main job when the learner is on the same step.
24+
get_current_step:
25+
name: Check current step number
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- id: get_step
31+
run: |
32+
echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT
33+
outputs:
34+
current_step: ${{ steps.get_step.outputs.current_step }}
35+
36+
on_push_ci_file:
37+
name: On push ci file
38+
needs: get_current_step
39+
40+
# We will only run this action when:
41+
# 1. This repository isn't the template repository.
42+
# 2. The step is currently 1.
43+
# Reference: https://docs.github.com/actions/learn-github-actions/contexts
44+
# Reference: https://docs.github.com/actions/learn-github-actions/expressions
45+
if: >-
46+
${{ !github.event.repository.is_template
47+
&& needs.get_current_step.outputs.current_step == 1 }}
48+
49+
# We'll run Ubuntu for performance instead of Mac or Windows.
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
# We'll need to check out the repository so that we can edit the README.
54+
- name: Checkout
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0 # Let's get all the branches.
58+
59+
# Verify the learner added remark-lint.
60+
- name: Verify workflow
61+
uses: skills/action-check-file@v1
62+
with:
63+
file: .github/workflows/ci.yml
64+
search: remark-preset-lint-consistent
65+
66+
# In README.md, switch step 1 for step 2.
67+
- name: Update to step 2
68+
uses: skills/action-update-step@v2
69+
with:
70+
token: ${{ secrets.GITHUB_TOKEN }}
71+
from_step: 1
72+
to_step: 2
73+
branch_name: ci

0 commit comments

Comments
 (0)