Skip to content

Conversation

@alex000kim
Copy link
Contributor

Add support for building docs previews from fork PRs.

I tested this locally with act:

act issue_comment -e test-event.json \
  --container-architecture linux/amd64 \
  -s GITHUB_TOKEN="$GITHUB_TOKEN" \
  -s READTHEDOCS_TOKEN="$READTHEDOCS_TOKEN" \
  -s READTHEDOCS_PROJECT="$READTHEDOCS_PROJECT" \
  --var AUTHORIZED_RTD_BUILDERS="alex000kim"

INFO[0000] Using docker host 'unix:///Users/akim/.docker/run/docker.sock', and daemon socket 'unix:///Users/akim/.docker/run/docker.sock' 
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Set up job
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] 🚀  Start image=catthehacker/ubuntu:act-latest
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker create image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker run image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Set up job
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ☁  git clone 'https://github.com/actions/github-script' # ref=v7
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ☁  git clone 'https://github.com/actions/github-script' # ref=v7
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ☁  git clone 'https://github.com/actions/github-script' # ref=v7
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ☁  git clone 'https://github.com/actions/github-script' # ref=v7
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Main Check authorization
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker cp src=/Users/akim/.cache/act/actions-github-script@v7/ dst=/var/run/act/actions/actions-github-script@v7/
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.8/x64/bin/node /var/run/act/actions/actions-github-script@v7/dist/index.js] user= workdir=
| ✅ User alex000kim is authorized to trigger builds
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Main Check authorization [785.896458ms]
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ⚙  ::set-output:: result=true
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Main Get PR details
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker cp src=/Users/akim/.cache/act/actions-github-script@v7/ dst=/var/run/act/actions/actions-github-script@v7/
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.8/x64/bin/node /var/run/act/actions/actions-github-script@v7/dist/index.js] user= workdir=
| PR details: {
|   "branch": "readthedocs-handle-forked-prs",
|   "isFork": false,
|   "forkOwner": "alex000kim",
|   "forkRepo": "skypilot",
|   "prNumber": 1
| }
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Main Get PR details [1.24257275s]
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ⚙  ::set-output:: result={"branch":"readthedocs-handle-forked-prs","isFork":false,"forkOwner":"alex000kim","forkRepo":"skypilot","prNumber":1}
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Main Trigger ReadTheDocs build
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker exec cmd=[bash -e /var/run/act/workflow/4] user= workdir=
| Triggering ReadTheDocs build for project: ***, branch: readthedocs-handle-forked-prs
| Activating and configuring version for branch: readthedocs-handle-forked-prs
| ✅ Version activated and configured successfully
| Triggering build...
| ✅ ReadTheDocs build triggered successfully!
...
...
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Main Trigger ReadTheDocs build [994.531083ms]
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Main Add label and comment on PR
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker cp src=/Users/akim/.cache/act/actions-github-script@v7/ dst=/var/run/act/actions/actions-github-script@v7/
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   🐳  docker exec cmd=[/opt/acttoolcache/node/18.20.8/x64/bin/node /var/run/act/actions/actions-github-script@v7/dist/index.js] user= workdir=
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Main Add label and comment on PR [2.063389875s]
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ⚙  ::set-output:: result=
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] ⭐ Run Complete job
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] Cleaning up container for job trigger-rtd-build
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ]   ✅  Success - Complete job
[Manual ReadTheDocs Build on PR/trigger-rtd-build  ] 🏁  Job succeeded

test-event.json

@gemini-code-assist
Copy link
Contributor

Note

Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported.

Comment on lines +98 to +107
# Add fork as remote and fetch the branch
git remote add fork "https://github.com/${FORK_OWNER}/${FORK_REPO}.git"
git fetch fork "${BRANCH}"
# Push to main repo with the same branch name
# This makes the branch available for ReadTheDocs to sync
echo "Pushing branch '${BRANCH}' to main repository..."
git push origin "fork/${BRANCH}:refs/heads/${BRANCH}" --force
echo "✅ Fork branch pushed to main repository successfully"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit unsecure, and the two branches could be out of sync without calling the /build-docs again. Would there be a way to just have the rtd to be able to clone from a fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think do to this properly, you'd need to enabled the "Build pull requests for this project" option as per https://docs.readthedocs.com/platform/stable/guides/pull-requests.html#how-to-configure-pull-request-builds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants