From 9df110026462407a56aa7075519c37d357295370 Mon Sep 17 00:00:00 2001 From: OTheDev <116417456+OTheDev@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:14:51 +0700 Subject: [PATCH 1/4] Add doc preview --- .github/workflows/docs.yml | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..dfeb13b --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,90 @@ +name: Documentation + +on: + pull_request: + branches: [ main ] + paths: + - 'arbi/**' + - '.github/workflows/docs.yml' + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + pull-requests: write + +jobs: + build-deploy-docs: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Rust + run: | + rustup toolchain install nightly + rustup override set nightly + + - name: Build Documentation + run: | + RUSTDOCFLAGS="--html-in-header ./arbi/doc/header.html --cfg docsrs" cargo +nightly doc --no-deps --all-features + + - name: Prepare PR-specific path + if: github.event_name == 'pull_request' + run: | + mkdir -p "pr-${{ github.event.number }}" + mv target/doc "pr-${{ github.event.number }}/doc" + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: '.' + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + + - name: Comment PR + uses: actions/github-script@v7 + if: github.event_name == 'pull_request' + with: + script: | + const url = `${{ steps.deployment.outputs.page_url }}pr-${{ github.event.number }}/doc/arbi/index.html`; + const timestamp = new Date().toISOString(); + const message = `📚 Documentation preview is ready!\nView it here: ${url}\n\n_Last updated: ${timestamp}_`; + + // Find existing comments + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + }); + + // Look for our documentation preview comment + const docComment = comments.data.find(comment => + comment.body.includes('📚 Documentation preview is ready!') + ); + + if (docComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: docComment.id, + body: message + }); + } else { + // Create new comment if none exists + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + body: message + }); + } From 70ffc96d3da6f956b8e39eb48242ebfdf00b61aa Mon Sep 17 00:00:00 2001 From: OTheDev <116417456+OTheDev@users.noreply.github.com> Date: Mon, 20 Jan 2025 18:25:25 +0700 Subject: [PATCH 2/4] Add commit hash of last successful preview --- .github/workflows/docs.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index dfeb13b..363d0b6 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,7 +28,7 @@ jobs: rustup toolchain install nightly rustup override set nightly - - name: Build Documentation + - name: Build static files (documentation) run: | RUSTDOCFLAGS="--html-in-header ./arbi/doc/header.html --cfg docsrs" cargo +nightly doc --no-deps --all-features @@ -41,7 +41,7 @@ jobs: - name: Setup Pages uses: actions/configure-pages@v4 - - name: Upload artifact + - name: Upload static files as artifact uses: actions/upload-pages-artifact@v3 with: path: '.' @@ -50,37 +50,36 @@ jobs: id: deployment uses: actions/deploy-pages@v4 - - name: Comment PR + - name: Comment on PR - documentation preview link uses: actions/github-script@v7 if: github.event_name == 'pull_request' with: script: | const url = `${{ steps.deployment.outputs.page_url }}pr-${{ github.event.number }}/doc/arbi/index.html`; const timestamp = new Date().toISOString(); - const message = `📚 Documentation preview is ready!\nView it here: ${url}\n\n_Last updated: ${timestamp}_`; + const commit_hash = context.payload.pull_request.head.sha; + const message = `📚 Documentation preview is ready!\nView it here: ${url}\n\n_Last updated: ${timestamp}_\n_Commit: ${commit_hash}_`; - // Find existing comments + // Look for an existing documentation preview comment. const comments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, }); - - // Look for our documentation preview comment - const docComment = comments.data.find(comment => + const doc_comment = comments.data.find(comment => comment.body.includes('📚 Documentation preview is ready!') ); - if (docComment) { - // Update existing comment + if (doc_comment) { + // If a comment exists, update the existing one. await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, - comment_id: docComment.id, + comment_id: doc_comment.id, body: message }); } else { - // Create new comment if none exists + // If no comment exists, create a new one. await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, From 229bab9af9acf83d114a05bebb4b53bcfcce7f9b Mon Sep 17 00:00:00 2001 From: OTheDev <116417456+OTheDev@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:24:34 +0700 Subject: [PATCH 3/4] Update message --- .github/workflows/docs.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 363d0b6..dc1541a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -58,7 +58,7 @@ jobs: const url = `${{ steps.deployment.outputs.page_url }}pr-${{ github.event.number }}/doc/arbi/index.html`; const timestamp = new Date().toISOString(); const commit_hash = context.payload.pull_request.head.sha; - const message = `📚 Documentation preview is ready!\nView it here: ${url}\n\n_Last updated: ${timestamp}_\n_Commit: ${commit_hash}_`; + const message = `📚 Documentation preview: ${url}\n\n_Last updated: ${timestamp}_\n_Commit: ${commit_hash}_`; // Look for an existing documentation preview comment. const comments = await github.rest.issues.listComments({ @@ -67,23 +67,25 @@ jobs: issue_number: context.payload.pull_request.number, }); const doc_comment = comments.data.find(comment => - comment.body.includes('📚 Documentation preview is ready!') + comment.body.includes('📚 Documentation preview') ); + + const comment_params = { + owner: context.repo.owner, + repo: context.repo.repo, + body: message + }; if (doc_comment) { // If a comment exists, update the existing one. await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, + ...comment_params, comment_id: doc_comment.id, - body: message }); } else { // If no comment exists, create a new one. await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, + ...comment_params, issue_number: context.payload.pull_request.number, - body: message }); } From bc0747f8af188c71e6ad1a0f205b664a8fe699a1 Mon Sep 17 00:00:00 2001 From: OTheDev <116417456+OTheDev@users.noreply.github.com> Date: Mon, 20 Jan 2025 20:06:23 +0700 Subject: [PATCH 4/4] Update --- .github/workflows/docs.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index dc1541a..5ecdf2a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,6 +14,10 @@ permissions: id-token: write pull-requests: write +concurrency: + group: "pages" + cancel-in-progress: false + jobs: build-deploy-docs: runs-on: ubuntu-latest @@ -21,35 +25,29 @@ jobs: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - - uses: actions/checkout@v4 - + - name: Checkout + uses: actions/checkout@v4 - name: Setup Rust run: | rustup toolchain install nightly rustup override set nightly - - name: Build static files (documentation) run: | RUSTDOCFLAGS="--html-in-header ./arbi/doc/header.html --cfg docsrs" cargo +nightly doc --no-deps --all-features - - name: Prepare PR-specific path if: github.event_name == 'pull_request' run: | mkdir -p "pr-${{ github.event.number }}" mv target/doc "pr-${{ github.event.number }}/doc" - - name: Setup Pages - uses: actions/configure-pages@v4 - - - name: Upload static files as artifact + uses: actions/configure-pages@v5 + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: '.' - - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 - - name: Comment on PR - documentation preview link uses: actions/github-script@v7 if: github.event_name == 'pull_request'