Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR previews #4819

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Cargo.lock linguist-generated=true merge=binary
flake.lock linguist-generated=true merge=binary
poetry.lock linguist-generated=true merge=binary
uv.lock linguist-generated=true merge=binary
9 changes: 3 additions & 6 deletions .github/scripts/docs-build-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Run from the root directory of the project as
# .github/scripts/docs-build-deploy 'https://martinvonz.github.io' prerelease main
# All arguments after the first are passed to `mike deploy`, run
# `poetry run -- mike deploy --help` for options. Note that `mike deploy`
# `uv run -- mike deploy --help` for options. Note that `mike deploy`
# creates a commit directly on the `gh-pages` branch.
set -ev

Expand All @@ -13,15 +13,12 @@ export "SITE_URL_FOR_MKDOCS=$1"; shift
# https://github.com/jimporter/mike/issues/103 and
# https://reproducible-builds.org/docs/source-date-epoch/
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct docs/ mkdocs.yml)
# https://github.com/python-poetry/poetry/issues/1917 and
# https://github.com/python-poetry/poetry/issues/8623
export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring
poetry install # Only really needed once per environment unless there are updates
uv sync # Only really needed once per environment unless there are updates
# TODO: `--alias-type symlink` is the
# default, and may be nicer in some ways. However,
# this requires deploying to GH Pages via a "custom GitHub Action", as in
# https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow.
# Otherwise, you get an error:
# > Site contained a symlink that should be dereferenced: /main.
# > For more information, see https://docs.github.com/github/working-with-github-pages/troubleshooting-jekyll-build-errors-for-github-pages-sites#config-file-error.
poetry run -- mike deploy --alias-type copy "$@"
uv run -- mike deploy --alias-type copy "$@"
33 changes: 5 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,37 +126,14 @@ jobs:
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: 3.11
- name: Install poetry (latest release)
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd
- name: Install uv
uses: astral-sh/setup-uv@2e657c127d5b1635d5a8e3fa40e0ac50a5bf6992
with:
poetry-version: latest
version: "0.5.1"
- name: Install dependencies
run: poetry install
run: uv sync
- name: Check that `mkdocs` can build the docs
run: poetry run -- mkdocs build --strict

mkdocs-old-poetry:
name: Check that MkDocs can build the docs with Poetry 1.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: 3.11
- name: Install poetry
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd
with:
# Test with the version of Poetry in Debian stable. If this starts
# failing, we should increase this version and document the minimum
# necessary version of Poetry in contributing.md.
#
# One way to install old `poetry` is using `pipx`:
# pipx install 'poetry<1.4' --suffix -1.3
poetry-version: 1.8
- name: Install dependencies
run: poetry install
- name: Check that `mkdocs` can build the docs
run: poetry run -- mkdocs build --strict
run: uv run -- mkdocs build --strict

cargo-deny:
runs-on: ubuntu-latest
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/docs-preview-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

# This action builds and deploys the docs on each pull request created
# Security notes:
# The preview deployment is split in two workflows, preview_build and preview_deploy.
# `preview_build` runs on pull_request, so it won't have any access to the repositories secrets, so it is safe to
# build / execute untrusted code.
# `preview_deploy` has access to the repositories secrets (so it can push to the pr preview repo) but won't run
# any untrusted code (it will just extract the build artifact and push it to the pages branch where it will
# automatically be deployed).

# TODO: rewrite the comment and clarify

# TODO: use commit hashes for actions

# TODO: the publish job should run sequentially so that it does proper version switcher generation?

name: Docs - preview build

on:
- pull_request

# TODO: trailing whitespace

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: Install uv
uses: astral-sh/setup-uv@2e657c127d5b1635d5a8e3fa40e0ac50a5bf6992

- name: Build the docs
# Intentionally without --strict, to have previews even if the docs are
# mildly broken
run: uv run mkdocs build

- uses: actions/upload-artifact@v4
with:
name: rendered-docs
path: rendered-docs

# TODO: this should indicate forks in the name, maybe? PR numbers are
# unique but pr_branch is not I suppose
- name: Generate meta.json
env:
PR_NUMBER: ${{ github.event.number }}
PR_BRANCH: ${{ github.head_ref }}
run: |
echo "{\"pr_number\": \"$PR_NUMBER\", \"pr_branch\": \"$PR_BRANCH\"}" > meta.json

- uses: actions/upload-artifact@v4
with:
name: meta.json
path: meta.json
67 changes: 67 additions & 0 deletions .github/workflows/docs-preview-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Docs - preview deploy

permissions:
contents: write
pull-requests: write

on:
workflow_run:
workflows:
- "Docs - preview build"
types:
- completed

# Since we use single-commit and force on the deploy action, only one deploy action can run at a time.
concurrency:
group: preview_deploy

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: 'Download build artifact'
uses: actions/download-artifact@v4
with:
name: rendered-docs
path: rendered-docs
# TODO: what token is that?
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: 'Download build meta'
uses: actions/download-artifact@v4
with:
name: meta.json
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: Parse meta.json
run: |
echo "PR_NUMBER=$(jq -r .pr_number meta.json)" >> $GITHUB_ENV
echo "PR_BRANCH=$(jq -r .pr_branch meta.json)" >> $GITHUB_ENV

- name: Url slug variable
run: |
echo "URL_SLUG=${{ env.PR_NUMBER }}-${{ env.PR_BRANCH }}" >> $GITHUB_ENV

# TODO: this is where we have to use mike? but for now it's fine not to have it
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: rendered-docs
repository-name: neongreen/jj-pr-preview # TODO: change
branch: 'main'
clean: true
target-folder: ${{ env.URL_SLUG }}
ssh-key: ${{ secrets.DEPLOY_KEY }}
commit-message: "Update preview for PR ${{ env.URL_SLUG }}"
single-commit: true

- name: Comment on the PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Docs preview is available at https://neongreen.github.io/jj-pr-preview/${{ env.URL_SLUG }}.
pr_number: ${{ env.PR_NUMBER }}
comment_tag: 'docs-preview'
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: 3.11
- name: Install poetry
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd
- name: Install uv
uses: astral-sh/setup-uv@2e657c127d5b1635d5a8e3fa40e0ac50a5bf6992
with:
poetry-version: latest
version: "0.5.1"
- name: Install dependencies, compile and deploy docs
run: |
git config user.name 'jj-docs[bot]'
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ jobs:
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: 3.11
- name: Install poetry
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd
- name: Install uv
uses: astral-sh/setup-uv@2e657c127d5b1635d5a8e3fa40e0ac50a5bf6992
with:
poetry-version: latest
version: "0.5.1"
- name: Compile docs and zip them up
run: |
poetry install
poetry run -- mkdocs build -f mkdocs-offline.yml
uv sync
uv run -- mkdocs build -f mkdocs-offline.yml
archive="jj-${{ github.event.release.tag_name }}-docs-html.tar.gz"
tar czf "$archive" -C "rendered-docs" .
echo "ASSET=$archive" >> $GITHUB_ENV
Expand All @@ -132,10 +132,10 @@ jobs:
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: 3.11
- name: Install poetry
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd
- name: Install uv
uses: astral-sh/setup-uv@2e657c127d5b1635d5a8e3fa40e0ac50a5bf6992
with:
poetry-version: latest
version: "0.5.1"
- name: Install dependencies, compile and deploy docs to the "latest release" section of the website
run: |
git config user.name 'jj-docs[bot]'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ result
*.snap*
!cli/tests/[email protected]

# mkdocs
/.venv

# Editor specific ignores
.idea

Expand Down
40 changes: 11 additions & 29 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,15 @@ result will look as expected when published to the website.

### Setting up the prerequisites

To build the website, you must have Python and `poetry 1.8+` installed (the
latest version is recommended). It is easiest to install `poetry` via `pipx`, as
explained in the [Poetry installation instructions]. A few helpful points from
the instructions: `pipx` can often be installed from your distribution, e.g.
`sudo apt install pipx`; this will usually also install Python for you if
necessary. Any version of `pipx` will do. If you are installing `pipx` manually,
you may first need to follow the [Python installation instructions].

[Python installation instructions]: https://docs.python.org/3/using/index.html
[Poetry installation instructions]: https://python-poetry.org/docs/#installation

Once you have `poetry` installed, you should ask it to install the rest
of the required tools into a virtual environment as follows:
To build the website, you must have `uv` installed. Please see: [Installing uv].

```shell
poetry install
```
[Installing uv]: https://docs.astral.sh/uv/getting-started/installation/

You may get requests to "unlock a keyring", [an error messages about failing to
do so](https://github.com/python-poetry/poetry/issues/1917), or Poetry may
[simply hang indefinitely](https://github.com/python-poetry/poetry/issues/8623).
The workaround is to either to unlock the keyring or to run the following, and
then to try `poetry install` again:
Once you have `uv` installed, you should ask it to install the rest
of the required tools into a virtual environment as follows:

```shell
# For sh-compatible shells or recent versions of `fish`
export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring
uv sync
```

### Building the HTML docs locally (with live reload)
Expand All @@ -264,15 +246,15 @@ following the above steps, you should be able to view the docs by running
```shell
# Note: this and all the commands below should be run from the root of
# the `jj` source tree.
poetry run -- mkdocs serve
uv run mkdocs serve
```

and opening <http://127.0.0.1:8000> in your browser.

As you edit the `md` files, the website should be rebuilt and reloaded in your
browser automatically, unless build errors occur.

You should occasionally check the terminal from which you ran `mkdocs serve` for
You should occasionally check the terminal from which you ran `uv run mkdocs serve` for
any build errors or warnings. Warnings about `"GET /versions.json HTTP/1.1" code
404` are expected and harmless.

Expand All @@ -286,7 +268,7 @@ the docs for the last stable version.

The different versions of documentation are managed and deployed with
[`mike`](https://github.com/jimporter/mike), which can be run with
`poetry run -- mike`.
`uv run mike`.

On a POSIX system or WSL, one way to build the entire website is as follows (on
Windows, you'll need to understand and adapt the shell script):
Expand Down Expand Up @@ -347,11 +329,11 @@ The script sets up the `site_url` mkdocs config to
where you loaded the website, some minor website features (like the
version switching widget) will have reduced functionality.

Then, the script passes the rest of its arguments to `potery run -- mike
deploy`, which does the rest of the job. Run `poetry run -- mike help deploy` to
Then, the script passes the rest of its arguments to `uv run mike
deploy`, which does the rest of the job. Run `uv run mike help deploy` to
find out what the arguments do.

If you need to do something more complicated, you can use `poetry run -- mike
If you need to do something more complicated, you can use `uv run mike
...` commands. You can also edit the `gh-pages` bookmark directly, but take care
to avoid files that will be overwritten by future invocations of `mike`. Then,
you can submit a PR based on the `gh-pages` bookmark of
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
openssh

# For building the documentation website
poetry
uv
] ++ darwinDeps ++ linuxNativeDeps;

shellHook = ''
Expand Down
2 changes: 1 addition & 1 deletion mkdocs-offline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This config is good if you plan to use the rendered docs from
# your file system. To use, run:
# poetry run -- mkdocs build -f mkdocs-offline.yml
# uv run mkdocs build -f mkdocs-offline.yml
INHERIT: 'mkdocs.yml'
plugins:
- offline
Expand Down
Loading