Skip to content

Commit 862f60b

Browse files
authored
chore(ci): Use actions/deploy-pages for Cargo Contributor Guide deployment (#16876)
This replaces the `gh-pages` git branch deployment with the official `actions/upload-pages-artifact` and `actions/deploy-pages` actions. It requires changing the repository's Pages settings from "Deploy from a branch" to "GitHub Actions" as described also in rust-lang/rfcs#3419, which has used a similar setup for a while now. I've tested the `build` job in my forked repo and verified that the artifact contents match the current content of the `gh-pages` branch. I did not test the `deploy` job with my fork repo, but since it is the same as in e.g. the `rfcs` repo I don't expect any issues from that.
2 parents 6307456 + 732417a commit 862f60b

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

.github/workflows/contrib.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,45 @@ env:
1515
MDBOOK_VERSION: 0.5.1
1616

1717
jobs:
18-
deploy:
19-
permissions:
20-
contents: write # for Git to git push
18+
build:
2119
runs-on: ubuntu-latest
2220
steps:
2321
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24-
with:
25-
fetch-depth: 0
2622
- name: Install mdbook
2723
run: |
2824
mkdir mdbook
2925
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
3026
echo `pwd`/mdbook >> $GITHUB_PATH
31-
- name: Deploy docs
27+
- name: Build
3228
run: |
3329
GENERATE_PY="$(pwd)/ci/generate.py"
3430
3531
cd src/doc/contrib
3632
mdbook build
3733
38-
# Override previous ref to avoid keeping history.
39-
git worktree add --orphan -B gh-pages gh-pages
40-
git config user.name "Deploy from CI"
41-
git config user.email ""
34+
mkdir gh-pages
4235
cd gh-pages
4336
mv ../book contrib
44-
git add contrib
4537
4638
# Generate HTML for link redirections.
4739
python3 "$GENERATE_PY"
48-
git add *.html
49-
# WARN: The CNAME file is for GitHub to redirect requests to the custom domain.
50-
# Missing this may entail security hazard and domain takeover.
51-
# See <https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#securing-your-custom-domain>
52-
git add CNAME
53-
54-
git commit -m "Deploy $GITHUB_SHA to gh-pages"
55-
git push origin +gh-pages
40+
- name: Upload Artifact
41+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
42+
with:
43+
path: src/doc/contrib/gh-pages
44+
45+
deploy:
46+
needs: build
47+
48+
permissions:
49+
pages: write # to deploy to Pages
50+
id-token: write # to verify the deployment originates from an appropriate source
51+
52+
environment:
53+
name: github-pages
54+
url: ${{ steps.deployment.outputs.page_url }}
55+
56+
runs-on: ubuntu-latest
57+
steps:
58+
- id: deployment
59+
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0

ci/generate.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,5 @@ def main():
3939
mapped = "https://doc.rust-lang.org/cargo/reference/{}".format(name)
4040
f.write(TEMPLATE.format(name=name, mapped=mapped))
4141

42-
# WARN: The CNAME file is for GitHub to redirect requests to the custom domain.
43-
# Missing this may entail security hazard and domain takeover.
44-
# See <https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#securing-your-custom-domain>
45-
with open('CNAME', 'w') as f:
46-
f.write('doc.crates.io')
47-
4842
if __name__ == '__main__':
4943
main()

0 commit comments

Comments
 (0)