diff --git a/.github/steps/-step.txt b/.github/steps/-step.txt index 573541a..00750ed 100644 --- a/.github/steps/-step.txt +++ b/.github/steps/-step.txt @@ -1 +1 @@ -0 +3 diff --git a/.github/workflows/welcome.yml b/.github/workflows/welcome.yml new file mode 100644 index 0000000..dfaa776 --- /dev/null +++ b/.github/workflows/welcome.yml @@ -0,0 +1,10 @@ +name: Post welcome comment +on: + pull_request: + types: [opened] +permissions: + pull-requests: write +jobs: + build: + name: Post welcome comment + runs-on: ubuntu-latest diff --git a/README.md b/README.md index f121210..64c6737 100644 --- a/README.md +++ b/README.md @@ -6,34 +6,46 @@ _Create and run a GitHub Actions workflow._ -## Welcome - -Automation is key for streamlining your work processes, and [GitHub Actions](https://docs.github.com/actions) is the best way to supercharge your workflow. - -- **Who is this for**: Developers, DevOps engineers, students, managers, teams, GitHub users. -- **What you'll learn**: How to create workflow files, trigger workflows, and find workflow logs. -- **What you'll build**: An Actions workflow that will check emoji shortcode references in Markdown files. -- **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. -- **How long**: This course can be finished in less than two hours. - -In this course, you will: - -1. Create a workflow -2. Add a job -3. Add a run step -4. Merge your pull request -5. See effect of the workflow - -### How to start this course - -[![start-course](https://user-images.githubusercontent.com/1221423/235727646-4a590299-ffe5-480d-8cd5-8194ea184546.svg)](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) - -1. Right-click **Start course** and open the link in a new tab. -2. In the new tab, most of the prompts will automatically fill in for you. - - For owner, choose your personal account or an organization to host the repository. - - 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). - - Scroll down and click the **Create repository** button at the bottom of the form. -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. +## Step 3: Add a step to your workflow file + +_Nice work adding a job to your workflow! :dancer:_ + +Workflows have jobs, and jobs have steps. So now we'll add a step to your workflow. + +**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. + +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. + +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/). + +### :keyboard: Activity: Add a step to your workflow file + +1. Still working on the `welcome-workflow` branch, open your `welcome.yml` file. +1. Update the contents of the file to: + + ```yaml copy + name: Post welcome comment + on: + pull_request: + types: [opened] + permissions: + pull-requests: write + jobs: + build: + name: Post welcome comment + runs-on: ubuntu-latest + steps: + - 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 }} + ``` + + **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. + +1. Click **Commit changes** in the top right of the workflow editor. +1. Type your commit message and commit your changes directly to your branch. +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.