From 59eeebf97a28a35833d5c565be79a43cca08f3ed Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Tue, 26 Jan 2021 14:07:01 +0800 Subject: [PATCH 1/7] Add initial modifications --- packages/core/src/Site/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/Site/index.js b/packages/core/src/Site/index.js index 466742da8f..b0d324cf1d 100644 --- a/packages/core/src/Site/index.js +++ b/packages/core/src/Site/index.js @@ -1174,6 +1174,17 @@ class Site { name: 'AppVeyorBot', email: 'deploy@appveyor.com', }; + } else if (process.env.GITHUB_ACTIONS) { + if (options.repo) { + repoSlug = Site.extractRepoSlug(options.repo); + } else { + repoSlug = process.env.GITHUB_REPOSITORY; + } + + options.user = { + name: 'Github', + email: 'noreply@github.com', + }; } else { throw new Error('-c/--ci should only be run in CI environments.'); } From d2d34a8e5694644d29c7a07cdd4e44b450598c01 Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Tue, 26 Jan 2021 14:13:39 +0800 Subject: [PATCH 2/7] Update user for gh-action --- packages/core/src/Site/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/Site/index.js b/packages/core/src/Site/index.js index b0d324cf1d..90e2a2e02c 100644 --- a/packages/core/src/Site/index.js +++ b/packages/core/src/Site/index.js @@ -1182,8 +1182,8 @@ class Site { } options.user = { - name: 'Github', - email: 'noreply@github.com', + name: 'github-actions', + email: 'github-actions@github.com', }; } else { throw new Error('-c/--ci should only be run in CI environments.'); From 3ce12194d316f4302af4a038479fd02c0cbe2508 Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Sat, 30 Jan 2021 13:50:44 +0800 Subject: [PATCH 3/7] Fix failing tests --- packages/core/test/unit/Site.test.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/test/unit/Site.test.js b/packages/core/test/unit/Site.test.js index 7637747b86..5daeb91107 100644 --- a/packages/core/test/unit/Site.test.js +++ b/packages/core/test/unit/Site.test.js @@ -282,11 +282,13 @@ describe('Site deploy with various CI environments', () => { beforeEach(() => { // Delete all environment variables that affect tests - delete process.env.TRAVIS; delete process.env.GITHUB_TOKEN; + delete process.env.TRAVIS; delete process.env.TRAVIS_REPO_SLUG; delete process.env.APPVEYOR; delete process.env.APPVEYOR_REPO_NAME; + delete process.env.GITHUB_ACTIONS; + delete process.env.GITHUB_REPOSITORY; }); afterAll(() => { @@ -297,6 +299,7 @@ describe('Site deploy with various CI environments', () => { test.each([ ['TRAVIS', 'TRAVIS_REPO_SLUG', { name: 'Deployment Bot', email: 'deploy@travis-ci.org' }], ['APPVEYOR', 'APPVEYOR_REPO_NAME', { name: 'AppVeyorBot', email: 'deploy@appveyor.com' }], + ['GITHUB_ACTIONS', 'GITHUB_REPOSITORY', { name: 'github-actions', email: 'github-actions@github.com' }], ])('Site deploy -c/--ci deploys with default settings', async (ciIdentifier, repoSlugIdentifier, deployBotUser) => { process.env[ciIdentifier] = true; @@ -319,6 +322,7 @@ describe('Site deploy with various CI environments', () => { test.each([ ['TRAVIS', 'TRAVIS_REPO_SLUG'], ['APPVEYOR', 'APPVEYOR_REPO_NAME'], + ['GITHUB_ACTIONS', 'GITHUB_REPOSITORY'], ])('Site deploy -c/--ci deploys with custom GitHub repo', async (ciIdentifier, repoSlugIdentifier) => { process.env[ciIdentifier] = true; @@ -342,6 +346,7 @@ describe('Site deploy with various CI environments', () => { test.each([ ['TRAVIS', 'TRAVIS_REPO_SLUG'], ['APPVEYOR', 'APPVEYOR_REPO_NAME'], + ['GITHUB_ACTIONS', 'GITHUB_REPOSITORY'], ])('Site deploy -c/--ci deploys to correct repo when .git is in repo name', async (ciIdentifier, repoSlugIdentifier) => { process.env[ciIdentifier] = true; @@ -378,6 +383,7 @@ describe('Site deploy with various CI environments', () => { test.each([ ['TRAVIS'], ['APPVEYOR'], + ['GITHUB_ACTIONS'], ])('Site deploy -c/--ci should not deploy without authentication token', async (ciIdentifier) => { process.env[ciIdentifier] = true; @@ -396,6 +402,7 @@ describe('Site deploy with various CI environments', () => { test.each([ ['TRAVIS'], ['APPVEYOR'], + ['GITHUB_ACTIONS'], ])('Site deploy -c/--ci should not deploy if custom repository is not on GitHub', async (ciIdentifier) => { process.env[ciIdentifier] = true; process.env.GITHUB_TOKEN = 'githubToken'; From baaedd2c71e0e05df26575db4784fff76001e5c3 Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Sun, 31 Jan 2021 15:17:19 +0800 Subject: [PATCH 4/7] Update deploy url to include x-access-token --- packages/core/src/Site/index.js | 2 +- packages/core/test/unit/Site.test.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/src/Site/index.js b/packages/core/src/Site/index.js index 90e2a2e02c..81fac27d33 100644 --- a/packages/core/src/Site/index.js +++ b/packages/core/src/Site/index.js @@ -1189,7 +1189,7 @@ class Site { throw new Error('-c/--ci should only be run in CI environments.'); } - options.repo = `https://${githubToken}@github.com/${repoSlug}.git`; + options.repo = `https://x-access-token:${githubToken}@github.com/${repoSlug}.git`; } publish(basePath, options); diff --git a/packages/core/test/unit/Site.test.js b/packages/core/test/unit/Site.test.js index 5daeb91107..047cf87dd5 100644 --- a/packages/core/test/unit/Site.test.js +++ b/packages/core/test/unit/Site.test.js @@ -315,7 +315,8 @@ describe('Site deploy with various CI environments', () => { const site = new Site('./', '_site'); await site.deploy(true); expect(ghpages.options.repo) - .toEqual(`https://${process.env.GITHUB_TOKEN}@github.com/${process.env[repoSlugIdentifier]}.git`); + // eslint-disable-next-line max-len + .toEqual(`https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env[repoSlugIdentifier]}.git`); expect(ghpages.options.user).toEqual(deployBotUser); }); @@ -340,7 +341,7 @@ describe('Site deploy with various CI environments', () => { const site = new Site('./', '_site'); await site.deploy(true); expect(ghpages.options.repo) - .toEqual(`https://${process.env.GITHUB_TOKEN}@github.com/USER/REPO.git`); + .toEqual(`https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/USER/REPO.git`); }); test.each([ @@ -362,7 +363,8 @@ describe('Site deploy with various CI environments', () => { const site = new Site('./', '_site'); await site.deploy(true); expect(ghpages.options.repo) - .toEqual(`https://${process.env.GITHUB_TOKEN}@github.com/${process.env[repoSlugIdentifier]}.git`); + // eslint-disable-next-line max-len + .toEqual(`https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${process.env[repoSlugIdentifier]}.git`); }); test('Site deploy -c/--ci should not deploy if not in CI environment', async () => { From 4873ff288ddde1c82b760aef8cba6521ce725538 Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Sun, 31 Jan 2021 16:20:34 +0800 Subject: [PATCH 5/7] Update userGuide - Add section on deploying to gh-pages via Github Actions --- docs/userGuide/deployingTheSite.md | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/userGuide/deployingTheSite.md b/docs/userGuide/deployingTheSite.md index e4a3eac0dd..6884bb2230 100644 --- a/docs/userGuide/deployingTheSite.md +++ b/docs/userGuide/deployingTheSite.md @@ -65,11 +65,36 @@ You can override the default deployment settings %%(e.g., repo/branch to deploy) ### Deploying to GitHub Pages via CI Tools **You can setup CI Tools to automatically build and deploy your site on GitHub Pages every time your GitHub repo is updated.** - + -Markbind currently supports deploying to Github Pages via [Travis CI](https://www.travis-ci.com/) or [AppVeyor CI](https://www.appveyor.com/). - +To instruct [Github Actions](https://docs.github.com/en/actions) to build and deploy the site when you push to the repository, add a Github Actions workflow file in your project repo at the location `/.github/workflows/deploy.yml` A sample workflow file is provided below: +``` +name: Deploy Markbind Site +on: + push: + branches: master + +jobs: + build: + runs-on: ubuntu-latest + name: test + env: + GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '10' + - run: npm i -g markbind-cli + - run: markbuild build + - run: markbind deploy --ci +``` +Once you have created the file, commit and push the file to your repo. Github Actions should start to build and deploy your markbind site. You can verify this by visiting `www.github.com///actions`. + +For more information on customizing your workflow file to fit your specific needs, you may refer to the [Github Action Docs](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions). + + From 84e5cd4acc2628a2b1c1d760def279eefc72c787 Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Mon, 1 Feb 2021 05:59:57 +0800 Subject: [PATCH 6/7] Fix typo in userGuide - markbuild -> markbind --- docs/userGuide/deployingTheSite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userGuide/deployingTheSite.md b/docs/userGuide/deployingTheSite.md index 6884bb2230..13cac5e5c2 100644 --- a/docs/userGuide/deployingTheSite.md +++ b/docs/userGuide/deployingTheSite.md @@ -86,7 +86,7 @@ jobs: with: node-version: '10' - run: npm i -g markbind-cli - - run: markbuild build + - run: markbind build - run: markbind deploy --ci ``` From 754dd5af25153b7613f4af5ca807a030a3cf8bac Mon Sep 17 00:00:00 2001 From: raysonkoh Date: Mon, 1 Feb 2021 19:06:11 +0800 Subject: [PATCH 7/7] Update userGuide - Add note that personal access token would also work in place of default github token --- docs/userGuide/deployingTheSite.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/userGuide/deployingTheSite.md b/docs/userGuide/deployingTheSite.md index 13cac5e5c2..d87d5df3fa 100644 --- a/docs/userGuide/deployingTheSite.md +++ b/docs/userGuide/deployingTheSite.md @@ -90,6 +90,11 @@ jobs: - run: markbind deploy --ci ``` + + +The sample `deploy.yml` workflow above uses the [default Github Token secret](https://docs.github.com/en/actions/reference/authentication-in-a-workflow) that is generated automatically for each Github Actions workflow. You may also use a Github Personal Access Token in place of the default Github Token. For steps on setting up your Github Personal Access Token, you may refer to the [setup instructions for Travis CI](#configuring-your-repository-in-travis-ci). + + Once you have created the file, commit and push the file to your repo. Github Actions should start to build and deploy your markbind site. You can verify this by visiting `www.github.com///actions`. For more information on customizing your workflow file to fit your specific needs, you may refer to the [Github Action Docs](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions).