|
24 | 24 | permissions: |
25 | 25 | contents: write |
26 | 26 |
|
27 | | -# Every run rewrites gh-pages and then uploads the whole tree, so run them |
28 | | -# one at a time to avoid racing mike or publishing a stale snapshot. |
29 | | -concurrency: |
30 | | - group: publish-versioned-docs |
31 | | - cancel-in-progress: false |
32 | | - |
33 | 27 | jobs: |
34 | 28 | publish: |
35 | 29 | runs-on: ubuntu-latest |
36 | 30 |
|
| 31 | + # One group per branch. GitHub keeps at most one pending run per group |
| 32 | + # and cancels older pending ones, which is harmless here: the newest |
| 33 | + # push to a branch already contains the older ones. Different branches |
| 34 | + # publish in parallel and retry if another one updates gh-pages first. |
| 35 | + concurrency: |
| 36 | + group: publish-versioned-docs-${{ github.ref_name }} |
| 37 | + cancel-in-progress: false |
| 38 | + |
37 | 39 | steps: |
38 | 40 | - name: Check out source |
39 | 41 | uses: actions/checkout@v7 |
@@ -98,17 +100,45 @@ jobs: |
98 | 100 | env: |
99 | 101 | # "Edit this page" should open the branch this version is built from. |
100 | 102 | DOCS_EDIT_URI: edit/${{ github.ref_name }}/website/md-docs/ |
101 | | - run: uv run mike deploy --push --update-aliases --title "${{ steps.version.outputs.title }}" ${{ steps.version.outputs.aliases }} |
| 103 | + IS_LATEST: ${{ steps.version.outputs.is_latest }} |
| 104 | + run: | |
| 105 | + # Other branches may push to gh-pages while this one builds. mike's |
| 106 | + # push is then rejected as non-fast-forward, so rebuild on top of |
| 107 | + # the new tip and try again. |
| 108 | + for attempt in 1 2 3 4 5; do |
| 109 | + git fetch origin gh-pages |
| 110 | + git branch -f gh-pages origin/gh-pages |
| 111 | + if uv run mike deploy --push --update-aliases --title "${{ steps.version.outputs.title }}" ${{ steps.version.outputs.aliases }} \ |
| 112 | + && { [[ "${IS_LATEST}" != "true" ]] || uv run mike set-default --push latest; }; then |
| 113 | + exit 0 |
| 114 | + fi |
| 115 | + echo "gh-pages push failed (attempt ${attempt}), retrying" >&2 |
| 116 | + sleep $((attempt * 10)) |
| 117 | + done |
| 118 | + exit 1 |
| 119 | +
|
| 120 | + deploy: |
| 121 | + needs: publish |
| 122 | + runs-on: ubuntu-latest |
102 | 123 |
|
103 | | - - name: Set default docs version |
104 | | - if: steps.version.outputs.is_latest == 'true' |
105 | | - run: uv run mike set-default --push latest |
| 124 | + # One group across all branches, so uploads never overlap. If several |
| 125 | + # are queued, GitHub keeps only the newest; that's fine because it |
| 126 | + # exports gh-pages when it starts, which already includes every |
| 127 | + # earlier publish. The last upload is therefore always the newest tree. |
| 128 | + concurrency: |
| 129 | + group: publish-versioned-docs-cloudflare |
| 130 | + cancel-in-progress: false |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Check out source |
| 134 | + uses: actions/checkout@v7 |
106 | 135 |
|
107 | 136 | - name: Export gh-pages tree for Cloudflare |
108 | 137 | run: | |
| 138 | + git fetch --depth 1 origin gh-pages |
109 | 139 | rm -rf .site-publish |
110 | 140 | mkdir .site-publish |
111 | | - git archive gh-pages | tar -x -C .site-publish |
| 141 | + git archive FETCH_HEAD | tar -x -C .site-publish |
112 | 142 |
|
113 | 143 | - name: Deploy to Cloudflare Workers |
114 | 144 | uses: cloudflare/wrangler-action@v4 |
|
0 commit comments