Skip to content

Commit

Permalink
Auto merge of #257 - lennart/docs-custom-index, r=TroyKomodo
Browse files Browse the repository at this point in the history
feat(ci): add custom html step for docs
- Adds CI step to insert custom html into the docs

Requested-by: TroyKomodo <[email protected]>
Reviewed-by: TroyKomodo <[email protected]>
  • Loading branch information
scuffle-brawl[bot] authored Jan 19, 2025
2 parents 5447007 + 6be9234 commit 7747f1a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .github/patch-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail

repo_url=$1
commit_hash=$2
short_commit_hash=$3
pull_request_number=$4

pull_request_code=""
if [ -n "$pull_request_number" ]; then
pull_request_code="<br><a href=\"$repo_url/pull/$pull_request_number\">Pull Request $pull_request_number</a>"
fi

commit_code="<br><a href=\"$repo_url/commit/$commit_hash\">Commit <code>$short_commit_hash</code></a>"

sed -i "s#</nav><div class=\"sidebar-resizer\"#<div class=\"version\">Deployed from$pull_request_code$commit_code</div></nav><div class=\"sidebar-resizer\"#" target/doc/index.html
27 changes: 20 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,39 @@ jobs:
run: |
RUSTDOCFLAGS="-D warnings --cfg docsrs --enable-index-page -Zunstable-options" cargo +${{ env.RUST_TOOLCHAIN }} doc --no-deps --all-features
- name: Upload docs
uses: actions/upload-artifact@v4
with:
name: docs
path: target/doc

- name: Get PR Number
if: ${{ startsWith(github.ref, 'refs/heads/automation/brawl/try/') }}
run: |
PR_NUMBER=$(echo ${{ github.ref }} | sed -n 's/^refs\/heads\/automation\/brawl\/try\/\([0-9]*\)$/\1/p')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Get short commit SHA
run: |
SHORT_SHA=$(echo ${{ env.SHA }} | cut -c 1-7)
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
- name: Insert custom html for PR
if: ${{ startsWith(github.ref, 'refs/heads/automation/brawl/try/') || github.event.pull_request.head.repo.full_name == github.repository }}
run: .github/patch-docs.sh ${{ github.event.repository.html_url }} ${{ env.SHA }} ${{ env.SHORT_SHA }} ${{ env.PR_NUMBER || github.event.pull_request.number }}

- name: Insert custom html for merge
if: ${{ startsWith(github.ref, 'refs/heads/automation/brawl/merge/') }}
run: .github/patch-docs.sh ${{ github.event.repository.html_url }} ${{ env.SHA }} ${{ env.SHORT_SHA }}

- name: Upload docs
uses: actions/upload-artifact@v4
with:
name: docs
path: target/doc

- name: Deploy
if: ${{ startsWith(github.ref, 'refs/heads/automation/brawl/try/') || github.event.pull_request.head.repo.full_name == github.repository }}
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_DOCS_API_KEY }}
accountId: ${{ secrets.CF_DOCS_ACCOUNT_ID }}
command: pages deploy --project-name=scuffle-docrs --branch=pr/${{ env.PR_NUMBER || github.event.pull_request.number }} --commit-hash=${{ env.SHA }} ./target/doc
command: pages deploy --project-name=scuffle-docrs --branch=pr/${{ env.PR_NUMBER || github.event.pull_request.number }} --commit-hash=${{ env.SHA }} --commit-dirty=true ./target/doc

brawl-done:
runs-on: ubuntu-24.04
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/docs-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- test-deploy

jobs:
docs:
Expand All @@ -30,4 +29,4 @@ jobs:
with:
apiToken: ${{ secrets.CF_DOCS_API_KEY }}
accountId: ${{ secrets.CF_DOCS_ACCOUNT_ID }}
command: pages deploy --project-name=scuffle-docrs --branch=main --commit-hash=${{ github.sha }} ./target/doc
command: pages deploy --project-name=scuffle-docrs --branch=main --commit-hash=${{ github.sha }} --commit-dirty=true ./target/doc

0 comments on commit 7747f1a

Please sign in to comment.