Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit d8d5d32

Browse files
committed
add initial steps
1 parent ab67136 commit d8d5d32

File tree

10 files changed

+254
-8
lines changed

10 files changed

+254
-8
lines changed

config.yml

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
title: write-github-script
1+
title: GitHub Actions: "Using GitHub Script"
22
description: >-
33
This course covers how to use GitHub Script to quickly use octokit/rest in a
44
GitHub Actions workflow.
@@ -7,12 +7,129 @@ template:
77
name: write-github-script
88
before:
99
- type: createIssue
10-
title: Welcome!
11-
body: new-issue.md
10+
title: Start here!
11+
body: 01_welcome-issue.md
12+
action_id: welcomeIssue
13+
- type: respond
14+
issue: "%actions.welcomeIssue.data.number%"
15+
with: 01_welcome-activity.md
16+
data:
17+
quicklink: "%payload.repository.html_url%/new/master?filename=.github/workflows/my-workflow.yml&workflow_template=blank"
18+
actionsUrl: "%payload.repository.html_url%/actions/new"
19+
1220
steps:
13-
- title: First step
14-
description: The first step in your course
15-
event: issues.assigned
16-
link: '{{ repoUrl }}'
21+
- title: Setup a workflow file
22+
description: Create a pull request to add a workflow
23+
event: pull_request
24+
link: "{{ repoUrl }}/issues/%payload.pull_request.number%"
1725
actions:
26+
- type: gate
27+
gates:
28+
# if the payload action is 'opened' OR 'edited'
29+
- left: "%payload.action%"
30+
operator: ===
31+
right: opened
32+
- left: "%payload.action%"
33+
operator: ===
34+
right: edited
35+
# AND the pull request title equals 'Create my-workflow.yml'
36+
- type: gate
37+
left: "%payload.pull_request.title%"
38+
operator: ===
39+
right: Create my-workflow.yml
40+
41+
# if those statments FAIL... do this
42+
else:
43+
- type: respond
44+
with: e-rename-pr.md
45+
data:
46+
title: Create my-workflow.yml
47+
# if those gates === true Then do this stuff
48+
49+
#######################################################
50+
# Validate the filepath for the my-workflow.yml file
51+
# get tree
52+
- type: getTree
53+
action_id: isInTree
54+
recursive: true
55+
sha: "%payload.pull_request.head.sha%"
56+
# check for a file in a tree
57+
- type: gate
58+
left: "%actions.isInTree.data.tree%"
59+
operator: includes
60+
right: "path:.github/workflows/my-workflow.yml"
61+
else:
62+
# if file isn't where expected find true location
63+
- type: findInTree
64+
path: my-workflow.yml
65+
tree: "%actions.isInTree.data.tree%"
66+
# multiple: true
67+
action_id: fileLocation
68+
# help user with proper file location
69+
- type: respond
70+
with: e-wrong-file-location.md
71+
data:
72+
haveFile: "%actions.fileLocation.path%"
73+
needFile: ".github/actions/cat-facts/action.yml"
74+
editLink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/%actions.fileLocation.path%"
75+
fileName: my-workflow.yml
76+
# End filepath verification
77+
#######################################################
78+
- type: respond
79+
issue: Start here!
80+
with: new-pull-request.md
81+
data:
82+
pullUrl: "%payload.pull_request.html_url%"
1883
- type: closeIssue
84+
issue: Start here!
85+
- type: respond
86+
with: 01_explain-workflow.md
87+
data:
88+
actionsUrl: "%payload.repository.html_url%/actions"
89+
- type: respond
90+
with: 02_modify-workflow.md
91+
issue: Create my-workflow.yml
92+
data:
93+
workflowFile: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/my-workflow.yml"
94+
95+
- title: Open an issue to trigger GitHub Script workflow
96+
description: Use GitHub script to comment when an issue is opened
97+
event: pull_request.synchronize
98+
link: "{{ repoUrl }}/issues/%payload.pull_request.number%"
99+
actions:
100+
#######################################################
101+
# Validate the filepath for the my-workflow.yml file
102+
# get tree
103+
- type: getTree
104+
action_id: isInTree
105+
recursive: true
106+
sha: "%payload.pull_request.head.sha%"
107+
# check for a file in a tree
108+
- type: gate
109+
left: "%actions.isInTree.data.tree%"
110+
operator: includes
111+
right: "path:.github/workflows/my-workflow.yml"
112+
else:
113+
# if file isn't where expected find true location
114+
- type: findInTree
115+
path: my-workflow.yml
116+
tree: "%actions.isInTree.data.tree%"
117+
# multiple: true
118+
action_id: fileLocation
119+
# help user with proper file location
120+
- type: respond
121+
with: e-wrong-file-location.md
122+
data:
123+
haveFile: "%actions.fileLocation.path%"
124+
needFile: ".github/actions/cat-facts/action.yml"
125+
editLink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/%actions.fileLocation.path%"
126+
fileName: my-workflow.yml
127+
# End filepath verification
128+
#######################################################
129+
- type: respond
130+
issue: Start here!
131+
with: 03_create-an-issue.md
132+
data:
133+
pullUrl: "%payload.pull_request.html_url%"
134+
actionsUrl: "%payload.repository.html_url%/actions"
135+
workflowFile: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/my-workflow.yml"

responses/01_explain-workflow.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## You have triggered a workflow!
2+
3+
Great job @{{user.login}}, you successfully added a workflow to this repository 🎉! Adding that file to this branch is enough for GitHub Actions to begin running. The time this takes will vary based on the complexity of the workflow.
4+
5+
At this point we can ignore the workflow because it doesn't do anything yet 😢, but we will be modifying it many times to explore using GitHub Script.
6+
7+
---
8+
9+
If you want to inspect the workflows that are configured in this repository, you can do so by heading over to the [Actions tab]({{actionsUrl}}) of this repository.

responses/01_welcome-activity.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Configuring a workflow
2+
3+
### :keyboard: Activity: Create a pull request to prepare the repository for actions
4+
5+
1. Create a new workflow file titled `my-workflow.yml` by using the instructions below, or [this quicklink]({{quicklink}}).
6+
- Go to the [Actions tab]({{ actionsUrl }}).
7+
- Choose the **Set up a workflow yourself** option, located on the top right hand corner of the screen.
8+
- Change the name of the file from `main.yml` to `my-workflow.yml`.
9+
1. Commit the workflow to a new branch.
10+
1. Create a pull request titled **Create my-workflow.yml**.
11+
1. Supply the pull request body content and click `Create pull request`.
12+
13+
_It is important to place meaningful content into the body of the pull requests you create throughout this course. This repository will stay with you long after you complete the course. It is advisable that you use the body of the pull requests you create as a way to take long lived notes about thing you want to remember._
14+
15+
<details><summary>Suggested body content</summary>
16+
17+
`Workflow files are the recipe for task automation. This is where actions are placed if I want to use them for a task.`
18+
19+
</details>
20+
21+
I'll respond in the new pull request when I detect it has been created.
22+
23+
---
24+
25+
If at any point you're expecting a response and don't see one, refresh the page.

responses/01_welcome-issue.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Hi there 👋!
2+
3+
Hello @{{user.login}}, I'm so excited to teach you how to use GitHub Script in your workflows 😄
4+
5+
Actions are enabled on your repository by default, but we still have to tell our repository to use them. We do this by creating a workflow file in our repository.
6+
7+
#### What is a workflow file?
8+
9+
A **workflow** file can be thought of as the recipe for automating a task. They house the start to finish instructions, in the form of `jobs` and `steps`, for what should happen based on specific triggers.
10+
11+
Your repository can contain multiple **workflow** files that carry out a wide variety of tasks. It is important to consider this when deciding on a name for your **workflow**. The name you choose should reflect the tasks being performed.
12+
13+
_In our case, we will use this one **workflow** file for many things, which leads us to break this convention for teaching purposes._
14+
15+
---
16+
17+
<!-- 💻 Actively learn about workflows by enrolling in [this Learning Lab course which has no name or content yet]() -->
18+
19+
📖 Read more about [workflows](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#choosing-the-type-of-actions-for-your-workflow)

responses/02_modify-workflow.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Edit the current workflow
2+
3+
Currently `my-workflow.yml` is not set up correctly for our use-case. Before we make any changes now is a good time to answer **what is GitHub Script?**
4+
5+
**GitHub Script**
6+
7+
[GitHub Script](https://github.com/actions/github-script) is a really awesome action that allows you to quickly interact with the GitHub API directly in your workflow!
8+
9+
You can think of this as a way to run simple functions without the need to build a bulky custom action to do so.
10+
11+
📖 See [octokit/rest.js](https://octokit.github.io/rest.js/) for the API client
12+
documentation.
13+
14+
### :keyboard: Activity: Use GitHub Script in a workflow to comment on an issue
15+
16+
1. [Edit]({{workflowFile}}) the `.github/workflows/my-workflow.yml` so that it has the contents below:
17+
18+
```yaml
19+
name: Learning GitHub Script
20+
21+
on:
22+
issues:
23+
types: [opened]
24+
25+
jobs:
26+
comment:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/github-script@0.8.0
30+
with:
31+
github-token: ${{secrets.GITHUB_TOKEN}}
32+
script: |
33+
github.issues.createComment({
34+
issue_number: context.issue.number,
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
body: '🎉 You've created this issue comment using GitHub Script!!!'
38+
})
39+
```
40+
41+
1. Commit these file changes to this branch
42+
43+
---
44+
45+
I'll respond in this pull request once you make these changes.

responses/03_create-an-issue.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Congrats
2+
3+
@{{user.login}} go create an issue to trigger your workflow

responses/e-rename-pr.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Oh no... I found an error ⚠️
2+
3+
**Error**
4+
The title of this pull request isn't what I expected!
5+
6+
**Solution**
7+
Verify the name of your pull request is **{{title}}** and keep in mind that this is case-sensitive.
8+
9+
Follow these steps to rename your pull request:
10+
1. Click on **Edit** next to the pull request's title.
11+
1. The title will turn to a text field, **{{ title }}** in the title field.
12+
1. Click **Save**.
13+
14+
I'll respond when I detect this pull request has been renamed.

responses/e-wrong-file-location.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Oops....
2+
3+
It seems as though your file is located here:
4+
5+
`{{haveFile}}`
6+
7+
and it should be located here:
8+
9+
`{{needFile}}`
10+
11+
**Solution**
12+
Click [here]({{editLink}}) to edit `{{fileName}}` and move it to the proper directory

responses/new-issue.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

responses/new-pull-request.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## A new pull request
2+
3+
I have created a [new pull request]({{pullUrl}}) where we will continue this lesson. Click the link to meet me over there.

0 commit comments

Comments
 (0)