Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Previewing PR using Surge.sh #1487

Merged
merged 17 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/images/surgeAddToken.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/surgeCreateAccount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/surgeGithubActionsBot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/surgeToken.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 153 additions & 1 deletion docs/userGuide/deployingTheSite.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,162 @@ Here are the steps to set up Netlify:

Now your site will be deployed on Netlify at the given address specified after deployment. It will be updated automatically when the default branch of your repo is updated.

Additionally, **when contributors make a pull request to your GitHub repo, you can _preview_ the updated site** at the bottom of the pull request by clicking on `details` link in the PR:
## Previewing Pull Requests for MarkBind sites

There may be more than one user making changes to your MarkBind site. In such cases, it might be prudent to have a workflow that is centered around pull requests (PRs) such as a [feature branch workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow) or a [forking workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's preface a little bit more who this section is for (users having MarkBind projects on github)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I have added an info box below ## Previewing Pull Requests for MarkBind sites


You can setup PR previews in order to automatically build and deploy the modified Markbind site based on the changes in the PR, which would lead to greater convenience and time-savings for the PR reviewers.

### Previewing PRs using Netlify

By following the [steps to deploy to Netlify](#deploying-to-netlify) in the previous section, you would automatically be able to preview PRs.

You can _preview_ the updated site at the bottom of the pull request by clicking on `details` link in the PR:

<include src="screenshot.md" boilerplate var-alt="Preview deploy" var-file="netlifyPreview4.png" inline />

For more information on previewing PRs with Netlify, you may refer to [Netlify's docs](https://www.netlify.com/tags/deploy-previews/).

### Previewing PRs using Surge

You may also preview PRs using [Surge](https://surge.sh/), which is an NPM package that does static web publishing. Here are the steps to do so:

1. First install Surge using by typing `npm install --global surge` on your terminal.
1. Next, type `surge` in the terminal. You should see the following prompt:

<include src="screenshot.md" boilerplate var-alt="Create Surge account" var-file="surgeCreateAccount.png" inline />

1. Proceed to create a Surge account.
Copy link
Contributor

@jonahtanjz jonahtanjz Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps can also include instruction to inform the user to press 'Enter' to proceed to use the default values of project and domain when setting up the account? New users may be confused by this step.

image

Copy link
Contributor Author

@raysonkoh raysonkoh Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this part is not needed - the user can just CTRL-C out of this process (after logging in / creating an account). I have added a clarification in the userGuide on this. Could you help to check to see if it is clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this part is not needed - the user can just CTRL-C out of this process (after logging in / creating an account).

Ahh I see. Yup it's much clearer now 👍 Thanks for updating :)

1. Next, type `surge token` to generate your surge token.

<include src="screenshot.md" boilerplate var-alt="Get Surge token" var-file="surgeToken.png" inline />

1. In the repo of your markbind site, create a new secret by going to "Settings"->"Secrets" and naming it as `SURGE_TOKEN` and setting its value to the value of the generated surge token.

<include src="screenshot.md" boilerplate var-alt="Add Surge token" var-file="surgeAddToken.png" inline />

1. Commit and push the following 2 files into your markbind site repo, in the directory `./github/workflows/`.
raysonkoh marked this conversation as resolved.
Show resolved Hide resolved

<panel header="`receivePR.yml` File" type="seamless">

{% raw %}
```yml
name: Receive Markbind PR

# read-only
# no access to secrets
on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 10
- name: Build Markbind website
if: ${{ success() && github.event_name == 'pull_request' }}
raysonkoh marked this conversation as resolved.
Show resolved Hide resolved
run: |
npm install -g markbind-cli
markbind build
- name: Save PR number and HEAD commit
if: ${{ success() && github.event_name == 'pull_request' }}
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NUMBER
echo ${{ github.event.pull_request.head.sha }} > ./pr/SHA
- name: Upload artifacts
if: ${{ success() && github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v2
with:
name: markbind-deployment
path: |
./_site
./pr
```
{% endraw %}

</panel>

<panel header="`previewPR.yml` File" type="seamless">

{% raw %}

```yml
name: Deploy PR Preview

# Runs after PR is received and build by markbind-cli
# Has access to repo secrets
on:
workflow_run:
workflows: ["Receive Markbind PR"]
types:
- completed

jobs:
build:
runs-on: ubuntu-latest
name: Deploying to surge
steps:
- uses: actions/checkout@v2
- name: Download artifact
raysonkoh marked this conversation as resolved.
Show resolved Hide resolved
uses: dawidd6/action-download-artifact@v2
with:
workflow: receivePR.yml
run_id: ${{ github.event.workflow_run.id }}
name: markbind-deployment
path: .
- name: Display structure of downloaded files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this step? since devs can include it as needed if preferred

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup make sense, will remove it

run: ls -R
- name: Extract PR number
id: pr-number
run: echo '::set-output name=ACTIONS_PR_NUMBER::'$(cat ./pr/NUMBER)
- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 10
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: Build PR preview url
id: pr-url
run: echo '::set-output name=ACTIONS_PREVIEW_URL::'https://pr-${{ steps.pr-number.outputs.ACTIONS_PR_NUMBER }}-${{ env.GITHUB_REPOSITORY_SLUG_URL }}.surge.sh/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove rlespinasse/github-slug-action@v3.x and simplify the surge url?

also a small comment / note to change this as appropriate, since the url is project-dependent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think that if we remove rlespinasse/github-slug-action@v3.x, it will add some more complexity since there needs to be some regex script to extract the repoSlug. I am not sure if there is a way to simplify the surge url while ensuring that it is still as general as possible.

I can add a note to say that the user can make modifications to the surge URL as needed to a simpler one, together with a short code snippet showing the relevant changes. What do you think @ang-zeyu ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too familiar with surge's specifics - is ${{ env.GITHUB_REPOSITORY_SLUG_URL }} necessary / convention for pr previewing in surge?

my view is that this could be easily configured to something unique if the user wants to (not limited to owner + repo format).
i.e. just https://pr-${{ steps.pr-number.outputs.ACTIONS_PR_NUMBER }}-xxxx-anything-xxxx.surge.sh.
Would that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way is that the user can have a SURGE_URL secret, so the PR URL would be something like https://pr-${{ steps.pr-number.outputs.ACTIONS_PR_NUMBER }}-${{ secrets.SURGE_URL }}.surge.sh.

This would eliminate the need for rlespinasse/github-slug-action@v3.x in the code. However, this would be slightly more inconvenient for the user.

What do you think about this approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm was thinking of just highlighting that the specific line in the .yml should be edited per the project as needed before committing. (comment / warning box / highlight)
Since folks who are using pull requests, github actions, github likely have the know how =P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I have added in the userGuide a new variable PR_URL which the user can modify. I have also added a note to highlight to the user that they have to edit the PR_URL according to their needs.

- name: Install surge and deploy PR to surge
run: |
npm i -g surge
surge --project ./_site --domain ${{ steps.pr-url.outputs.ACTIONS_PREVIEW_URL }}
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
- name: Find PR preview link comment
raysonkoh marked this conversation as resolved.
Show resolved Hide resolved
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ steps.pr-number.outputs.ACTIONS_PR_NUMBER }}
body-includes: Your PR can be previewed
- name: Comment PR preview link in PR
if: ${{ steps.fc.outputs.comment-id == 0 }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.pr-number.outputs.ACTIONS_PR_NUMBER }}
body: |
Thank you for submitting the Pull Request! :thumbsup:

Your PR can be previewed [here](${{ steps.pr-url.outputs.ACTIONS_PREVIEW_URL }})
```

{% endraw %}

</panel>

Finally, you may open a PR to the repo of your Markbind site. If everything is configured correctly, after a few minutes, you should be able to see a `github-actions bot` automatically commenting on the PR with a link to _preview_ the updated Markbind site. The link is configured as such: `https://pr-[PR_NUMBER]-[REPO_OWNER_NAME]-[REPO_NAME].surge.sh`.

<include src="screenshot.md" boilerplate var-alt="Surge PR bot" var-file="surgeGithubActionsBot.png" inline />

For more information on Surge, you may refer to [Surge's docs](https://surge.sh/help/).


## Relevant Tips & Tricks

<panel header="Configuring Online Deployment platforms to use specific MarkBind version" type="seamless" expand-headerless>
Expand Down