Gate gh-pages deployment to push-to-master only#6
Merged
Conversation
Agent-Logs-Url: https://github.com/FerreolS/InverseProblemsCookbook/sessions/99e5e942-df69-4048-a567-935bbcdc522c Co-authored-by: FerreolS <10050083+FerreolS@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Prevent gh-pages deployment on pull_request events
Gate gh-pages deployment to push-to-master only
Apr 30, 2026
Agent-Logs-Url: https://github.com/FerreolS/InverseProblemsCookbook/sessions/99f2ddad-1f68-4690-99d2-557f5d50ce3c Co-authored-by: FerreolS <10050083+FerreolS@users.noreply.github.com>
FerreolS
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
permissions: contents: writeto thebuildjob so the token can push togh-pageson push eventsgithub.event_name == 'push' && github.ref == 'refs/heads/master' && github.actor != 'dependabot[bot]') — no changes needed thereOriginal prompt
Create a pull request that prevents deployments to
gh-pagesfrom running on pull_request events. Specifically, in.github/workflows/main.yml, keep the LaTeX build and pdf2svg steps running for both pushes and PRs, but gate thepeaceiris/actions-gh-pages@v3step so it only runs on push events to themasterbranch (and also skip whengithub.actorisdependabot[bot]).Repository: FerreolS/InverseProblemsCookbook
PR context: Existing PR #4 fails because the workflow tries to push to
gh-pagesduring a pull_request run and gets a 403.Acceptance criteria:
actions-gh-pagesdeploy step does not run on pull_request.master.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for failing job 73769684955. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The job isn’t failing in the LaTeX build step; it’s failing when trying to publish the generated PDFs/SVGs to the
gh-pagesbranch:remote: Permission to FerreolS/InverseProblemsCookbook.git denied to github-actions[bot].fatal: ... returned error: 403This happens because the workflow/job does not grant the required repository permissions for the token used by the Pages publish action, so the push to
gh-pagesis rejected.Fix: grant
contents: write(and Pages permissions if you use GitHub Pages) to the build jobEdit
.github/workflows/main.yml(refb0fd7ec...), and add explicit permissions for thebuildjob (or at workflow top-level). Minimal fix for pushing togh-pages:If your repo uses the newer GitHub Pages deployment permissions
Some configurations also require these additional permissions (safe to include if you’re unsure):
You can place
permissions:at the workflow level (top of the file) or per job; per-job is fine here.Optional cleanup (not required, but improves reliability)
git remote rm originfailing with “No such remote: 'origin'” is coming from the publish action’s internal setup and is not the root cause. The real failure is the 403 permission denial; once permissions are fixed, the publish should succeed.After adding
permissions: contents: writeto thebuildjob, the action should be able to push togh-pagesand the job should pass.User: PR shouldn't deploy on gh-papges
Assistant: Don’t grant push permissions on PRs. Instead, skip the
actions-gh-pagesdeploy step unless the event is a push tomaster(and optionally also skip when actor is Dependabot).In your workflow (
.github/workflows/main.ymlat refb0fd7ec887dadd4a26a038ede17d3da164bcbcb8), change the deploy step to be conditional:Why this fixes PR #4:
pull_requestwhere the token typically must not be allowed to push to your repo/gh-pages.if:guard, the job can still build/convert PDFs for PR validation, but deployment won’t run (so no 403 failure).If you still want artifacts from PRs, add an
actions/upload-artifactstep (separate from deployment).User: make a PR to do that
Assistant: I’ve kicked off the PR creation, but I need you to acce...
This pull request was created from Copilot chat.