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

Commit f66fad4

Browse files
committed
adding more steps
1 parent c453271 commit f66fad4

File tree

8 files changed

+238
-3
lines changed

8 files changed

+238
-3
lines changed

config.yml

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ steps:
130130
right: "GitHub Actions"
131131
else:
132132
- type: respond
133-
issue: Create an issue comment with GitHub Script
133+
issue: 3
134134
with: debug.md
135135
data:
136136
debug: "%payload%"
@@ -240,3 +240,85 @@ steps:
240240
issue: Update my-workflow.yml
241241
data:
242242
issueURL: "%actions.triggerIssue.data.html_url%"
243+
244+
- title: Break your workflow into multiple steps
245+
description: Separate the workflow concerns by adding more steps
246+
event: check_suite.completed
247+
link: "{{repoUrl}}/issues/5"
248+
actions:
249+
- type: gate
250+
left: "%payload.check_suite.app.name%"
251+
operator: ===
252+
right: "GitHub Actions"
253+
else:
254+
- type: respond
255+
issue: 5
256+
with: debug.md
257+
data:
258+
debug: "%payload%"
259+
- type: octokit
260+
method: projects.listForRepo
261+
owner: "%payload.repository.owner.login%"
262+
repo: "%payload.repository.name%"
263+
action_id: projectBoard
264+
- type: octokit
265+
method: projects.listColumns
266+
project_id: "%actions.projectBoard.data.0.id%"
267+
action_id: listColumns
268+
- type: respond
269+
with: 06_steps-overview.md
270+
data:
271+
projectTab: "%payload.repository.html_url%/projects/1"
272+
- type: respond
273+
with: 06_steps-activity.md
274+
data:
275+
listProj: "%actions.projectBoard.data%"
276+
listCol: "%actions.listColumns.data%"
277+
columnID: "%actions.listColumns.data.0.id%"
278+
quicklink: "%payload.repository.html_url%/edit/master/.github/workflows/my-workflow.yml"
279+
actionsTab: "%paylaod.repository.html_url%/actions"
280+
281+
- title: Create better comments
282+
description: Use a templated repsonse as the comment body
283+
event: pull_request
284+
link: "{{repoUrl}}/pull/6"
285+
actions:
286+
- type: respond
287+
with: 07_explain-node.md
288+
- type: respond
289+
with: 07_use-fs.md
290+
data:
291+
quicklink: "%payload.repository.html_url%/edit/%payload.head.ref%/.github/workflows/my-workflow.yml"
292+
293+
- title: Merge the final workflow
294+
description: Merge the final workflow into the repository
295+
event: pull_request.synchronize
296+
link: "{{repoUrl}}/pull/6"
297+
actions:
298+
- type: removeBranchProtection
299+
- type: respond
300+
with: 08_merge-workflow.md
301+
302+
- title: Course recap
303+
description: Final remarks on course content
304+
event: pull_request.closed
305+
link: "{{repoUrl}}/issue/7"
306+
actions:
307+
- type: octokit
308+
method: issues.create
309+
owner: "%payload.repository.owner.login%"
310+
repo: "%payload.repository.name%"
311+
title: It's alive!
312+
body: |
313+
## Great Job so far!
314+
315+
Like before, now we have to wait for the
316+
workflow to run so that we can see the results. I'll respond here once it has completed!
317+
labels: ["bug"]
318+
- type: respond
319+
with: 09_workflow-completed.md
320+
issue: It's alive!
321+
# - type: createIssue
322+
# title: It's alive!
323+
# body: 09_workflow-triggered
324+
# action_id: triggerIssue

responses/03_add-to-projects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ We've gone ahead and done this on our end of things so that we could give you th
2020
name: Learning GitHub Script
2121

2222
on:
23-
issues:
23+
issues:
2424
types: [opened]
2525

2626
jobs:
27-
comment:
27+
comment:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- uses: actions/github-script@0.8.0

responses/06_steps-activity.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Add steps for each action
2+
3+
We will make the following changes to the current workflow file:
4+
5+
- Name each step so we can easily keep track of it in the [actions tab]({{actionTab}})
6+
- Use expressions to determine `if` a step should execute
7+
8+
### :keyboard: Activity: Add newly opened issue to project board
9+
10+
1. [Edit]({{quicklink}}) the current workflow `.github/workflows/my-workflow.yml` to have he following contents:
11+
12+
```yaml
13+
name: Learning GitHub Script
14+
15+
on:
16+
issues:
17+
types: [opened]
18+
19+
jobs:
20+
comment:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Comment on new issue
24+
uses: actions/github-script@0.8.0
25+
with:
26+
github-token: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
27+
script: |
28+
github.issues.createComment({
29+
issue_number: context.issue.number,
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
body: "🎉 You've created this issue comment using GitHub Script!!!"
33+
})
34+
35+
- name: Add issue to project board
36+
if: contains(github.event.issue.labels.*.name, 'bug')
37+
uses: actions/github-script@0.8.0
38+
with:
39+
github-token: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
40+
script: |
41+
github.projects.createCard({
42+
column_id: {{columnID}},
43+
content_id: context.payload.issue.id,
44+
content_type: "Issue"
45+
});
46+
47+
```
48+
49+
2. Commit the workflow to a new branch.
50+
3. Create a pull request titled **Update my-workflow.yml**.
51+
4. Supply the pull request body content and click `Create pull request`.
52+
53+
---
54+
55+
I'll respond in the pull request you create

responses/06_steps-overview.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Let's improve the workflow
2+
3+
@{{user.login}} it looks like you workflow has completed! Let's take a look at the results!
4+
5+
We should be pretty familiar with the first portion of the workflow, it's the same as the first time it ran, and it just creates a comment whenever a new issue has been created.
6+
7+
The second portion may exactly be clear to you, but this issue was added to a project board that is present in this repository. Checkout the [projects tab]({{projectTab}}) if you want to see that this issue has been added!
8+
9+
#### Multiple steps
10+
11+
One benefit of using actions is the ability to separate `jobs` into smaller units of work called `steps`. If we think about what our workflow is doing we can see that it makes more sense to have these two tasks take place across two steps.
12+
13+
As an added advantage, once we break the current workflow into multiple steps we can apply logic through expressions to them. This will let us create rules around when steps are allowed to run. Ultimately this allows us to optimize our workflow run!
14+
15+
Since GitHub Script is simply an action, breaking each unique task into a new step works just fine! We will do this in our next activity!

responses/07_explain-node.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Improving the issue comment
2+
3+
💡Did you know that GitHub Script also grants you access to a full Node.js environment?
4+
5+
Although we wouldn't recommend using GitHub Script to write the logic for complex actions, there are use cases where you may want to leverage using a little more than just the octokit/rest.js API.
6+
7+
One such use case is our issue comment. Right now it is pretty hard coded the way it is making it less than ideal. What if we wanted to display our contribution guide every time an issue was opened?
8+
9+
Instead of writing the guide directly into our workflow, we can use the Node.js File System module to read a file and use it as the body of our issue comment.
10+
11+
If we want access to the files within our repository, we need to make sure we include the `actions/checkout` action in our workflow as the first step.

responses/07_use-fs.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Use the FS module to use a templated comment
2+
3+
We will make the following changes to the current workflow file:
4+
5+
- Add the `actions/checkout` action so we can read the templated response file located at `.github/ISSUE_RESPONSES/comment.md`
6+
- Add JavaScript to use the Node.js File System module to place the contents of our templated response as the body of the issue comment.
7+
8+
### :keyboard: Activity: Add newly opened issue to project board
9+
10+
1. [Edit]({{quicklink}}) the current workflow to have he following contents:
11+
12+
```yaml
13+
name: Learning GitHub Script
14+
15+
on:
16+
issues:
17+
types: [opened]
18+
19+
jobs:
20+
comment:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v2
25+
26+
- name: Comment on new issue
27+
uses: actions/github-script@0.8.0
28+
with:
29+
github-token: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
30+
script: |
31+
const fs = require('fs')
32+
const issueBody = fs.readFileSync(".github/ISSUE_RESPONSES/comment.md", "utf8")
33+
github.issues.createComment({
34+
issue_number: context.issue.number,
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
body: issueBody
38+
})
39+
40+
- name: Add issue to project board
41+
if: contains(github.event.issue.labels.*.name, 'bug')
42+
uses: actions/github-script@0.8.0
43+
with:
44+
github-token: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
45+
script: |
46+
github.projects.createCard({
47+
column_id: {{columnID}},
48+
content_id: context.payload.issue.id,
49+
content_type: "Issue"
50+
});
51+
52+
```
53+
54+
2. Commit the workflow changes to this branch.
55+
56+
---
57+
58+
I'll respond once you've committed the changes to this branch

responses/08_merge-workflow.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Time to see the magic in action!
2+
3+
@{{user.login}}, All of the necessary changes have been made, and our workflow now contains enough information to be quite awesome!
4+
5+
### :keyboard: Activity: Merge the workflow
6+
7+
When you are ready, merge this pull request.
8+
9+
---
10+
11+
Once you have merged this pull request I will open a new issue so we can see this workflow in action!
12+
13+
<details><summary>Trouble merging?</summary>Try refreshing the page!</details>

responses/09_workflow-completed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# super awesome workflow has been triggered

0 commit comments

Comments
 (0)