From a7474ff4cba0e1356bfdf1dad48850928ac1557d Mon Sep 17 00:00:00 2001 From: tlylt Date: Sun, 27 Mar 2022 13:09:48 +0800 Subject: [PATCH 01/13] Update action --- Dockerfile | 18 ---- README.md | 247 ++++++++++++++++++++++++++++++++++++++++++++++---- action.yml | 129 +++++++++++++++++++++++++- entrypoint.sh | 22 ----- 4 files changed, 357 insertions(+), 59 deletions(-) delete mode 100644 Dockerfile delete mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 65261f7..0000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM node:10 - -# Set default locale for the environment -ENV LC_ALL C.UTF-8 -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US.UTF-8 - -LABEL "com.github.actions.name"="Build & Deploy to GitHub Pages" -LABEL "com.github.actions.description"="Builds & deploys Jekyll to gh-pages branch of the same repository. " -LABEL "com.github.actions.icon"="globe" -LABEL "com.github.actions.color"="green" - -LABEL "repository"="https://github.com/le0tan/markbind-deploy-gh-pages" - -ADD entrypoint.sh /entrypoint.sh -RUN chmod +x entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 350d0d2..3b98ee0 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,191 @@ # markbind-action - A GitHub Action that builds and deploys your MarkBind site. -## How to use this action? +## Option Summary + +Option | Required | Default | Remarks +:-------------|:--------:|-----------------------------:|------------------------------------------------------------------------------ +token | yes | | The token to be used for the service +service | no | 'gh-pages' | The publishing service to deploy the site +purpose | no | 'deployment' | The deployment purpose +domain | no | '' | The domain that the site is available at. Required if service chosen is surge +version | no | 'latest' | The MarkBind version to use to build the site +keepFiles | no | false | Whether to keep the files in the published branch before pushing +rootDirectory | no | '.' | The directory to read source files from +baseUrl | no | Value specified in site.json | The base URL relative to your domain +siteConfig | no | 'site.json' | The site config file to use + +## Option Details + +### token +Currently two types of tokens are supported (correspond to the two supported publishing services): +- Token for GitHub Pages + - Simply use `${{ secrets.GITHUB_TOKEN }}` + - Note that you need to ensure that your have selected the branch that you want to deploy to in your GitHub repo's Pages settings +- Token for Surge.sh + - Example: `${{ secrets.SURGE_TOKEN }}` + - `SURGE_TOKEN` is the environment secret name + - Require registration with an email address + - After retrieving the token, put the token as a repository secret in your + - See [here](https://markbind.org/userGuide/deployingTheSite.html#previewing-prs-using-surge) for a detailed guide on how to retrieve the token + +### service +Currently two types of publishing services are supported: +- GitHub Pages + - 'gh-pages' + - See [here](https://markbind.org/userGuide/deployingTheSite.html#publishing-to-github-pages) for more details +- Surge.sh + - 'surge' + - See [here](https://surge.sh/) for more details + +### purpose +The purpose of the deployment. This can be either standard deployment or for PR previewing. +- Standard deployment + - 'deployment' + - This is the default value +- PR preview + - 'pr-preview' + - This is used when you want to build and preview a site when there is a PR made to the repository. Note that this does not work for PR from a fork(due to security reasons) + +### domain +The domain that the site is available at. Required if service chosen is surge. Surge.sh allows you to specify a subdomain as long as it is not taken up by others. + +- 'xxx.surge.sh' + - A typical domain that you can specify. You have to ensure that 'xxx' is unique. Read [here](https://surge.sh/help/adding-a-custom-domain) on how to configure a custom domain with Surge.sh +- 'pr-x-domain' + - Note that for PR Preview purposes, the domain will be prefixed with 'pr-x', which 'x' is the GitHub event number + - You will need to specify what 'domain' is + +### version +The MarkBind version to use to build the site. +- 'latest' + - This is the latest published version of MarkBind +- 'master' + - This is the latest, possibly unpublished version of MarkBind +- 'X.Y.Z' + - This is the version of MarkBind with the specified version number + - A sample version number is '3.1.1' + +### keepFiles +Whether to keep the files in the published branch before pushing. This is a boolean parameter. +- false + - This is the default value +- true + - This will make the published branch keep the existing files before an update is made. + +### rootDirectory (MarkBind CLI arguments) +The directory to read source files from. +- '.' + - This is the default value + - This is for the case that your source files of the MarkBind site are in the root directory of the repository +- './path/to/directory' + - This is for the case that your source files of the MarkBind site are in a subdirectory of the repository + - A sample path is './docs' + +### baseUrl (MarkBind CLI arguments) +The base URL relative to your domain. +- '/reponame' + - Defaults to the value of `baseUrl` in your `site.json` file + - This is important for deploying your site to GitHub Pages + - Note that you will need to specify this or in the site config file (typically the `site.json`), in order to configure the relative URL correctly. + +### siteConfig (MarkBind CLI arguments) +The site config file to use. +- 'site.json' + - This is the default value + +# Usage +In essence, there are two parts to a GitHub Action workflow: +- The trigger event +- The jobs/steps to be run after the trigger event occurs + +For our context, there two typical trigger events. This is written at the start of the workflow files: +(Assuming 'master' is the target branch) +1. Trigger the action whenever there is a push to the repository +```yaml +on: + push: + branches: + - master +``` + +2. Trigger the action whenever there is a pull request to the repository +```yaml +on: + pull_request: + branches: + - master +``` + +Then, specify a step to use this action: + +E.g. +```yaml +name: MarkBind Action -Make sure that your MarkBind project is on the master branch. +on: + push: + branches: + - master + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - name: Build & Deploy to GitHub Pages + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + baseUrl: '/mb-test' + version: '3.1.1' +``` +The above script builds the site from the repository's root directory, with baseUrl of '/mb-test' ('mb-test' is the repository name), with MarkBind version 3.1.1. -1. On the top of your repo, click **Actions** -2. Click **New workflow** -3. Click **Set up workflow yourself** on the top right corner -4. Configure your `main.yml` as follows (note that you need to specify the **BASE_URL** of your GitHub pages) +Then, it will deploy the site to GitHub Pages. It runs everytime there is a push to the repository. +# Scenarios +## Deploy to Github Pages on push to main ```yaml -name: MarkBind Deploy +name: MarkBind Action + +on: + push: + branches: + - main + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - name: Build & Deploy to GitHub Pages + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: '3.1.1' +``` + +## Deploy to Surge.sh +```yaml +name: MarkBind Action + +on: [push] + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - name: Build & Deploy to GitHub Pages + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.SURGE_TOKEN }} + service: 'surge' + domain: 'mb-test.surge.sh' +``` +Note that if you are using custom domain, you will need to ensure that it is configured with Surge.sh. + +## Build with the development branch of MarkBind +```yaml +name: MarkBind Action on: [push] @@ -20,15 +193,57 @@ jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - name: Build & Deploy to GitHub Pages - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }} - GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} - BASE_URL: # base URL to your gh-page - uses: MarkBind/markbind-action@1.0.0 + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: 'master' +``` +'master' is specified so that the site is built with the latest (possibly unpublished) version of MarkBind. + +## Build with files that is not at the root level of the repository +```yaml +name: MarkBind Action +on: [push] + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - name: Build & Deploy to GitHub Pages + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + rootDirectory: './docs' +``` + +## PR Preview for PRs made following a branching workflow +```yaml +name: MarkBind Action + +on: + pull_request: + branches: + - master + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - name: Build & Deploy to GitHub Pages + uses: tlylt/markbind-deploy@main + with: + token: ${{ secrets.SURGE_TOKEN }} + service: 'surge' + purpose: 'pr-preview' + domain: 'mb-test.surge.sh' ``` -This action will be triggered on push, and built files will be in `gh-pages` branch of the same repo. +## Underlying Actions +Besides some processing bash scripts, this action is composed of the following actions: +- [actions/checkout](https://github.com/actions/checkout) +- [actions/setup-node](https://github.com/actions/setup-node) +- [peter-evans/find-comment](https://github.com/peter-evans/find-comment) +- [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) +- [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) \ No newline at end of file diff --git a/action.yml b/action.yml index 9e168dd..155f3ec 100644 --- a/action.yml +++ b/action.yml @@ -1,8 +1,131 @@ name: markbind-action -description: 'A GitHub Action that builds and deploys your MarkBind site.' +description: 'Deploy your MarkBind site' branding: icon: 'upload-cloud' color: 'blue' + +inputs: + token: + description: the required token + required: true + service: + description: the publishing service + default: 'gh-pages' + type: string + purpose: + description: the deployment purpose, could be standard deployment or for PR preview + default: 'deployment' + type: string + domain: + description: the domain to use + type: string + version: + description: the MarkBind version to use. e.g. 3.1.1 + default: 'latest' + type: string + rootDirectory: + description: the directory to read source files from + default: '.' + type: string + baseUrl: + description: the base URL relative to your domain + default: 'unsetFlag' # a flag indicating that baseUrl defaults to the one specified in site.json config file + type: string + siteConfig: + description: the site config file to use + default: 'site.json' + type: string + keepFiles: + description: whether the existing files will be removed in the published branch, before pushing. + default: false + type: boolean + runs: - using: 'docker' - image: 'Dockerfile' \ No newline at end of file + using: "composite" + steps: + - name: Checkout source repo + uses: actions/checkout@v3 + with: + path: curr-repo + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: 12 + - name: Checkout markbind-cli@master + if: inputs.version == 'master' + uses: actions/checkout@v3 + with: + repository: MarkBind/markbind + path: markbind-cli + - name: Install markbind-cli@master + if: inputs.version == 'master' + run: | + npm i -g npm@8.3.1 + cd markbind-cli + npm run setup && npm run build:web + cd packages/cli + npm link + cd ../../.. + shell: bash + - name: Install a released version of markbind-cli + if: inputs.version != 'master' + run: | + npm install -g markbind-cli@${{ inputs.version }} + shell: bash + - name: Build site + run: | + BASEURL="--baseUrl ${{ inputs.baseurl }}" + if [[ ${{ inputs.baseurl }} == "unsetFlag" ]]; then + BASEURL="" + echo "Default baseUrl to the config file attribute" + fi + cd curr-repo + markbind build ${{ inputs.rootDirectory }} ./_site \ + $BASEURL --site-config ${{ inputs.siteConfig }} + cd .. + echo "Site Built!" + shell: bash + - name: Deploy via gh-pages + if: inputs.service == 'gh-pages' + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ inputs.token }} + publish_dir: ./curr-repo/_site + user_name: github-actions[bot] + user_email: 41898282+github-actions[bot]@users.noreply.github.com + keep_files: ${{ inputs.keepFiles }} + - name: Deploy via Surge.sh for normal deployment + if: inputs.service == 'surge' && inputs.purpose == 'deployment' + run: | + npm i -g surge + surge --project ./curr-repo/_site --domain ${{ inputs.domain }} + shell: bash + env: + SURGE_TOKEN: ${{ inputs.token }} + - name: Deploy via Surge.sh for PR Preview + if: inputs.service == 'surge' && inputs.purpose == 'pr-preview' && github.event_name == 'pull_request' + run: | + echo "prNum=${{ github.event.number }}" >> $GITHUB_ENV + npm i -g surge + PR_PREVIEW_URL="https://pr-${{ github.event.number }}-${{ inputs.domain }}" + echo "previewUrl=$PR_PREVIEW_URL" >> $GITHUB_ENV + surge --project ./curr-repo/_site --domain $PR_PREVIEW_URL + shell: bash + env: + SURGE_TOKEN: ${{ inputs.token }} + - name: Find existing PR preview link comment + if: inputs.service == 'surge' && inputs.purpose == 'pr-preview' && github.event_name == 'pull_request' + uses: peter-evans/find-comment@v1 + id: fc + with: + issue-number: ${{ env.prNum }} + body-includes: Your PR can be previewed + - name: Comment PR preview link in PR + if: inputs.service == 'surge' && inputs.purpose == 'pr-preview' && github.event_name == 'pull_request' && steps.fc.outputs.comment-id == 0 + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ env.prNum }} + body: | + Thank you for submitting the Pull Request! :thumbsup: + + Your PR can be previewed [here](${{ env.previewUrl }}) \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index eddf8ae..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -set -e - -echo '👍 MAIN ENTRYPOINT HAS STARTED—' -npm install -g markbind-cli -echo '👍 BUILDING THE SITE' -markbind build --baseUrl ${BASE_URL} -echo '👍 THE SITE IS BUILT—PUSHING IT BACK TO GITHUB-PAGES' -cd _site -remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \ -remote_branch="gh-pages" && \ -git init && \ -git config user.name "${GITHUB_ACTOR}" && \ -git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \ -git add . && \ -echo -n 'Files to Commit:' && ls -l | wc -l && \ -git commit -m'action build' > /dev/null 2>&1 && \ -git push --force $remote_repo master:$remote_branch > /dev/null 2>&1 && \ -rm -fr .git && \ -cd ../ -echo '👍 GREAT SUCCESS!' From 9b52f58d90e25bc5495e1836fb3bf622d5598299 Mon Sep 17 00:00:00 2001 From: tlylt Date: Sun, 27 Mar 2022 13:14:14 +0800 Subject: [PATCH 02/13] Update docs --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b98ee0..63524ad 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} baseUrl: '/mb-test' @@ -158,7 +158,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} version: '3.1.1' @@ -175,7 +175,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.SURGE_TOKEN }} service: 'surge' @@ -194,7 +194,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} version: 'master' @@ -212,7 +212,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} rootDirectory: './docs' @@ -232,7 +232,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy to GitHub Pages - uses: tlylt/markbind-deploy@main + uses: MarkBind/markbind-action@master with: token: ${{ secrets.SURGE_TOKEN }} service: 'surge' From f24d43a15f1daf50e54fb4eb3ffa04b67815385e Mon Sep 17 00:00:00 2001 From: Liu YongLiang <41845017+tlylt@users.noreply.github.com> Date: Sun, 27 Mar 2022 18:53:24 +0800 Subject: [PATCH 03/13] Apply suggestions from code review Co-authored-by: Ang Ze Yu --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 63524ad..d92a43d 100644 --- a/README.md +++ b/README.md @@ -52,16 +52,15 @@ The domain that the site is available at. Required if service chosen is surge. S - 'xxx.surge.sh' - A typical domain that you can specify. You have to ensure that 'xxx' is unique. Read [here](https://surge.sh/help/adding-a-custom-domain) on how to configure a custom domain with Surge.sh -- 'pr-x-domain' - - Note that for PR Preview purposes, the domain will be prefixed with 'pr-x', which 'x' is the GitHub event number - - You will need to specify what 'domain' is +- 'pr-x-' + - Note that for PR Preview purposes, the domain you specify will be prefixed with 'pr-x-', where 'x' is the GitHub event number ### version The MarkBind version to use to build the site. - 'latest' - This is the latest published version of MarkBind - 'master' - - This is the latest, possibly unpublished version of MarkBind + - This is the latest, possibly unpublished version of MarkBind in development - 'X.Y.Z' - This is the version of MarkBind with the specified version number - A sample version number is '3.1.1' @@ -71,7 +70,7 @@ Whether to keep the files in the published branch before pushing. This is a bool - false - This is the default value - true - - This will make the published branch keep the existing files before an update is made. + - This will preserve any existing files in the published branch before an update is made. ### rootDirectory (MarkBind CLI arguments) The directory to read source files from. @@ -240,8 +239,8 @@ jobs: domain: 'mb-test.surge.sh' ``` -## Underlying Actions -Besides some processing bash scripts, this action is composed of the following actions: +## Behind the Scenes +Besides processing a few bash scripts, this action utilises the following actions: - [actions/checkout](https://github.com/actions/checkout) - [actions/setup-node](https://github.com/actions/setup-node) - [peter-evans/find-comment](https://github.com/peter-evans/find-comment) From 52bea00d7f28c16373814380d27a1d163cad54c8 Mon Sep 17 00:00:00 2001 From: tlylt Date: Sun, 27 Mar 2022 20:26:53 +0800 Subject: [PATCH 04/13] Update action & docs --- README.md | 122 ++++++++++++++++++++++++++++++++--------------------- action.yml | 6 +-- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index d92a43d..57df923 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,16 @@ A GitHub Action that builds and deploys your MarkBind site. ## Option Summary Option | Required | Default | Remarks -:-------------|:--------:|-----------------------------:|------------------------------------------------------------------------------ +:-------------|:--------:|-----------------------------:|----------------------------------------------------------------------------------------------------------- token | yes | | The token to be used for the service -service | no | 'gh-pages' | The publishing service to deploy the site -purpose | no | 'deployment' | The deployment purpose -domain | no | '' | The domain that the site is available at. Required if service chosen is surge -version | no | 'latest' | The MarkBind version to use to build the site -keepFiles | no | false | Whether to keep the files in the published branch before pushing -rootDirectory | no | '.' | The directory to read source files from +service | no | `'gh-pages'` | The publishing service to deploy the site +purpose | no | `'deployment'` | The deployment purpose +domain | no | `''` | The domain that the site is available at. Required if service chosen is surge or the purpose is PR preview +version | no | `'latest'` | The MarkBind version to use to build the site +keepFiles | no | `false` | Whether to keep the files in the published branch before pushing +rootDirectory | no | `'.'` | The directory to read source files from baseUrl | no | Value specified in site.json | The base URL relative to your domain -siteConfig | no | 'site.json' | The site config file to use +siteConfig | no | `'site.json'` | The site config file to use ## Option Details @@ -21,7 +21,8 @@ siteConfig | no | 'site.json' | The site config file t Currently two types of tokens are supported (correspond to the two supported publishing services): - Token for GitHub Pages - Simply use `${{ secrets.GITHUB_TOKEN }}` - - Note that you need to ensure that your have selected the branch that you want to deploy to in your GitHub repo's Pages settings + - Note that you need to ensure that your have selected the branch that you want to deploy to in your [GitHub repo's Pages settings](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source) + - Deployment to GitHub Pages might take 5-10 minutes before the site is available/refreshed - Token for Surge.sh - Example: `${{ secrets.SURGE_TOKEN }}` - `SURGE_TOKEN` is the environment secret name @@ -32,65 +33,83 @@ Currently two types of tokens are supported (correspond to the two supported pub ### service Currently two types of publishing services are supported: - GitHub Pages - - 'gh-pages' + - `'gh-pages'` - See [here](https://markbind.org/userGuide/deployingTheSite.html#publishing-to-github-pages) for more details - Surge.sh - - 'surge' + - `'surge'` - See [here](https://surge.sh/) for more details ### purpose The purpose of the deployment. This can be either standard deployment or for PR previewing. - Standard deployment - - 'deployment' + - `'deployment'` - This is the default value - PR preview - - 'pr-preview' - - This is used when you want to build and preview a site when there is a PR made to the repository. Note that this does not work for PR from a fork(due to security reasons) + - `'pr-preview'` + - This is used if you want to build and preview the updated site whenever there is a PR made to the repository. Note that this does not work for PR from a fork (due to security reasons) ### domain -The domain that the site is available at. Required if service chosen is surge. Surge.sh allows you to specify a subdomain as long as it is not taken up by others. - -- 'xxx.surge.sh' - - A typical domain that you can specify. You have to ensure that 'xxx' is unique. Read [here](https://surge.sh/help/adding-a-custom-domain) on how to configure a custom domain with Surge.sh -- 'pr-x-' - - Note that for PR Preview purposes, the domain you specify will be prefixed with 'pr-x-', where 'x' is the GitHub event number +The domain that the site is available at. Required if service chosen is Surge(also if the purpose is PR preview). +- A surge.sh subdomain + - `'.surge.sh'` + - Surge allows you to specify a subdomain for free as long as it has not been taken up by others. You have to ensure that the subDomain is unique. + - A possible subdomain to use is your repository name: `markbind-action.surge.sh` +- A custom domain that you have configured with Surge + - Read the [Surge documentation](https://surge.sh/help/adding-a-custom-domain) to understand how to set it up. +- Additional notes + - for PR preview purposes, the domain you specify will automatically be prefixed with 'pr-x-', where 'x' is the GitHub event number + - E.g. `'pr-x-'` + - Custom domain does not work with PR preview ### version The MarkBind version to use to build the site. -- 'latest' +- Latest + - `'latest'` - This is the latest published version of MarkBind -- 'master' +- Development + - `'development'` - This is the latest, possibly unpublished version of MarkBind in development -- 'X.Y.Z' +- Any valid version + - `'X.Y.Z'` - This is the version of MarkBind with the specified version number - A sample version number is '3.1.1' +- Any valid version range + - Internally the action calls [`npm install`](https://docs.npmjs.com/cli/v6/commands/npm-install) to install the specified version of MarkBind + - Hence, a version range such as `'>=3.0.0'` (or semantic versioning like `'^3.1.1'`) is also valid ### keepFiles Whether to keep the files in the published branch before pushing. This is a boolean parameter. -- false +- Keep + - `false` - This is the default value -- true +- Don't keep + - `true` - This will preserve any existing files in the published branch before an update is made. ### rootDirectory (MarkBind CLI arguments) The directory to read source files from. -- '.' +- Root + - `'.'` - This is the default value - This is for the case that your source files of the MarkBind site are in the root directory of the repository -- './path/to/directory' +- Any subdirectory + - `'./path/to/directory'` - This is for the case that your source files of the MarkBind site are in a subdirectory of the repository - - A sample path is './docs' + - A sample path is `'./docs'` ### baseUrl (MarkBind CLI arguments) The base URL relative to your domain. -- '/reponame' - - Defaults to the value of `baseUrl` in your `site.json` file - - This is important for deploying your site to GitHub Pages - - Note that you will need to specify this or in the site config file (typically the `site.json`), in order to configure the relative URL correctly. +- Default + - The value of `baseUrl` in the site config file (typically `site.json`) +- Any valid base URL + - For GitHub Pages, you will need to specify this here or in the site config file, in order to configure the relative URL correctly. + - e.g. `'/reponame'` + - For Surge, you will need to ensure that it's `''` here or in the site config file. ### siteConfig (MarkBind CLI arguments) The site config file to use. -- 'site.json' +- Default site config file + - `'site.json'` - This is the default value # Usage @@ -98,7 +117,7 @@ In essence, there are two parts to a GitHub Action workflow: - The trigger event - The jobs/steps to be run after the trigger event occurs -For our context, there two typical trigger events. This is written at the start of the workflow files: +For our context, there two typical trigger events. This is written at the start of a workflow file: (Assuming 'master' is the target branch) 1. Trigger the action whenever there is a push to the repository ```yaml @@ -131,18 +150,18 @@ jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} baseUrl: '/mb-test' version: '3.1.1' ``` -The above script builds the site from the repository's root directory, with baseUrl of '/mb-test' ('mb-test' is the repository name), with MarkBind version 3.1.1. +The above script builds the site from the repository's root directory, with `baseUrl` of '/mb-test' ('mb-test' is the repository name), with MarkBind version 3.1.1. -Then, it will deploy the site to GitHub Pages. It runs everytime there is a push to the repository. +Then, it will deploy the site to GitHub Pages. It runs everytime there is a push to the repository's master branch. -# Scenarios +# Recipes ## Deploy to Github Pages on push to main ```yaml name: MarkBind Action @@ -156,7 +175,7 @@ jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} @@ -167,13 +186,16 @@ jobs: ```yaml name: MarkBind Action -on: [push] +on: + push: + branches: + - main jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.SURGE_TOKEN }} @@ -186,13 +208,16 @@ Note that if you are using custom domain, you will need to ensure that it is con ```yaml name: MarkBind Action -on: [push] +on: + push: + branches: + - main jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} @@ -204,13 +229,16 @@ jobs: ```yaml name: MarkBind Action -on: [push] +on: + push: + branches: + - main jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} @@ -224,13 +252,13 @@ name: MarkBind Action on: pull_request: branches: - - master + - main jobs: build_and_deploy: runs-on: ubuntu-latest steps: - - name: Build & Deploy to GitHub Pages + - name: Build & Deploy MarkBind site uses: MarkBind/markbind-action@master with: token: ${{ secrets.SURGE_TOKEN }} diff --git a/action.yml b/action.yml index 155f3ec..e5244ef 100644 --- a/action.yml +++ b/action.yml @@ -52,13 +52,13 @@ runs: with: node-version: 12 - name: Checkout markbind-cli@master - if: inputs.version == 'master' + if: inputs.version == 'development' uses: actions/checkout@v3 with: repository: MarkBind/markbind path: markbind-cli - name: Install markbind-cli@master - if: inputs.version == 'master' + if: inputs.version == 'development' run: | npm i -g npm@8.3.1 cd markbind-cli @@ -68,7 +68,7 @@ runs: cd ../../.. shell: bash - name: Install a released version of markbind-cli - if: inputs.version != 'master' + if: inputs.version != 'development' run: | npm install -g markbind-cli@${{ inputs.version }} shell: bash From fcb2d546cc2a48b3cc27839d53221a033cd8de75 Mon Sep 17 00:00:00 2001 From: tlylt Date: Sun, 27 Mar 2022 20:33:01 +0800 Subject: [PATCH 05/13] Update readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 57df923..b6f6e0b 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ The domain that the site is available at. Required if service chosen is Surge(al - for PR preview purposes, the domain you specify will automatically be prefixed with 'pr-x-', where 'x' is the GitHub event number - E.g. `'pr-x-'` - Custom domain does not work with PR preview + - This action will not automatically cleanup merged PR deployments. Follow this [instruction](https://surge.sh/help/tearing-down-a-project) to manually tear down the deployed site ### version The MarkBind version to use to build the site. @@ -202,9 +203,8 @@ jobs: service: 'surge' domain: 'mb-test.surge.sh' ``` -Note that if you are using custom domain, you will need to ensure that it is configured with Surge.sh. -## Build with the development branch of MarkBind +## Build with the latest developmental version of MarkBind ```yaml name: MarkBind Action @@ -221,9 +221,8 @@ jobs: uses: MarkBind/markbind-action@master with: token: ${{ secrets.GITHUB_TOKEN }} - version: 'master' + version: 'development' ``` -'master' is specified so that the site is built with the latest (possibly unpublished) version of MarkBind. ## Build with files that is not at the root level of the repository ```yaml From f5e60b6b1897612fc9fee7a5af37fd2721269613 Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 13:46:09 +0800 Subject: [PATCH 06/13] Update Readme --- README.md | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b6f6e0b..65a77e0 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ A GitHub Action that builds and deploys your MarkBind site. ## Option Summary -Option | Required | Default | Remarks -:-------------|:--------:|-----------------------------:|----------------------------------------------------------------------------------------------------------- -token | yes | | The token to be used for the service -service | no | `'gh-pages'` | The publishing service to deploy the site -purpose | no | `'deployment'` | The deployment purpose -domain | no | `''` | The domain that the site is available at. Required if service chosen is surge or the purpose is PR preview -version | no | `'latest'` | The MarkBind version to use to build the site -keepFiles | no | `false` | Whether to keep the files in the published branch before pushing -rootDirectory | no | `'.'` | The directory to read source files from -baseUrl | no | Value specified in site.json | The base URL relative to your domain -siteConfig | no | `'site.json'` | The site config file to use +Option | Required | Default | Remarks +:-------------------------------|:--------:|-----------------------------:|----------------------------------------------------------------- +[token](#token) | yes | | The token to be used for the service +[service](#service) | no | `'gh-pages'` | The publishing service to deploy the site +[purpose](#purpose) | no | `'deployment'` | The deployment purpose +[domain](#domain) | no | `''` | The domain that the site is available at +[version](#version) | no | `'latest'` | The MarkBind version to use to build the site +[keepFiles](#keepFiles) | no | `false` | Whether to keep the files in the published branch before pushing +[rootDirectory](#rootDirectory) | no | `'.'` | The directory to read source files from +[baseUrl](#baseUrl) | no | Value specified in site.json | The base URL relative to your domain +[siteConfig](#siteConfig) | no | `'site.json'` | The site config file to use ## Option Details @@ -24,7 +24,7 @@ Currently two types of tokens are supported (correspond to the two supported pub - Note that you need to ensure that your have selected the branch that you want to deploy to in your [GitHub repo's Pages settings](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source) - Deployment to GitHub Pages might take 5-10 minutes before the site is available/refreshed - Token for Surge.sh - - Example: `${{ secrets.SURGE_TOKEN }}` + - `${{ secrets.SURGE_TOKEN }}` - `SURGE_TOKEN` is the environment secret name - Require registration with an email address - After retrieving the token, put the token as a repository secret in your @@ -46,21 +46,24 @@ The purpose of the deployment. This can be either standard deployment or for PR - This is the default value - PR preview - `'pr-preview'` - - This is used if you want to build and preview the updated site whenever there is a PR made to the repository. Note that this does not work for PR from a fork (due to security reasons) + - This is used if you want to build and preview the updated site whenever there is a PR made to the repository + - The `service` must be `'surge'` and the `domain` must be specified + - Note that this does not work for PR from a fork (due to security reasons) + - This action will not automatically cleanup merged PR deployments. Follow this [instruction](https://surge.sh/help/tearing-down-a-project) to manually tear down the deployed site if required ### domain -The domain that the site is available at. Required if service chosen is Surge(also if the purpose is PR preview). +The domain that the site is available at. Required if `service` chosen is Surge. - A surge.sh subdomain - `'.surge.sh'` - - Surge allows you to specify a subdomain for free as long as it has not been taken up by others. You have to ensure that the subDomain is unique. - - A possible subdomain to use is your repository name: `markbind-action.surge.sh` + - Surge allows you to specify a subdomain for free as long as it has not been taken up by others. You have to ensure that the `` is unique. + - A possible subdomain to use is your repository name: e.g. `markbind-action.surge.sh` - A custom domain that you have configured with Surge - - Read the [Surge documentation](https://surge.sh/help/adding-a-custom-domain) to understand how to set it up. + - Read the [Surge documentation](https://surge.sh/help/adding-a-custom-domain) to understand how to set it up - Additional notes - for PR preview purposes, the domain you specify will automatically be prefixed with 'pr-x-', where 'x' is the GitHub event number - - E.g. `'pr-x-'` + - E.g. `'pr-x-'` (and hence `'pr-1-markbind-action.surge.sh'`) - Custom domain does not work with PR preview - - This action will not automatically cleanup merged PR deployments. Follow this [instruction](https://surge.sh/help/tearing-down-a-project) to manually tear down the deployed site + - This action will not automatically cleanup merged PR deployments. Follow this [instruction](https://surge.sh/help/tearing-down-a-project) to manually tear down the deployed site if required ### version The MarkBind version to use to build the site. @@ -73,7 +76,7 @@ The MarkBind version to use to build the site. - Any valid version - `'X.Y.Z'` - This is the version of MarkBind with the specified version number - - A sample version number is '3.1.1' + - E.g. `'3.1.1'` - Any valid version range - Internally the action calls [`npm install`](https://docs.npmjs.com/cli/v6/commands/npm-install) to install the specified version of MarkBind - Hence, a version range such as `'>=3.0.0'` (or semantic versioning like `'^3.1.1'`) is also valid @@ -96,7 +99,7 @@ The directory to read source files from. - Any subdirectory - `'./path/to/directory'` - This is for the case that your source files of the MarkBind site are in a subdirectory of the repository - - A sample path is `'./docs'` + - E.g. `'./docs'` ### baseUrl (MarkBind CLI arguments) The base URL relative to your domain. @@ -105,13 +108,16 @@ The base URL relative to your domain. - Any valid base URL - For GitHub Pages, you will need to specify this here or in the site config file, in order to configure the relative URL correctly. - e.g. `'/reponame'` - - For Surge, you will need to ensure that it's `''` here or in the site config file. + - For Surge, you will need to ensure that it's specfied as `''` here or in the site config file. ### siteConfig (MarkBind CLI arguments) The site config file to use. - Default site config file - `'site.json'` - This is the default value +- Name of your site config file + - If your site config file is not named `site.json`, specify the name here + - E.g. `'ug-site.json'` # Usage In essence, there are two parts to a GitHub Action workflow: From dbd8f6f37081813deae282616721065dd73bee43 Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 13:50:42 +0800 Subject: [PATCH 07/13] Fix link --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 65a77e0..ac86c69 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ Option | Required | Default | Rema [domain](#domain) | no | `''` | The domain that the site is available at [version](#version) | no | `'latest'` | The MarkBind version to use to build the site [keepFiles](#keepFiles) | no | `false` | Whether to keep the files in the published branch before pushing -[rootDirectory](#rootDirectory) | no | `'.'` | The directory to read source files from -[baseUrl](#baseUrl) | no | Value specified in site.json | The base URL relative to your domain -[siteConfig](#siteConfig) | no | `'site.json'` | The site config file to use +[rootDirectory](#rootdirectory-markbind-cli-arguments) | no | `'.'` | The directory to read source files from +[baseUrl](#baseurl-markbind-cli-arguments) | no | Value specified in site.json | The base URL relative to your domain +[siteConfig](#siteconfig-markbind-cli-arguments) | no | `'site.json'` | The site config file to use ## Option Details From 6784a79de50f4b953dc3e63406884a486be8dd5f Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 13:56:48 +0800 Subject: [PATCH 08/13] Minor update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac86c69..0fd0f22 100644 --- a/README.md +++ b/README.md @@ -56,12 +56,12 @@ The domain that the site is available at. Required if `service` chosen is Surge. - A surge.sh subdomain - `'.surge.sh'` - Surge allows you to specify a subdomain for free as long as it has not been taken up by others. You have to ensure that the `` is unique. - - A possible subdomain to use is your repository name: e.g. `markbind-action.surge.sh` + - A possible subdomain to use is your repository name: e.g. `mb-test.surge.sh` - A custom domain that you have configured with Surge - Read the [Surge documentation](https://surge.sh/help/adding-a-custom-domain) to understand how to set it up - Additional notes - for PR preview purposes, the domain you specify will automatically be prefixed with 'pr-x-', where 'x' is the GitHub event number - - E.g. `'pr-x-'` (and hence `'pr-1-markbind-action.surge.sh'`) + - E.g. `'pr-x-'` (and hence `'pr-1-mb-test.surge.sh'`) - Custom domain does not work with PR preview - This action will not automatically cleanup merged PR deployments. Follow this [instruction](https://surge.sh/help/tearing-down-a-project) to manually tear down the deployed site if required @@ -250,7 +250,7 @@ jobs: rootDirectory: './docs' ``` -## PR Preview for PRs made following a branching workflow +## PR preview for PRs made within the same repository ```yaml name: MarkBind Action From 54483eb29aa14c2c471366f7a6836c81aaaa07e4 Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 14:09:25 +0800 Subject: [PATCH 09/13] Update table format --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0fd0f22..d5c7d8b 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ A GitHub Action that builds and deploys your MarkBind site. ## Option Summary -Option | Required | Default | Remarks -:-------------------------------|:--------:|-----------------------------:|----------------------------------------------------------------- -[token](#token) | yes | | The token to be used for the service -[service](#service) | no | `'gh-pages'` | The publishing service to deploy the site -[purpose](#purpose) | no | `'deployment'` | The deployment purpose -[domain](#domain) | no | `''` | The domain that the site is available at -[version](#version) | no | `'latest'` | The MarkBind version to use to build the site -[keepFiles](#keepFiles) | no | `false` | Whether to keep the files in the published branch before pushing +Option | Required | Default | Remarks +:-----------------------|:--------:|---------------:|----------------------------------------------------------------- +[token](#token) | yes | | The token to be used for the service +[service](#service) | no | `'gh-pages'` | The publishing service to deploy the site +[purpose](#purpose) | no | `'deployment'` | The deployment purpose +[domain](#domain) | no | `''` | The domain that the site is available at +[version](#version) | no | `'latest'` | The MarkBind version to use to build the site +[keepFiles](#keepFiles) | no | `false` | Whether to keep the files in the published branch before pushing [rootDirectory](#rootdirectory-markbind-cli-arguments) | no | `'.'` | The directory to read source files from [baseUrl](#baseurl-markbind-cli-arguments) | no | Value specified in site.json | The base URL relative to your domain [siteConfig](#siteconfig-markbind-cli-arguments) | no | `'site.json'` | The site config file to use From 4ceb24dad2bd166b058100979449269d7169f098 Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 14:16:15 +0800 Subject: [PATCH 10/13] Update version --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d5c7d8b..74e681c 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} baseUrl: '/mb-test' @@ -183,7 +183,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} version: '3.1.1' @@ -203,7 +203,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.SURGE_TOKEN }} service: 'surge' @@ -224,7 +224,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} version: 'development' @@ -244,7 +244,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} rootDirectory: './docs' @@ -264,7 +264,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Build & Deploy MarkBind site - uses: MarkBind/markbind-action@master + uses: MarkBind/markbind-action@v2 with: token: ${{ secrets.SURGE_TOKEN }} service: 'surge' From 7964e2d21e4ecc04e6b62b9dc09ffe8a377f86cc Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 21:21:47 +0800 Subject: [PATCH 11/13] Fix typo and wording --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 74e681c..82d6ec6 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,13 @@ Option | Required | Default | Remarks Currently two types of tokens are supported (correspond to the two supported publishing services): - Token for GitHub Pages - Simply use `${{ secrets.GITHUB_TOKEN }}` - - Note that you need to ensure that your have selected the branch that you want to deploy to in your [GitHub repo's Pages settings](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source) + - Note that you need to ensure that you have selected the branch that you want to deploy to in your [GitHub repo's Pages settings](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#choosing-a-publishing-source) - Deployment to GitHub Pages might take 5-10 minutes before the site is available/refreshed - Token for Surge.sh - `${{ secrets.SURGE_TOKEN }}` - `SURGE_TOKEN` is the environment secret name - Require registration with an email address - - After retrieving the token, put the token as a repository secret in your + - After retrieving the token, put the token as a repository secret in your repository - See [here](https://markbind.org/userGuide/deployingTheSite.html#previewing-prs-using-surge) for a detailed guide on how to retrieve the token ### service @@ -40,7 +40,7 @@ Currently two types of publishing services are supported: - See [here](https://surge.sh/) for more details ### purpose -The purpose of the deployment. This can be either standard deployment or for PR previewing. +The purpose of the deployment. This can either be standard deployment or for PR preview. - Standard deployment - `'deployment'` - This is the default value @@ -124,7 +124,7 @@ In essence, there are two parts to a GitHub Action workflow: - The trigger event - The jobs/steps to be run after the trigger event occurs -For our context, there two typical trigger events. This is written at the start of a workflow file: +For our context, there are two typical trigger events. This is written at the start of a workflow file: (Assuming 'master' is the target branch) 1. Trigger the action whenever there is a push to the repository ```yaml From 694895e47a2537d84dace11d35e33a364af69b54 Mon Sep 17 00:00:00 2001 From: tlylt Date: Mon, 28 Mar 2022 23:00:54 +0800 Subject: [PATCH 12/13] Fix typo --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index e5244ef..94e3624 100644 --- a/action.yml +++ b/action.yml @@ -74,8 +74,8 @@ runs: shell: bash - name: Build site run: | - BASEURL="--baseUrl ${{ inputs.baseurl }}" - if [[ ${{ inputs.baseurl }} == "unsetFlag" ]]; then + BASEURL="--baseUrl ${{ inputs.baseUrl }}" + if [[ ${{ inputs.baseUrl }} == "unsetFlag" ]]; then BASEURL="" echo "Default baseUrl to the config file attribute" fi From 909edfb33098fcc4786161e7e6c10f4ca9870024 Mon Sep 17 00:00:00 2001 From: tlylt Date: Tue, 29 Mar 2022 00:00:37 +0800 Subject: [PATCH 13/13] Fix bash error --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 94e3624..d3ce5ca 100644 --- a/action.yml +++ b/action.yml @@ -75,7 +75,7 @@ runs: - name: Build site run: | BASEURL="--baseUrl ${{ inputs.baseUrl }}" - if [[ ${{ inputs.baseUrl }} == "unsetFlag" ]]; then + if [[ "${{ inputs.baseUrl }}" == "unsetFlag" ]]; then BASEURL="" echo "Default baseUrl to the config file attribute" fi