In this lab, you will use pull request comments to trigger deployments to your GitHub Pages environment. This lets you temporarily deploy a branch to GitHub Pages to preview changes before merging the pull request.
By the time you are working on this lab, you should have a fully-functional game deployed to GitHub pages. You should also have a workflow that deploys the game to a GitHub Pages environment when a pull request is merged.
However, how can you preview changes before they are merged? What if you need to
quickly roll a change back? This is where repository environments come into
play. By specifying the environment property in a workflow, you can trigger
deployments that are marked as successful/failed based on the result of the
workflow run. Combining this with the ability to trigger workflows using pull
request comments, you can create a workflow that deploys a branch to an
environment when a comment is made on a pull request (often referred to as
IssueOps).
-
Ensure you are on the
mainbranchgit checkout main
-
Create a new feature branch
git checkout -b feature/high-score
-
Open the
src/local_storage_manager.tsfile -
Locate the comment
// Lab 11: Update Best Score -
Add the following code below the comment
LocalStorageManager.storage.setItem('bestScore', score.toString())
-
Save the file
-
Commit the changes
git add . git commit -m 'Save best score to local storage'
-
Push the changes to GitHub
git push
- In your browser, navigate to your repository on GitHub
- Click on the Pull requests tab
- Click the New pull request button
- Click the Compare button, then select your
feature/high-scorebranch - Click Create pull request
- Enter a title and description for your PR
- Click Create pull request
-
In the pull request, navigate to the Add a comment section
-
In the comment text field, enter
.deployIn a few seconds, you should see a comment is automatically to the pull request stating a deployment is in progress. You should also see that a deployment has been initiated.
-
Wait for the deployment to complete
Another comment will be added to the pull request with a link to the deployment.
-
Click the link to view the deployed game
As you play the game, your high score should now be saved in the BEST box.
In this scenario, we only have one environment, so we can only have one active version of the game at a time. For now, lets roll back the changes until the PR is merged.
-
In the pull request, navigate to the Add a comment section
-
In the comment text field, enter
.deploy mainIn a few seconds, you should see a comment is automatically to the pull request stating a deployment is in progress. You should also see that a deployment has been initiated.
-
Wait for the deployment to complete
Another comment will be added to the pull request with a link to the rollback deployment.
-
Click the link to view the deployed game
As you play the game, your high score should no longer be saved.
Feel free to follow the below steps to request and review each other's PRs.
-
Copy the URL of your PR and paste it into the meeting chat
-
Click on another PR link in the meeting chat
-
Click on the Files changed tab
-
Click the Review changes button
-
Enter a comment
-
Ensure Approve is selected as the review type
-
Click Submit review
Once your PR has been approved, you can merge it into main.
- Click the Merge pull request button
- Click Confirm merge
- Click Delete branch
After 1-2 minutes, the changes will be deployed automatically to GitHub Pages!
If you're having trouble with any of the steps, you can ask for help in the meeting chat.





