Skip to content

Commit

Permalink
Ask learner to create PR manually and add permissions (#36)
Browse files Browse the repository at this point in the history
* Don't auto create a PR in step 0

* Update README to manually create PR

* Move manual PR creation to step 1

If the PR is created _after_ the workflow is created, then the `welcome` workflow will run and comment on this PR which might add some confusion and renders the test PR in step 5 redundant.

* Add `permissions` to workflow code snippet

In order to leave a comment on a PR, the workflow needs the `pull-requests: write` permission.

* Update README.md

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>

---------

Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
  • Loading branch information
chadfawcett and heiskr committed Feb 15, 2023
1 parent 65df8f3 commit 8979909
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/0-start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ on:
permissions:
# Need `contents: read` to checkout the repository
# Need `contents: write` to update the step metadata
# Need `pull-requests: write` to create a pull request
contents: write
pull-requests: write

jobs:
# Get the current step from .github/script/STEP so we can
Expand Down Expand Up @@ -58,8 +56,8 @@ jobs:
with:
fetch-depth: 0 # Let's get all the branches

# Make a branch, file, commit, and pull request for the learner
- name: Prepare a pull request, branch, and file
# Make a branch, file, and commit for the learner
- name: Prepare a branch, and file
run: |
echo "Make sure we are on step 0"
if [ "$(cat .github/script/STEP)" != 0 ]
Expand All @@ -79,11 +77,7 @@ jobs:
echo "Push"
git push --set-upstream origin $BRANCH
echo "Make a pull request"
# Reference https://cli.github.com/manual/gh_pr_create
gh pr create --title "Post welcome comment workflow" --body "Post welcome comment workflow"
echo "Restore main"
git checkout main
env:
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ To get you started, we used actions to go ahead and made a branch and pull reque
### :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. Create a pull request to view all the changes you'll make throughout this course. Click the **Pull Requests** tab, click **New pull request**, set `base: main` and `compare:welcome-workflow`.
1. Navigate to the **Code** tab.
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**.
Expand All @@ -79,6 +80,8 @@ To get you started, we used actions to go ahead and made a branch and pull reque
on:
pull_request:
types: [opened]
permissions:
pull-requests: write
```
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.
Expand All @@ -101,6 +104,8 @@ Here's what it means:
- `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.
- `permissions` assigns the workflow permissions to operate on the repository
- `pull-requests: write` gives the workflow permission to write to pull requests. This is needed to create the welcome comment.

Next, we need to specify jobs to run.

Expand All @@ -117,6 +122,8 @@ In this step of our exercise, we will add a "build" job. We will specify `ubuntu
on:
pull_request:
types: [opened]
permissions:
pull-requests: write
jobs:
build:
name: Post welcome comment
Expand Down Expand Up @@ -154,6 +161,8 @@ In our action, we post a comment on the pull request using a [bash](https://en.w
on:
pull_request:
types: [opened]
permissions:
pull-requests: write
jobs:
build:
name: Post welcome comment
Expand Down Expand Up @@ -181,15 +190,15 @@ In our action, we post a comment on the pull request using a [bash](https://en.w

_You're now able to write and run an Actions workflow! :sparkles:_

Merge your pull request so the action will be a part of the `main` branch.
Merge your changes 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 **Post welcome comment workflow** pull request.
3. Click **Merge pull request**, then click **Confirm merge**.
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.
1. Click on the pull request you created in step 1.
1. Click **Merge pull request**, then click **Confirm merge**.
1. Optionally, click **Delete branch** to delete your `welcome-workflow` branch.
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 Down

0 comments on commit 8979909

Please sign in to comment.