From d639538d4b110c51c3d5272ab2f939359a52bb54 Mon Sep 17 00:00:00 2001 From: Ryan Vandersmith Date: Wed, 27 Nov 2024 16:16:28 -0700 Subject: [PATCH] Set up documentation preview (#1) * Set up docs preview with 'mo-doc' * Simplify formatter CI * Add 'docs' npm script * Update CI * Fix * Run 'dfx cache install' * Update github.io domain * Add 'destination_dir' * Fix * Adjust preview message text * Fix * Update CI * Swap out GH Pages deploy action * Fix * Simplify formatter CI * Use Node 20.x * Fix version conflict in package.json * Misc * Clarify preview text --- .github/workflows/formatting.yml | 31 ------- .github/workflows/gh-pages.yml | 83 +++++++++++++++++++ .github/workflows/pr-close.yml | 31 +++++++ .github/workflows/tests.yml | 19 +++++ package-lock.json | 137 +++++++++---------------------- package.json | 5 +- 6 files changed, 175 insertions(+), 131 deletions(-) delete mode 100644 .github/workflows/formatting.yml create mode 100644 .github/workflows/gh-pages.yml create mode 100644 .github/workflows/pr-close.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml deleted file mode 100644 index 94e5122f..00000000 --- a/.github/workflows/formatting.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Check Formatting -on: - pull_request: - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: [ubuntu-22.04] - node: [18] - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node }} - - run: npm install -g npm - - run: npm install prettier pretty-quick - - run: npm run format:check - - aggregate: - name: format:required - if: ${{ always() }} - needs: [test] - runs-on: ubuntu-latest - steps: - - name: check e2e test result - if: ${{ needs.test.result != 'success' }} - run: exit 1 diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 00000000..8970a42b --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,83 @@ +name: GitHub Pages + +on: + push: + branches: + - main + pull_request: + +jobs: + deploy: + strategy: + matrix: + node: [20] + concurrency: gh-pages-${{ github.ref }} + runs-on: ubuntu-20.04 + env: + PR_PATH: pull/${{github.event.number}} + steps: + - name: Comment on PR + uses: hasura/comment-progress@v2.2.0 + if: github.ref != 'refs/heads/main' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: deploy-preview + message: "⏳ Loading documentation preview..." + + - name: Set domain + run: echo "DOMAIN=dfinity.github.io" >> $GITHUB_ENV + + - name: Checkout website repo + uses: actions/checkout@v2 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + + - name: Setup dfx + uses: dfinity/setup-dfx@main + + - run: dfx cache install + + - name: Set production base URL + run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/" >> $GITHUB_ENV + + - name: Build docs if main branch + if: github.ref == 'refs/heads/main' + run: npm run docs + + - name: Deploy if main branch + uses: JamesIves/github-pages-deploy-action@v4 + if: github.ref == 'refs/heads/main' + with: + token: ${{ secrets.GITHUB_TOKEN }} + folder: ./docs + + - name: Set base URL for preview if PR + if: github.ref != 'refs/heads/main' + run: echo "BASE_URL=https://${{ env.DOMAIN }}/${{ github.event.repository.name }}/${{ env.PR_PATH}}/" >> $GITHUB_ENV + + - name: Build PR preview website + if: github.ref != 'refs/heads/main' + run: npm run docs + + - name: Deploy to PR preview + uses: JamesIves/github-pages-deploy-action@v4 + if: github.ref != 'refs/heads/main' + with: + token: ${{ secrets.GITHUB_TOKEN }} + folder: ./docs + target-folder: ${{ env.PR_PATH }} + + - name: Update comment + uses: hasura/comment-progress@v2.2.0 + if: github.ref != 'refs/heads/main' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: deploy-preview + message: "✨ Documentation preview for ${{ github.event.after }}:\n\n> **${{ env.BASE_URL }}**\n\n[Source code](https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/)" diff --git a/.github/workflows/pr-close.yml b/.github/workflows/pr-close.yml new file mode 100644 index 00000000..e9b4be86 --- /dev/null +++ b/.github/workflows/pr-close.yml @@ -0,0 +1,31 @@ +name: Delete preview on PR close + +# only trigger on pull request closed events +on: + pull_request: + types: [closed] + +jobs: + delete_preview: + runs-on: ubuntu-20.04 + env: + PR_PATH: pull/${{github.event.number}} + steps: + - name: Make empty dir + run: mkdir public + + - name: Delete folder + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + destination_dir: ${{ env.PR_PATH }} + + - name: Comment on PR + uses: hasura/comment-progress@v2.2.0 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.number }} + id: deploy-preview + message: "PR closed. Deleted preview at https://github.com/${{ github.repository }}/tree/gh-pages/${{ env.PR_PATH }}/" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..c88a8f63 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,19 @@ +name: Tests +on: + pull_request: + +jobs: + format: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-22.04] + node: [20] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + - run: npm ci + - run: npm run format:check diff --git a/package-lock.json b/package-lock.json index 87fa7bf5..277950b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "mo-dev": "^0.13.0", "prettier": "2", "prettier-plugin-motoko": "^0.10.1", - "pretty-quick": "^4.0.0" + "pretty-quick": "3" } }, "node_modules/@dfinity/agent": { @@ -3127,20 +3127,17 @@ "license": "MIT" }, "node_modules/find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, "license": "MIT", "dependencies": { - "locate-path": "^6.0.0", + "locate-path": "^5.0.0", "path-exists": "^4.0.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=8" } }, "node_modules/foreground-child": { @@ -4171,19 +4168,16 @@ } }, "node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "dev": true, "license": "MIT", "dependencies": { - "p-locate": "^5.0.0" + "p-locate": "^4.1.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=8" } }, "node_modules/lodash.includes": { @@ -5640,35 +5634,32 @@ } }, "node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, "license": "MIT", "dependencies": { - "yocto-queue": "^0.1.0" + "p-try": "^2.0.0" }, "engines": { - "node": ">=10" + "node": ">=6" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", "dev": true, "license": "MIT", "dependencies": { - "p-limit": "^3.0.2" + "p-limit": "^2.2.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=8" } }, "node_modules/p-map": { @@ -5746,6 +5737,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/package-json-from-dist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", @@ -5992,14 +5993,14 @@ } }, "node_modules/pretty-quick": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/pretty-quick/-/pretty-quick-4.0.0.tgz", - "integrity": "sha512-M+2MmeufXb/M7Xw3Afh1gxcYpj+sK0AxEfnfF958ktFeAyi5MsKY5brymVURQLgPLV1QaF5P4pb2oFJ54H3yzQ==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/pretty-quick/-/pretty-quick-3.3.1.tgz", + "integrity": "sha512-3b36UXfYQ+IXXqex6mCca89jC8u0mYLqFAN5eTQKoXO6oCQYcIVYZEB/5AlBHI7JPYygReM2Vv6Vom/Gln7fBg==", "dev": true, "license": "MIT", "dependencies": { - "execa": "^5.1.1", - "find-up": "^5.0.0", + "execa": "^4.1.0", + "find-up": "^4.1.0", "ignore": "^5.3.0", "mri": "^1.2.0", "picocolors": "^1.0.0", @@ -6007,60 +6008,13 @@ "tslib": "^2.6.2" }, "bin": { - "pretty-quick": "lib/cli.mjs" + "pretty-quick": "dist/cli.js" }, "engines": { - "node": ">=14" + "node": ">=10.13" }, "peerDependencies": { - "prettier": "^3.0.0" - } - }, - "node_modules/pretty-quick/node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "dev": true, - "license": "MIT", - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, - "node_modules/pretty-quick/node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/pretty-quick/node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": ">=10.17.0" + "prettier": "^2.0.0" } }, "node_modules/pretty-quick/node_modules/picomatch": { @@ -7413,19 +7367,6 @@ "fd-slicer": "~1.1.0" } }, - "node_modules/yocto-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/yoctocolors": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.1.tgz", diff --git a/package.json b/package.json index b04c03bc..2ab02d1d 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,12 @@ "description": "The Motoko base library v2", "private": true, "scripts": { + "postinstall": "mops install", "format:check": "npx -p prettier -p pretty-quick pretty-quick --check", "format": "npx -p prettier -p pretty-quick pretty-quick", "test": "node test/js && mops test --reporter files", "validate": "node test/js/validate", - "postinstall": "mops install" + "docs": "$(dfx cache show)/mo-doc" }, "repository": { "type": "git", @@ -29,6 +30,6 @@ "mo-dev": "^0.13.0", "prettier": "2", "prettier-plugin-motoko": "^0.10.1", - "pretty-quick": "^4.0.0" + "pretty-quick": "3" } }