mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
2f87bb8c1f
# Objective - Some developers enable Github Actions for their fork and commit directly to main. This triggers the `docs.yml` action, which attempts to deploy the documentation even if Github Pages is not enabled. (It also creates a `CNAME` file specific to Bevy and should not be used in forks, even for testing.) - For an example, see [this run](https://github.com/tychedelia/bevy/actions/runs/8978912060/job/24660082729). ## Solution - Only attempt to deploy docs when running from the main Bevy repository. - This does not affect us checking `cargo doc` on pull requests, since that it done in `ci.yml`. ## Testing It's difficult to test this, but you'd probably: 1. Fork Bevy 2. Cherry pick this PR's commits onto the main branch of your fork. 3. Push another commit to the main branch, triggering Github Actions. 4. Check the Github Actions job summary to ensure that the `build-and-deploy` job is skipped.
82 lines
2.7 KiB
YAML
82 lines
2.7 KiB
YAML
name: Deploy Docs
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
# Allows running the action manually.
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTDOCFLAGS: --html-in-header header.html
|
|
# If nightly is breaking CI, modify this variable to target a specific nightly version.
|
|
NIGHTLY_TOOLCHAIN: nightly
|
|
|
|
# Sets the permissions to allow deploying to Github pages.
|
|
permissions:
|
|
contents: read
|
|
pages: write
|
|
id-token: write
|
|
|
|
# Only allow one deployment to run at a time, however it will not cancel in-progress runs.
|
|
concurrency:
|
|
group: "pages"
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
# Only run this job when on the main Bevy repository. Without this, it would also run on forks
|
|
# where developers work on the main branch but have not enabled Github Pages.
|
|
if: ${{ github.repository == 'bevyengine/bevy' }}
|
|
environment:
|
|
name: github-pages
|
|
url: ${{ steps.deployment.outputs.page_url }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: dtolnay/rust-toolchain@master
|
|
with:
|
|
toolchain: ${{ env.NIGHTLY_TOOLCHAIN }}
|
|
|
|
- name: Install Linux dependencies
|
|
uses: ./.github/actions/install-linux-deps
|
|
with:
|
|
wayland: true
|
|
xkb: true
|
|
|
|
# This does the following:
|
|
# - Replaces the docs icon with one that clearly denotes it's not the released package on crates.io
|
|
# - Adds a meta tag that forces Google not to index any page on the site.
|
|
- name: Pre-docs-build
|
|
run: |
|
|
sed -i.bak "s/icon.png/icon-docs-dev.png/" src/lib.rs
|
|
echo "<meta name=\"robots\" content=\"noindex\">" > header.html
|
|
|
|
- name: Build docs
|
|
env:
|
|
# needs to be in sync with [package.metadata.docs.rs]
|
|
RUSTDOCFLAGS: -Zunstable-options --cfg=docsrs
|
|
run: cargo doc --all-features --no-deps -p bevy -Zunstable-options -Zrustdoc-scrape-examples
|
|
|
|
# This adds the following:
|
|
# - A top level redirect to the bevy crate documentation
|
|
# - A CNAME file for redirecting the docs domain to the API reference
|
|
# - A robots.txt file to forbid any crawling of the site (to defer to the docs.rs site on search engines).
|
|
- name: Finalize documentation
|
|
run: |
|
|
echo "<meta http-equiv=\"refresh\" content=\"0; url=bevy/index.html\">" > target/doc/index.html
|
|
echo "dev-docs.bevyengine.org" > target/doc/CNAME
|
|
echo "User-Agent: *\nDisallow: /" > target/doc/robots.txt
|
|
rm target/doc/.lock
|
|
|
|
- name: Upload site artifact
|
|
uses: actions/upload-pages-artifact@v3
|
|
with:
|
|
path: target/doc
|
|
|
|
- name: Deploy to Github Pages
|
|
id: deployment
|
|
uses: actions/deploy-pages@v4
|