Skip to content

Commit

Permalink
Add exercise files
Browse files Browse the repository at this point in the history
  • Loading branch information
a-a-ron committed Sep 14, 2022
1 parent 098c36d commit 7ed42bd
Show file tree
Hide file tree
Showing 13 changed files with 1,152 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/script/STEP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
17 changes: 17 additions & 0 deletions .github/script/check-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Make sure this file is executable
# chmod a+x .github/script/check-file.sh

# Make sure to escape your backslashes => \\ <= in YAML
# So that its still a single \ in bash

echo "Check that $FILE includes $SEARCH"
if grep --extended-regexp "$SEARCH" -- $FILE
then
echo "Found $SEARCH in $FILE"
else
echo "Missing $SEARCH in $FILE"
echo "----------------"
echo "$(cat $FILE)"
exit 204 # We're sending a weird code so it looks different from other "failures"
fi
81 changes: 81 additions & 0 deletions .github/workflows/0-start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Step 0, Start

# This step triggers after the learner creates a new repository from the template
# This step sets STEP to 1
# This step closes <details id=0> and opens <details id=1>

# This will run every time we create push a commit to `main`
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- main

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write
pull-requests: write

jobs:
on_start:
name: On start

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Make a branch, file, commit, and pull request for the learner
- name: Prepare a pull request, branch, and file
run: |
echo "Make sure we are on step 0"
if [ "$(cat .github/script/STEP)" != 0 ]
then
echo "Current step is not 0"
exit 0
fi
echo "Make a branch"
BRANCH=reusable-workflow
git checkout -b $BRANCH
echo "Make a commit"
git config user.name github-actions
git config user.email [email protected]
git commit --allow-empty --message="Create an empty commit"
echo "Push"
git push --set-upstream origin $BRANCH
echo "Make a pull request"
# Reference https://cli.github.com/manual/gh_pr_create
gh pr create --title "Reusable workflow example" --body "Reusable workflow example"
echo "Restore main"
git checkout main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Update README to close <details id=0> and open <details id=1>
# and set STEP to '1'
- name: Update to step 1
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 0
to_step: 1
branch_name: reusable-workflow
56 changes: 56 additions & 0 deletions .github/workflows/1-make-workflow-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Step 1, Make a workflow reusable

# This step triggers after step0
# This step sets STEP to 2
# This step closes <details id=1> and opens <details id=2>

# This will run every time we TBD-step-1-event-desc
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- reusable-workflow

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write

jobs:
make_reusable_workflow:
name: Make reusable workflow

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Verify the learner added the file contents
- name: Check workflow contents, workflow call
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/reusable-workflow.yml"
SEARCH: "workflow_call:"

# Update README to close <details id=1> and open <details id=2>
# and set STEP to '2'
- name: Update to step 2
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 1
to_step: 2
branch_name: reusable-workflow
58 changes: 58 additions & 0 deletions .github/workflows/2-add-a-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Step 2, Add a job

# This step triggers after TBD-step-2-event-desc
# This step sets STEP to 3
# This step closes <details id=2> and opens <details id=3>

# This will run every time we TBD-step-2-event-desc
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- reusable-workflow
paths-ignore:
- '.github/workflows/reusable-workflow.yml'

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write

jobs:
on_add_job:
name: On add job

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Verify the learner added the file contents
- name: Check workflow syntax, new job
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/my-starter-workflow.yml"
SEARCH: "uses: ./.github/workflows/reusable-workflow.yml"

# Update README to close <details id=2> and open <details id=3>
# and set STEP to '3'
- name: Update to step 3
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 2
to_step: 3
branch_name: reusable-workflow
58 changes: 58 additions & 0 deletions .github/workflows/3-add-matrix-strategy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Step 3, Add a Matrix Strategy

# This step triggers after TBD-step-3-event-desc
# This step sets STEP to 4
# This step closes <details id=3> and opens <details id=4>

# This will run every time we TBD-step-3-event-desc
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- reusable-workflow
paths-ignore:
- '.github/workflows/reusable-workflow.yml'

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write

jobs:
on_matrix_strategy:
name: On matrix strategy

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Verify the learner added the file contents
- name: Check workflow contents, matrix strategy
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/my-starter-workflow.yml"
SEARCH: "matrix:"

# Update README to close <details id=3> and open <details id=4>
# and set STEP to '4'
- name: Update to step 4
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 3
to_step: 4
branch_name: reusable-workflow
49 changes: 49 additions & 0 deletions .github/workflows/4-merge-your-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Step 4, Merge your pull request

# This step triggers after TBD-step-4-event-desc
# This step sets STEP to 5
# This step closes <details id=4> and opens <details id=5>

# This will run every time we TBD-step-4-event-desc
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- main

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write

jobs:
on_merge:
name: On merge

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Update README to close <details id=4> and open <details id=5>
# and set STEP to '5'
- name: Update to step 5
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 4
to_step: 5
branch_name: reusable-workflow
51 changes: 51 additions & 0 deletions .github/workflows/6-trigger-the-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Step 5, Trigger the workflow

# This step triggers after a pull request is merged to `main`
# This step sets STEP to X
# This step closes <details id=5> and opens <details id=X>

# This will run every time we create push a commit to `main`
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
workflow_run:
workflows:
- My Starter Workflow
types:
- completed

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
contents: write

jobs:
on_trigger:
name: On trigger

# We will only run this action when:
# 1. This repository isn't the template repository
# Reference https://docs.github.com/en/actions/learn-github-actions/contexts
# Reference https://docs.github.com/en/actions/learn-github-actions/expressions
if: ${{ !github.event.repository.is_template }}
# TBD replace `skills` with your organization name, if applicable

# We'll run Ubuntu for performance instead of Mac or Windows
runs-on: ubuntu-latest

steps:
# We'll need to check out the repository so that we can edit the README
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # Let's get all the branches

# Update README to close <details id=5> and open <details id=X>
# and set STEP to 'X'
- name: Update to step X
uses: skills/action-update-step@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 5
to_step: X
18 changes: 18 additions & 0 deletions .github/workflows/my-starter-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: My Starter Workflow

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy to your project.
Loading

0 comments on commit 7ed42bd

Please sign in to comment.