├── .github
├── steps
│ ├── -step.txt
│ ├── 0-welcome.md
│ ├── 4-merge-your-pull-request.md
│ ├── X-finish.md
│ ├── 5-trigger.md
│ ├── 2-add-a-job.md
│ ├── 3-add-actions.md
│ └── 1-create-a-workflow.md
├── dependabot.yml
└── workflows
│ ├── 4-merge-your-pull-request.yml
│ ├── 5-trigger.yml
│ ├── 2-add-a-job.yml
│ ├── 3-add-actions.yml
│ ├── 1-create-a-workflow.yml
│ └── 0-welcome.yml
├── .gitignore
├── LICENSE
└── README.md
/.github/steps/-step.txt:
--------------------------------------------------------------------------------
1 | 0
2 |
--------------------------------------------------------------------------------
/.github/steps/0-welcome.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | schedule:
6 | interval: "monthly"
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.exe
7 | *.o
8 | *.so
9 |
10 | # Packages #
11 | ############
12 | # it's better to unpack these files and commit the raw source
13 | # git has its own built in compression methods
14 | *.7z
15 | *.dmg
16 | *.gz
17 | *.iso
18 | *.jar
19 | *.rar
20 | *.tar
21 | *.zip
22 |
23 | # Logs and databases #
24 | ######################
25 | *.log
26 | *.sql
27 | *.sqlite
28 |
29 | # OS generated files #
30 | ######################
31 | .DS_Store
32 | .DS_Store?
33 | ._*
34 | .Spotlight-V100
35 | .Trashes
36 | ehthumbs.db
37 | Thumbs.db
38 |
--------------------------------------------------------------------------------
/.github/steps/4-merge-your-pull-request.md:
--------------------------------------------------------------------------------
1 | ## Step 4: Merge your workflow file
2 |
3 | _You're now able to write and run an Actions workflow! :sparkles:_
4 |
5 | Merge your changes so the action will be a part of the `main` branch.
6 |
7 | ### :keyboard: Activity: Merge your workflow file
8 |
9 | 1. In your repo, click on the **Pull requests** tab.
10 | 1. Click on the pull request you created in step 1.
11 | 1. Click **Merge pull request**, then click **Confirm merge**.
12 | 1. Optionally, click **Delete branch** to delete your `welcome-workflow` branch.
13 | 1. Wait about 20 seconds, then refresh this page (the one you're following instructions from). Another workflow will run and will replace the contents of this README file with instructions for the next step.
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) GitHub, Inc.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/.github/steps/X-finish.md:
--------------------------------------------------------------------------------
1 | ## Finish
2 |
3 | _Congratulations friend, you've completed this course!_
4 |
5 |
6 |
7 | Here's a recap of all the tasks you've accomplished in your repository:
8 |
9 | - You've created your first GitHub Actions workflow file.
10 | - You learned where to make your workflow file.
11 | - You defined an event trigger, a job, and a step for your workflow.
12 | - You're ready to automate anything you can dream of.
13 |
14 | ### What's next?
15 |
16 | - Learn more about GitHub Actions by reading "[Learn GitHub Actions](https://docs.github.com/actions/learn-github-actions)"
17 | - Use actions created by others in [awesome-actions](https://github.com/sdras/awesome-actions)
18 | - We'd love to hear what you thought of this course [in our discussion board](https://github.com/orgs/skills/discussions/categories/hello-github-actions)
19 | - [Take another course on GitHub Actions](https://skills.github.com/#automate-workflows-with-github-actions)
20 | - Learn more about GitHub by reading the "[Get started](https://docs.github.com/get-started)" docs
21 | - To find projects to contribute to, check out [GitHub Explore](https://github.com/explore)
22 |
--------------------------------------------------------------------------------
/.github/steps/5-trigger.md:
--------------------------------------------------------------------------------
1 | ## Step 5: Trigger the workflow
2 |
3 | _You've now added a fully functioning workflow to your repository! :smile:_
4 |
5 | The shell script in the workflow will run whenever a new pull request is opened.
6 |
7 | **Seeing your _action_ in action**: The status of each workflow run that's triggered is shown in the pull request before it's merged: look for **All checks have passed** when you try out the steps below. You can also see a list of all the workflows that are running, or have finished running, in the **Actions** tab of your repository. From there, you can click on each workflow run to view more details and access log files.
8 |
9 | 
10 |
11 | ### :keyboard: Activity: Trigger the workflow
12 |
13 | 1. Make a new branch named `test-workflow`.
14 | 1. Make a change, such as adding an emoji to your README.md file, and commit the change directly to your new branch.
15 | 1. In the **Pull requests** tab, create a pull request that will merge `test-workflow` into `main`.
16 | 1. Watch the workflow running in the checks section of the pull request.
17 | 1. Notice the comment that the workflow adds to the pull request.
18 | 1. Wait about 20 seconds, then refresh this page (the one you're following instructions from). Another workflow will run and will replace the contents of this README file with instructions for the next step.
19 |
--------------------------------------------------------------------------------
/.github/workflows/4-merge-your-pull-request.yml:
--------------------------------------------------------------------------------
1 | name: Step 4, Merge your pull request
2 |
3 | # This step triggers after a pull request is merged to `main`.
4 | # This workflow updates from step 4 to step 5.
5 |
6 | # This will run every time we create push a commit to `main`.
7 | # Reference: https://docs.github.com/en/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/en/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_merge:
35 | name: On merge
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 4.
41 | # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
42 | # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
43 | if: >-
44 | ${{ !github.event.repository.is_template
45 | && needs.get_current_step.outputs.current_step == 4 }}
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 4 for step 5.
58 | - name: Update to step 5
59 | uses: skills/action-update-step@v2
60 | with:
61 | token: ${{ secrets.GITHUB_TOKEN }}
62 | from_step: 4
63 | to_step: 5
64 | branch_name: welcome-workflow
65 |
--------------------------------------------------------------------------------
/.github/workflows/5-trigger.yml:
--------------------------------------------------------------------------------
1 | name: Step 5, Trigger the workflow
2 |
3 | # This step triggers after we finish running "Post welcome comment".
4 | # This workflow updates from step 5 to step X.
5 |
6 | # This will run every time we finish running "Post welcome comment".
7 | # Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
8 | on:
9 | workflow_dispatch:
10 | workflow_run:
11 | workflows:
12 | - Post welcome comment
13 | types:
14 | - completed
15 |
16 | # Reference: https://docs.github.com/en/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_trigger:
37 | name: On trigger
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 5.
43 | # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
44 | # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
45 | if: >-
46 | ${{ !github.event.repository.is_template
47 | && needs.get_current_step.outputs.current_step == 5 }}
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 | # In README.md, switch step 5 for step X.
60 | - name: Update to step X
61 | uses: skills/action-update-step@v2
62 | with:
63 | token: ${{ secrets.GITHUB_TOKEN }}
64 | from_step: 5
65 | to_step: X
66 | branch_name: test-workflow
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Hello GitHub Actions
4 |
5 | _Create and run a GitHub Actions workflow._
6 |
7 |
8 |
9 | ## Welcome
10 |
11 | Automation is key for streamlining your work processes, and [GitHub Actions](https://docs.github.com/actions) is the best way to supercharge your workflow.
12 |
13 | - **Who is this for**: Developers, DevOps engineers, students, managers, teams, GitHub users.
14 | - **What you'll learn**: How to create workflow files, trigger workflows, and find workflow logs.
15 | - **What you'll build**: An Actions workflow that will check emoji shortcode references in Markdown files.
16 | - **Prerequisites**: In this course you will work with issues and pull requests, as well as edit files. We recommend you take the [Introduction to GitHub](https://github.com/skills/introduction-to-github) course first.
17 | - **How long**: This course can be finished in less than two hours.
18 |
19 | In this course, you will:
20 |
21 | 1. Create a workflow
22 | 2. Add a job
23 | 3. Add a run step
24 | 4. Merge your pull request
25 | 5. See effect of the workflow
26 |
27 | ### How to start this course
28 |
29 | [](https://github.com/new?template_owner=skills&template_name=hello-github-actions&owner=%40me&name=skills-hello-github-actions&description=My+clone+repository&visibility=public)
30 |
31 | 1. Right-click **Start course** and open the link in a new tab.
32 | 2. In the new tab, most of the prompts will automatically fill in for you.
33 | - For owner, choose your personal account or an organization to host the repository.
34 | - We recommend creating a public repository, as private repositories will [use Actions minutes](https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions).
35 | - Scroll down and click the **Create repository** button at the bottom of the form.
36 | 3. After your new repository is created, wait about 20 seconds, then refresh the page. Follow the step-by-step instructions in the new repository's README.
37 |
38 |
47 |
--------------------------------------------------------------------------------
/.github/steps/2-add-a-job.md:
--------------------------------------------------------------------------------
1 | ## Step 2: Add a job to your workflow file
2 |
3 | _Nice work! :tada: You added a workflow file!_
4 |
5 | Here's what the entries in the `welcome.yml` file, on the `welcome-workflow` branch, mean:
6 |
7 | - `name: Post welcome comment` gives your workflow a name. This name will appear in the Actions tab of your repository.
8 | - `on: pull_request: types: [opened]` indicates that your workflow will execute whenever someone opens a pull request in your repository.
9 | - `permissions` assigns the workflow permissions to operate on the repository
10 | - `pull-requests: write` gives the workflow permission to write to pull requests. This is needed to create the welcome comment.
11 |
12 | Next, we need to specify jobs to run.
13 |
14 | **What is a _job_?**: A job is a set of steps in a workflow that execute on the same runner (a runner is a server that runs your workflows when triggered). Workflows have jobs, and jobs have steps. Steps are executed in order and are dependent on each other. You'll add steps to your workflow later in the course. To read more about jobs, see "[Jobs](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#jobs)".
15 |
16 | In the following activity, you'll add a "build" job to your workflow. You'll specify `ubuntu-latest` as the fastest, and cheapest, job runner available. If you want to read more about why we'll use that runner, see the code explanation for the line `runs-on: ubuntu-latest` in the "[Understanding the workflow file](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file)" article.
17 |
18 | ### :keyboard: Activity: Add a job to your workflow file
19 |
20 | 1. In a separate browser tab, make sure you are on the `welcome-workflow` branch and open your `.github/workflows/welcome.yml` file.
21 | 1. Edit the file and update its contents to:
22 |
23 | ```yaml copy
24 | name: Post welcome comment
25 | on:
26 | pull_request:
27 | types: [opened]
28 | permissions:
29 | pull-requests: write
30 | jobs:
31 | build:
32 | name: Post welcome comment
33 | runs-on: ubuntu-latest
34 | ```
35 |
36 | 1. Click **Commit changes** in the top right of the workflow editor.
37 | 1. Type a commit message and commit your changes directly to the `welcome-workflow` branch.
38 | 1. Wait about 20 seconds, then refresh this page (the one you're following instructions from). Another workflow will run and will replace the contents of this README file with instructions for the next step.
39 |
--------------------------------------------------------------------------------
/.github/workflows/2-add-a-job.yml:
--------------------------------------------------------------------------------
1 | name: Step 2, Add a job
2 |
3 | # This step triggers after every push to welcome-workflow.
4 | # This workflow updates from step 2 to step 3.
5 |
6 | # This will run every time we push to welcome-workflow.
7 | # Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
8 | on:
9 | workflow_dispatch:
10 | push:
11 | branches:
12 | - welcome-workflow
13 |
14 | # Reference: https://docs.github.com/en/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_add_job:
35 | name: On add job
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 2.
41 | # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
42 | # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
43 | if: >-
44 | ${{ !github.event.repository.is_template
45 | && needs.get_current_step.outputs.current_step == 2 }}
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 | # Verify the learner added the file contents.
58 | - name: Check workflow contents, jobs
59 | uses: skills/action-check-file@v1
60 | with:
61 | file: ".github/workflows/welcome.yml"
62 | search: "jobs:"
63 |
64 | # In README.md, switch step 2 for step 3.
65 | - name: Update to step 3
66 | uses: skills/action-update-step@v2
67 | with:
68 | token: ${{ secrets.GITHUB_TOKEN }}
69 | from_step: 2
70 | to_step: 3
71 | branch_name: welcome-workflow
72 |
--------------------------------------------------------------------------------
/.github/workflows/3-add-actions.yml:
--------------------------------------------------------------------------------
1 | name: Step 3, Add actions
2 |
3 | # This step triggers after every push to welcome-workflow.
4 | # This workflow updates from step 3 to step 4.
5 |
6 | # This will run every time we push to welcome-workflow.
7 | # Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
8 | on:
9 | workflow_dispatch:
10 | push:
11 | branches:
12 | - welcome-workflow
13 |
14 | # Reference: https://docs.github.com/en/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_add_actions:
35 | name: On add actions
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 3.
41 | # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
42 | # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
43 | if: >-
44 | ${{ !github.event.repository.is_template
45 | && needs.get_current_step.outputs.current_step == 3 }}
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 | # Verify the learner added the file contents.
58 | - name: Check workflow contents, steps
59 | uses: skills/action-check-file@v1
60 | with:
61 | file: ".github/workflows/welcome.yml"
62 | search: "steps:"
63 |
64 | # In README.md, switch step 3 for step 4.
65 | - name: Update to step 4
66 | uses: skills/action-update-step@v2
67 | with:
68 | token: ${{ secrets.GITHUB_TOKEN }}
69 | from_step: 3
70 | to_step: 4
71 | branch_name: welcome-workflow
72 |
--------------------------------------------------------------------------------
/.github/workflows/1-create-a-workflow.yml:
--------------------------------------------------------------------------------
1 | name: Step 1, Create a workflow
2 |
3 | # This step triggers after every push to welcome-workflow.
4 | # This workflow updates from step 1 to step 2.
5 |
6 | # This will run every time we push to welcome-workflow.
7 | # Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
8 | on:
9 | workflow_dispatch:
10 | push:
11 | branches:
12 | - welcome-workflow
13 |
14 | # Reference: https://docs.github.com/en/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_create_workflow:
35 | name: On create workflow
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 1.
41 | # Reference: https://docs.github.com/en/actions/learn-github-actions/contexts
42 | # Reference: https://docs.github.com/en/actions/learn-github-actions/expressions
43 | if: >-
44 | ${{ !github.event.repository.is_template
45 | && needs.get_current_step.outputs.current_step == 1 }}
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 | # Verify the learner added the file contents.
58 | - name: Check workflow contents, name
59 | uses: skills/action-check-file@v1
60 | with:
61 | file: ".github/workflows/welcome.yml"
62 | search: "name:"
63 |
64 | # In README.md, switch step 1 for step 2.
65 | - name: Update to step 2
66 | uses: skills/action-update-step@v2
67 | with:
68 | token: ${{ secrets.GITHUB_TOKEN }}
69 | from_step: 1
70 | to_step: 2
71 | branch_name: welcome-workflow
72 |
--------------------------------------------------------------------------------
/.github/steps/3-add-actions.md:
--------------------------------------------------------------------------------
1 | ## Step 3: Add a step to your workflow file
2 |
3 | _Nice work adding a job to your workflow! :dancer:_
4 |
5 | Workflows have jobs, and jobs have steps. So now we'll add a step to your workflow.
6 |
7 | **What are _steps_?**: Actions steps run - in the order they are specified, from the top down - when a workflow job is processed. Each step must pass for the next step to run.
8 |
9 | Each step consists of either a shell script that's executed, or a reference to an action that's run. When we talk about an action (with a lowercase "a") in this context, we mean a reusable unit of code. You can find out about actions in "[Finding and customizing actions](https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions)," but for now we'll use a shell script in our workflow step.
10 |
11 | Update your workflow to make it post a comment on new pull requests. It will do this using a [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) script and [GitHub CLI](https://cli.github.com/).
12 |
13 | ### :keyboard: Activity: Add a step to your workflow file
14 |
15 | 1. Still working on the `welcome-workflow` branch, open your `welcome.yml` file.
16 | 1. Update the contents of the file to:
17 |
18 | ```yaml copy
19 | name: Post welcome comment
20 | on:
21 | pull_request:
22 | types: [opened]
23 | permissions:
24 | pull-requests: write
25 | jobs:
26 | build:
27 | name: Post welcome comment
28 | runs-on: ubuntu-latest
29 | steps:
30 | - run: gh pr comment $PR_URL --body "Welcome to the repository!"
31 | env:
32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 | PR_URL: ${{ github.event.pull_request.html_url }}
34 | ```
35 |
36 | **Note:** The step you've added uses GitHub CLI (`gh`) to add a comment when a pull request is opened. To allow GitHub CLI to post a comment, we set the `GITHUB_TOKEN` environment variable to the value of the `GITHUB_TOKEN` secret, which is an installation access token, created when the workflow runs. For more information, see "[Automatic token authentication](https://docs.github.com/en/actions/security-guides/automatic-token-authentication)." We set the `PR_URL` environment variable to the URL of the newly created pull request, and we use this in the `gh` command.
37 |
38 | 1. Click **Commit changes** in the top right of the workflow editor.
39 | 1. Type your commit message and commit your changes directly to your branch.
40 | 1. Wait about 20 seconds, then refresh this page (the one you're following instructions from). Another workflow will run and will replace the contents of this README file with instructions for the next step.
41 |
--------------------------------------------------------------------------------
/.github/steps/1-create-a-workflow.md:
--------------------------------------------------------------------------------
1 | ## Step 1: Create a workflow file
2 |
3 | _Welcome to "Hello GitHub Actions"! :wave:_
4 |
5 | **What is _GitHub Actions_?**: GitHub Actions is a flexible way to automate nearly every aspect of your team's software workflow. You can automate testing, continuously deploy, review code, manage issues and pull requests, and much more. The best part, these workflows are stored as code in your repository and easily shared and reused across teams. To learn more, check out these resources:
6 |
7 | - The GitHub Actions feature page, see [GitHub Actions](https://github.com/features/actions).
8 | - The "GitHub Actions" user documentation, see [GitHub Actions](https://docs.github.com/actions).
9 |
10 | **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.
11 |
12 | - To read more about workflows, jobs, and events, see "[Understanding GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)".
13 | - 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)".
14 |
15 | To get you started, we ran an Actions workflow in your new repository that, among other things, created a branch for you to work in, called `welcome-workflow`.
16 |
17 | ### :keyboard: Activity: Create a workflow file
18 |
19 | 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.
20 | 1. Create a pull request. This will contain all of the changes you'll make throughout this part of the course.
21 |
22 | Click the **Pull Requests** tab, click **New pull request**, set `base: main` and `compare:welcome-workflow`, click **Create pull request**, then click **Create pull request** again.
23 |
24 | 1. Navigate to the **Code** tab.
25 | 1. From the **main** branch dropdown, click on the **welcome-workflow** branch.
26 | 1. Navigate to the `.github/workflows/` folder, then select **Add file** and click on **Create new file**.
27 | 1. In the **Name your file** field, enter `welcome.yml`.
28 | 1. Add the following content to the `welcome.yml` file:
29 |
30 | ```yaml copy
31 | name: Post welcome comment
32 | on:
33 | pull_request:
34 | types: [opened]
35 | permissions:
36 | pull-requests: write
37 | ```
38 |
39 | 1. To commit your changes, click **Commit changes**.
40 | 1. Type a commit message, select **Commit directly to the welcome-workflow branch** and click **Commit changes**.
41 | 1. Wait about 20 seconds, then refresh this page (the one you're following instructions from). A separate Actions workflow in the repository (not the workflow you created) will run and will automatically replace the contents of this README file with instructions for the next step.
42 |
--------------------------------------------------------------------------------
/.github/workflows/0-welcome.yml:
--------------------------------------------------------------------------------
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/en/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/en/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/en/actions/learn-github-actions/contexts
42 | # Reference: https://docs.github.com/en/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 | # Make a branch, file, and commit for the learner.
58 | - name: Prepare a branch, and file
59 | run: |
60 | echo "Make sure we are on step 0"
61 | if [ "$(cat .github/steps/-step.txt)" != 0 ]
62 | then
63 | echo "Current step is not 0"
64 | exit 0
65 | fi
66 |
67 | echo "Make a branch"
68 | BRANCH=welcome-workflow
69 | git checkout -b $BRANCH
70 |
71 | echo "Make a commit"
72 | git config user.name github-actions[bot]
73 | git config user.email github-actions[bot]@users.noreply.github.com
74 | git commit --allow-empty --message="Create an empty commit"
75 |
76 | echo "Push"
77 | git push --set-upstream origin $BRANCH
78 |
79 | echo "Restore main"
80 | git checkout main
81 | env:
82 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83 |
84 | # In README.md, switch step 0 for step 1.
85 | - name: Update to step 1
86 | uses: skills/action-update-step@v2
87 | with:
88 | token: ${{ secrets.GITHUB_TOKEN }}
89 | from_step: 0
90 | to_step: 1
91 | branch_name: welcome-workflow
92 |
--------------------------------------------------------------------------------