Skip to content

Commit a4c9b6a

Browse files
Copilotm-aciek
andauthored
Switch scheduled Pages deployment from concurrent git pushes to single artifact-based deploy (#16)
* Initial plan * Switch scheduled workflow to artifact-based GitHub Pages deployment Replace concurrent gh-pages git pushes with the recommended Actions Pages pattern: build jobs run in parallel and upload artifacts, a single deploy job downloads all artifacts and publishes once via actions/configure-pages + actions/upload-pages-artifact + actions/deploy-pages. - schedule.yaml: set permissions (pages:write, id-token:write, contents:read), add concurrency group, pass publish:false to build jobs, add single deploy job - build.yaml: update permissions, replace git-push publish job with deploy-pages-based publish (for standalone workflow_dispatch use) Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/ef8d01ff-dbf0-4912-b4ea-425561a6b349 Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com> * Skip deploy job on push trigger Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/3a039646-7f76-4cf9-b6b4-cb675827b67a Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
1 parent 95628bc commit a4c9b6a

File tree

2 files changed

+106
-49
lines changed

2 files changed

+106
-49
lines changed

.github/workflows/build.yaml

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ on:
4545
default: '3'
4646
type: string
4747
permissions:
48-
contents: write
48+
contents: read
49+
pages: write
50+
id-token: write
4951
jobs:
5052
build-html:
5153
runs-on: ubuntu-latest
@@ -184,56 +186,46 @@ jobs:
184186
needs: [build-html, build-text, build-texinfo, build-epub, build-pdf]
185187
if: ${{ !cancelled() && inputs.publish == 'true' }}
186188
runs-on: ubuntu-latest
187-
concurrency:
188-
group: gh-pages-publish
189-
cancel-in-progress: false
189+
environment:
190+
name: github-pages
191+
url: ${{ steps.deployment.outputs.page_url }}
190192
steps:
191-
- name: Checkout gh-pages branch
193+
- name: Configure Pages
194+
uses: actions/configure-pages@v5
195+
196+
- name: Checkout existing gh-pages content
197+
id: checkout-pages
192198
uses: actions/checkout@v5
193199
with:
194200
ref: gh-pages
195-
path: gh-pages
196-
- name: Pull latest gh-pages
197-
run: git -C gh-pages pull --rebase origin gh-pages
201+
path: _site
202+
continue-on-error: true
203+
204+
- name: Prepare site directory
205+
run: |
206+
mkdir -p _site/3
207+
# Remove git metadata; safe even if checkout above did not succeed
208+
rm -rf _site/.git
209+
198210
- name: Download all artifacts
199-
uses: actions/download-artifact@master
211+
# Collect all build artifacts then merge into the publish directory
212+
uses: actions/download-artifact@v4
200213
with:
201-
path: artifacts
202-
- name: Copy generated archives to gh-pages
203-
run: |
204-
mkdir -p gh-pages/3
205-
# PDF
206-
cp artifacts/python-${{ inputs.dist_version }}-docs-pdf-a4.zip/* gh-pages/3/ 2>/dev/null || true
207-
cp artifacts/python-${{ inputs.dist_version }}-docs-pdf-a4.tar.bz2/* gh-pages/3/ 2>/dev/null || true
208-
# HTML
209-
cp artifacts/python-${{ inputs.dist_version }}-docs-html.zip/* gh-pages/3/ 2>/dev/null || true
210-
cp artifacts/python-${{ inputs.dist_version }}-docs-html.tar.bz2/* gh-pages/3/ 2>/dev/null || true
211-
# Text
212-
cp artifacts/python-${{ inputs.dist_version }}-docs-text.zip/* gh-pages/3/ 2>/dev/null || true
213-
cp artifacts/python-${{ inputs.dist_version }}-docs-text.tar.bz2/* gh-pages/3/ 2>/dev/null || true
214-
# Texinfo
215-
cp artifacts/python-${{ inputs.dist_version }}-docs-texinfo.zip/* gh-pages/3/ 2>/dev/null || true
216-
cp artifacts/python-${{ inputs.dist_version }}-docs-texinfo.tar.bz2/* gh-pages/3/ 2>/dev/null || true
217-
# EPUB
218-
cp artifacts/python-${{ inputs.dist_version }}-docs.epub/* gh-pages/3/ 2>/dev/null || true
219-
- name: Commit generated archives
220-
id: commit
214+
path: artifacts/
215+
216+
- name: Copy new archives into site directory
221217
run: |
222-
cd gh-pages
223-
git config user.name github-actions
224-
git config user.email github-actions@github.com
225-
git add 3/
226-
if git diff --cached --quiet; then
227-
echo "No documentation archives to commit"
228-
echo "has_changes=false" >> "$GITHUB_OUTPUT"
229-
else
230-
git commit -m "Update documentation archives for ${{ inputs.dist_version }}"
231-
echo "has_changes=true" >> "$GITHUB_OUTPUT"
232-
fi
233-
- name: Push commit
234-
if: steps.commit.outputs.has_changes == 'true'
235-
uses: ad-m/github-push-action@master
236-
with:
237-
branch: gh-pages
238-
github_token: ${{ secrets.GITHUB_TOKEN }}
239-
directory: gh-pages
218+
# Copy generated archives (zip, tar.bz2, epub) into _site/3/,
219+
# excluding PDF build logs which are for debugging only.
220+
find artifacts/ -type f \( -name "*.zip" -o -name "*.tar.bz2" -o -name "*.epub" \) \
221+
! -name "python-*-pdf-logs.zip" \
222+
-exec cp {} _site/3/ \;
223+
224+
- name: Upload Pages artifact
225+
uses: actions/upload-pages-artifact@v3
226+
with:
227+
path: _site
228+
229+
- name: Deploy to GitHub Pages
230+
id: deployment
231+
uses: actions/deploy-pages@v4

.github/workflows/schedule.yaml

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ on:
44
- cron: '0 5 * * *'
55
workflow_dispatch:
66
push:
7+
8+
# Pages deployment requires pages:write and id-token:write.
9+
# contents:write is no longer needed since we no longer push to gh-pages directly.
710
permissions:
8-
contents: write
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# Prevent overlapping scheduled runs from deploying to GitHub Pages simultaneously.
16+
concurrency:
17+
group: pages-${{ github.ref }}
18+
cancel-in-progress: false
19+
920
jobs:
1021
get-versions:
1122
runs-on: ubuntu-latest
@@ -24,9 +35,63 @@ jobs:
2435
fail-fast: false
2536
matrix:
2637
include: ${{ fromJson(needs.get-versions.outputs.versions) }}
38+
# Build jobs run concurrently and upload artifacts per version. The single
39+
# deploy job below collects all artifacts and publishes once, avoiding
40+
# concurrent git pushes/commit conflicts to gh-pages.
2741
uses: ./.github/workflows/build.yaml
2842
with:
2943
reference: ${{ matrix.branch }}
3044
dist_version: ${{ matrix.version }}
3145
python_version: ${{ matrix.python_version }}
32-
publish: ${{ 'true' }}
46+
publish: ${{ 'false' }}
47+
48+
deploy:
49+
# A single deploy job runs after all build matrix jobs complete.
50+
# Artifacts from every concurrent build job are merged here and published
51+
# once via actions/deploy-pages, eliminating concurrent gh-pages push conflicts.
52+
needs: build
53+
if: ${{ !cancelled() && needs.build.result != 'failure' && github.event_name != 'push' }}
54+
runs-on: ubuntu-latest
55+
environment:
56+
name: github-pages
57+
url: ${{ steps.deployment.outputs.page_url }}
58+
steps:
59+
- name: Configure Pages
60+
uses: actions/configure-pages@v5
61+
62+
- name: Checkout existing gh-pages content
63+
id: checkout-pages
64+
uses: actions/checkout@v5
65+
with:
66+
ref: gh-pages
67+
path: _site
68+
continue-on-error: true
69+
70+
- name: Prepare site directory
71+
run: |
72+
mkdir -p _site/3
73+
# Remove git metadata; safe even if checkout above did not succeed
74+
rm -rf _site/.git
75+
76+
- name: Download all build artifacts
77+
# Collect artifacts uploaded by all concurrent build matrix jobs
78+
uses: actions/download-artifact@v4
79+
with:
80+
path: artifacts/
81+
82+
- name: Copy new archives into site directory
83+
run: |
84+
# Copy generated archives (zip, tar.bz2, epub) into _site/3/,
85+
# excluding PDF build logs which are for debugging only.
86+
find artifacts/ -type f \( -name "*.zip" -o -name "*.tar.bz2" -o -name "*.epub" \) \
87+
! -name "python-*-pdf-logs.zip" \
88+
-exec cp {} _site/3/ \;
89+
90+
- name: Upload Pages artifact
91+
uses: actions/upload-pages-artifact@v3
92+
with:
93+
path: _site
94+
95+
- name: Deploy to GitHub Pages
96+
id: deployment
97+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)