Skip to content

Commit

Permalink
Change learner action to be a welcome message on new pull requests (#6)
Browse files Browse the repository at this point in the history
* Update README.md

* Update 0-start.yml

* Update 1-create-a-workflow.yml

* Update 2-add-a-job.yml

* Update 3-add-actions.yml

* Update 4-merge-your-pull-request.yml

* Update 5-trigger.yml

* message -> comment
  • Loading branch information
heiskr committed Jun 8, 2022
1 parent 61e7122 commit 47c4d8a
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 52 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/0-start.yml
Expand Up @@ -51,7 +51,7 @@ jobs:
fi
echo "Make a branch"
BRANCH=emoji-workflow
BRANCH=welcome-workflow
git checkout -b $BRANCH
echo "Make a commit"
Expand All @@ -64,7 +64,7 @@ jobs:
echo "Make a pull request"
# Reference https://cli.github.com/manual/gh_pr_create
gh pr create --title "Create emoji shortcode workflow" --body "Create emoji shortcode workflow"
gh pr create --title "Post welcome comment workflow" --body "Post welcome comment workflow"
echo "Restore main"
git checkout main
Expand All @@ -79,4 +79,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 0
to_step: 1
branch_name: emoji-workflow
branch_name: welcome-workflow
6 changes: 3 additions & 3 deletions .github/workflows/1-create-a-workflow.yml
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:
push:
branches:
- emoji-workflow
- welcome-workflow

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Check workflow contents, name
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/emoji.yml"
FILE: ".github/workflows/welcome.yml"
SEARCH: "name:"

# Update README to close <details id=1> and open <details id=2>
Expand All @@ -53,4 +53,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 1
to_step: 2
branch_name: emoji-workflow
branch_name: welcome-workflow
6 changes: 3 additions & 3 deletions .github/workflows/2-add-a-job.yml
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:
push:
branches:
- emoji-workflow
- welcome-workflow

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Check workflow contents, jobs
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/emoji.yml"
FILE: ".github/workflows/welcome.yml"
SEARCH: "jobs:"

# Update README to close <details id=2> and open <details id=3>
Expand All @@ -53,4 +53,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 2
to_step: 3
branch_name: emoji-workflow
branch_name: welcome-workflow
10 changes: 5 additions & 5 deletions .github/workflows/3-add-actions.yml
Expand Up @@ -10,7 +10,7 @@ on:
workflow_dispatch:
push:
branches:
- emoji-workflow
- welcome-workflow

# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
Expand Down Expand Up @@ -39,11 +39,11 @@ jobs:
fetch-depth: 0 # Let's get all the branches

# Verify the learner added the file contents
- name: Check workflow contents, actions/checkout
- name: Check workflow contents, steps
run: ./.github/script/check-file.sh
env:
FILE: ".github/workflows/emoji.yml"
SEARCH: "actions/checkout"
FILE: ".github/workflows/welcome.yml"
SEARCH: "steps:"

# Update README to close <details id=3> and open <details id=4>
# and set STEP to '4'
Expand All @@ -53,4 +53,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 3
to_step: 4
branch_name: emoji-workflow
branch_name: welcome-workflow
2 changes: 1 addition & 1 deletion .github/workflows/4-merge-your-pull-request.yml
Expand Up @@ -46,4 +46,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 4
to_step: 5
branch_name: emoji-workflow
branch_name: welcome-workflow
4 changes: 2 additions & 2 deletions .github/workflows/5-trigger.yml
Expand Up @@ -4,13 +4,13 @@ name: Step 5, Trigger the workflow
# This step sets STEP to X
# This step closes <details id=5> and opens <details id=X>

# This will run every time we finish running "Check emoji shortcode"
# This will run every time we finish running "Post welcome comment"
# Reference https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
workflow_run:
workflows:
- Check emoji shortcode
- Post welcome comment
types:
- completed

Expand Down
70 changes: 35 additions & 35 deletions README.md
Expand Up @@ -58,27 +58,29 @@ _Welcome to "Hello GitHub Actions"! :wave:_
- The GitHub Actions feature page, see [GitHub Actions](https://github.com/features/actions).
- The "GitHub Actions" user documentation, see [GitHub Actions](https://docs.github.com/actions).

**What is a _workflow_?**: A workflow is a configurable automated process that will run one or more jobs. Workflows are defined in special files in the `.github/workflows` directory and they execute based on your chosen event. For this exercise, we'll use a `push` event.
**What is a _workflow_?**: A workflow is a configurable automated process that will run one or more jobs. Workflows are defined in special files in the `.github/workflows` directory and they execute based on your chosen event. For this exercise, we'll use a `pull_request` event.

- To read more about workflows, jobs, and events, see "[Understanding GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)".
- If you want to learn more about the `push` event before using it, see "[push](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push)".
- If you want to learn more about the `pull_request` event before using it, see "[pull_request](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request)".

To get you started, we used actions to go ahead and made a branch and pull request for you.

### :keyboard: Activity: Create a workflow file

1. Open a new browser tab, and navigate to this same repository. Then, work on the steps in your second tab while you read the instructions in this tab.
1. Navigate to the **Code** tab.
2. From the **main** branch dropdown, click on the **emoji-workflow** branch.
3. Navigate to the `.github/workflows/` folder, then select **Add file** and click on **Create new file**.
4. In the **Name your file...** field, enter `emoji.yml`.
1. Add the following content to the `emoji.yml` file:
1. From the **main** branch dropdown, click on the **welcome-workflow** branch.
1. Navigate to the `.github/workflows/` folder, then select **Add file** and click on **Create new file**.
1. In the **Name your file...** field, enter `welcome.yml`.
1. Add the following content to the `welcome.yml` file:
```yaml
name: Check emoji shortcode
on: push
name: Post welcome comment
on:
pull_request:
types: [opened]
```
2. To commit your changes, click **Commit new file**.
3. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
1. To commit your changes, click **Commit new file**.
1. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.

</details>

Expand All @@ -96,8 +98,8 @@ _Nice work! :tada: You added a workflow file!_

Here's what it means:

- `name: A workflow for my Hello World file` gives your workflow a name. This name appears on any pull request or in the Actions tab of your repository.
- `on: push` indicates that your workflow will execute anytime code is pushed to your repository.
- `name: Post welcome comment` gives your workflow a name. This name appears on any pull request or in the Actions tab of your repository.
- `on: pull_request: types: [opened]` indicates that your workflow will execute anytime a pull request opens in your repository.

Next, we need to specify jobs to run.

Expand All @@ -107,14 +109,16 @@ In this step of our exercise, we will add a "build" job. We will specify `ubuntu

### :keyboard: Activity: Add a job to your workflow file

1. Open your `emoji.yml` file.
1. Open your `welcome.yml` file.
2. Update the contents of the file to:
```yaml
name: Check emoji shortcode
on: push
name: Post welcome comment
on:
pull_request:
types: [opened]
jobs:
build:
name: Check emoji shortcode
name: Post welcome comment
runs-on: ubuntu-latest
```
3. Click **Start commit** in the top right of the workflow editor.
Expand All @@ -138,30 +142,26 @@ Workflows have jobs, and jobs have steps. So now we'll add steps to your workflo

**What are _steps_?**: Actions steps will run during our job in order. Each step is either a shell script that will be executed, or an action that will be run. Each step must pass for the next step to run. Actions steps can be used from within the same repository, from any other public repository, or from a published Docker container image.

In our action, we will have steps for each of the following:
1. Checkout the code with `git checkout`, using a [pre-built checkout action](https://github.com/actions/checkout).
2. Run a [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) script to check Markdown files.
3. Fail with (`exit 1`) if any Markdown file contains an emoji without using [emoji shortcodes](https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md).
In our action, we post a comment on the pull request using a [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) script and [GitHub CLI](https://cli.github.com/).

### :keyboard: Activity: Add Actions steps to your workflow file

1. Open your `emoji.yml` file.
1. Open your `welcome.yml` file.
2. Update the contents of the file to:
```yaml
name: Check emoji shortcode
on: push
name: Post welcome comment
on:
pull_request:
types: [opened]
jobs:
build:
name: Check emoji shortcode
name: Post welcome comment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
if LC_ALL=C grep -R '[^ -~]' *.md; then
echo "Use emoji shortcodes instead!"
echo "See https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md"
exit 1
fi
- run: gh pr comment $PR_URL --body "Welcome to the repository!"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
```
3. Click **Start commit** in the top right of the workflow editor.
4. Type your commit message and commit your changes directly to your branch.
Expand All @@ -185,9 +185,9 @@ Merge your pull request so the action will be a part of the `main` branch.
### :keyboard: Activity: Merge your workflow file

1. In your repo, click on the **Pull requests** tab.
2. Click on the **Create emoji shortcode workflow** pull request.
2. Click on the **Post welcome comment workflow** pull request.
3. Click **Merge pull request**, then click **Confirm merge**.
4. Optionally, click **Delete branch** to delete your `emoji-workflow` branch.
4. Optionally, click **Delete branch** to delete your `welcome-workflow` branch.
5. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.

</details>
Expand All @@ -212,8 +212,8 @@ Your new action will run any time a new commit is created or pushed to the remot
### :keyboard: Activity: Trigger the workflow

1. Make a new branch named `test-workflow`.
1. Commit any change to your branch, such as adding an emoji to your README.md file. If you want to see what happens if an action fails, add an emoji without using shortcode.
2. View the pull request on your branch.
1. Commit any change to your branch, such as adding an emoji to your README.md file.
2. Create the pull request on your branch.
3. See your action run on your pull request.
4. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.

Expand Down

0 comments on commit 47c4d8a

Please sign in to comment.