You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by "jamesfredley (via GitHub)" <gi...@apache.org> on 2026/09/03 01:14:19 UTC
[PR] Retry publishMainSite on concurrent asf-site-production pushes [grails-static-website]
jamesfredley opened a new pull request, #541:
URL: https://github.com/apache/grails-static-website/pull/541
## Why not deploy-github-pages (grails-github-actions#110)
`apache/grails-github-actions` `deploy-github-pages` (the action from PR #110, used by grails-core in apache/grails-core#16110) is **not a drop-in replacement** for this repo's publish:
- It publishes under `docs/<snapshot|version>`, not the site root.
- Staging uses `git add $path/*`, so root `.htaccess` and `.well-known` are skipped.
- A root-level copy would delete grails-core's `docs/` tree on `apache/grails-website` `asf-site-production`.
- Two sequential action runs (site then docs) are racy: each clones, commits, and pushes independently.
This site still uses `:publishMainSite` (PAT clone/push of `build/dist/` onto the deploy branch).
## What this PR does
Ports the #110 retry into `publishMainSite`: on porcelain `non-fast-forward` / `fetch first`, fetch, require the new tip to descend from the cloned tip, rebase the unpublished commit, retry up to 5 times. No force-push. Rewritten history and rebase conflicts fail closed.
## Secrets and permissions
- Still uses `secrets.GRAILS_GHTOKEN` (`GH_TOKEN`) to push to `apache/grails-website`. `GITHUB_TOKEN` cannot write that other repo.
- Workflow `permissions.contents` is `read` (this job does not push this repo).
- Unchanged: `if: github.repository == 'apache/grails-static-website'`, `GH_BRANCH: asf-site-production`.
- Intra-repo overlap is still serialized with `concurrency` `cancel-in-progress: false`. Cross-repo races vs grails-core are handled by the rebase retry.
## Tests
`PublishMainSiteTaskSpec`: first push, disjoint rebase keeps both trees, conflict aborts, unrelated failures are not retried, rewritten history fails closed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Retry publishMainSite on concurrent asf-site-production pushes [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley merged PR #541:
URL: https://github.com/apache/grails-static-website/pull/541
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Retry publishMainSite on concurrent asf-site-production pushes [grails-static-website]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #541:
URL: https://github.com/apache/grails-static-website/pull/541#discussion_r3920155923
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
Review Comment:
The raw `git push` output is logged verbatim. Since the push URL includes an embedded OAuth token, some git errors can echo the full URL and leak the secret into build logs. Please redact credentials before logging (or avoid logging full output at lifecycle level).
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
+ if (exit == 0) {
+ logger.lifecycle('Deployment successful!')
+ return
+ }
+ boolean retryable = retryablePushRejection(output)
+ if (!retryable) {
+ throw new GradleException('Push failed without a retryable non-fast-forward rejection.')
+ }
+ if (attempt == MAX_PUSH_ATTEMPTS) {
+ throw new GradleException("Push failed after ${MAX_PUSH_ATTEMPTS} attempts.")
+ }
+ logger.lifecycle('Push rejected by a concurrent publisher, rebasing and retrying...')
+ if (!Boolean.getBoolean('website.publish.skipRetryBackoff')) {
+ int backoffSeconds = 1 << (attempt - 1)
+ Thread.sleep((backoffSeconds + new Random().nextInt(backoffSeconds + 1)) * 1000L)
+ }
+ runGit(deployRoot, 'fetch', '--no-tags', pushUrl, "refs/heads/${branch}")
+ String newRemoteTip = captureGit(deployRoot, 'rev-parse', 'FETCH_HEAD')
+ ByteArrayOutputStream ancestorOut = new ByteArrayOutputStream()
+ int ancestorExit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', 'merge-base', '--is-ancestor', observedTip, newRemoteTip]
Review Comment:
This `git merge-base` invocation doesn't disable hooks, while other git commands in this task explicitly pass `-c core.hooksPath=`. For consistency and to avoid any unexpected `core.hooksPath` global config affecting CI, include the same flag here.
This issue also appears in the following locations of the same file:
- line 309
- line 315
##########
buildSrc/src/test/groovy/website/gradle/tasks/PublishMainSiteTaskSpec.groovy:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package website.gradle.tasks
+
+import org.gradle.api.GradleException
+import org.gradle.testfixtures.ProjectBuilder
+
+import spock.lang.Specification
+import spock.lang.TempDir
+
+class PublishMainSiteTaskSpec extends Specification {
+
+ @TempDir
+ File tempDir
+
+ def setupSpec() {
+ System.setProperty('website.publish.skipRetryBackoff', 'true')
+ }
Review Comment:
`setupSpec` sets a JVM-wide system property but never restores it. That can leak into other buildSrc tests in the same JVM and change behavior unexpectedly. Capture the prior value and restore/clear it in `cleanupSpec`.
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
+ if (exit == 0) {
+ logger.lifecycle('Deployment successful!')
+ return
+ }
+ boolean retryable = retryablePushRejection(output)
+ if (!retryable) {
+ throw new GradleException('Push failed without a retryable non-fast-forward rejection.')
+ }
+ if (attempt == MAX_PUSH_ATTEMPTS) {
+ throw new GradleException("Push failed after ${MAX_PUSH_ATTEMPTS} attempts.")
+ }
+ logger.lifecycle('Push rejected by a concurrent publisher, rebasing and retrying...')
+ if (!Boolean.getBoolean('website.publish.skipRetryBackoff')) {
+ int backoffSeconds = 1 << (attempt - 1)
+ Thread.sleep((backoffSeconds + new Random().nextInt(backoffSeconds + 1)) * 1000L)
+ }
+ runGit(deployRoot, 'fetch', '--no-tags', pushUrl, "refs/heads/${branch}")
+ String newRemoteTip = captureGit(deployRoot, 'rev-parse', 'FETCH_HEAD')
+ ByteArrayOutputStream ancestorOut = new ByteArrayOutputStream()
+ int ancestorExit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', 'merge-base', '--is-ancestor', observedTip, newRemoteTip]
+ spec.standardOutput = ancestorOut
+ spec.errorOutput = ancestorOut
+ spec.ignoreExitValue = true
+ }.exitValue
+ if (newRemoteTip == observedTip || ancestorExit != 0) {
+ throw new GradleException('Concurrent documentation branch update is not a descendant of the observed remote tip.')
Review Comment:
This failure message hard-codes "documentation" but the concurrent update could be from any publisher (site or docs). Also, including the observed/new tips makes diagnosing rewritten history vs race conditions much easier.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Retry publishMainSite on concurrent asf-site-production pushes [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #541:
URL: https://github.com/apache/grails-static-website/pull/541#discussion_r3920274864
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
+ if (exit == 0) {
+ logger.lifecycle('Deployment successful!')
+ return
+ }
+ boolean retryable = retryablePushRejection(output)
+ if (!retryable) {
+ throw new GradleException('Push failed without a retryable non-fast-forward rejection.')
+ }
+ if (attempt == MAX_PUSH_ATTEMPTS) {
+ throw new GradleException("Push failed after ${MAX_PUSH_ATTEMPTS} attempts.")
+ }
+ logger.lifecycle('Push rejected by a concurrent publisher, rebasing and retrying...')
+ if (!Boolean.getBoolean('website.publish.skipRetryBackoff')) {
+ int backoffSeconds = 1 << (attempt - 1)
+ Thread.sleep((backoffSeconds + new Random().nextInt(backoffSeconds + 1)) * 1000L)
+ }
+ runGit(deployRoot, 'fetch', '--no-tags', pushUrl, "refs/heads/${branch}")
+ String newRemoteTip = captureGit(deployRoot, 'rev-parse', 'FETCH_HEAD')
+ ByteArrayOutputStream ancestorOut = new ByteArrayOutputStream()
+ int ancestorExit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', 'merge-base', '--is-ancestor', observedTip, newRemoteTip]
Review Comment:
Fixed in 0424196bd3. `merge-base --is-ancestor`, `rebase --onto`, and `rebase --abort` now all pass `-c core.hooksPath=` like the other git invocations in this task.
##########
buildSrc/src/test/groovy/website/gradle/tasks/PublishMainSiteTaskSpec.groovy:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package website.gradle.tasks
+
+import org.gradle.api.GradleException
+import org.gradle.testfixtures.ProjectBuilder
+
+import spock.lang.Specification
+import spock.lang.TempDir
+
+class PublishMainSiteTaskSpec extends Specification {
+
+ @TempDir
+ File tempDir
+
+ def setupSpec() {
+ System.setProperty('website.publish.skipRetryBackoff', 'true')
+ }
Review Comment:
Fixed in 0424196bd3. `setupSpec` captures the previous `website.publish.skipRetryBackoff` value and `cleanupSpec` restores or clears it so the property does not leak into other buildSrc tests.
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
Review Comment:
Fixed in 0424196bd3. Push output is run through `redactAuthenticatedUrls` before `logger.lifecycle`, so `https://oauth2:token@host` becomes `https://***@host`. Covered by `redactAuthenticatedUrls masks credentials in git output`.
##########
buildSrc/src/main/groovy/website/gradle/tasks/PublishMainSiteTask.groovy:
##########
@@ -233,17 +236,93 @@ abstract class PublishMainSiteTask extends DefaultTask {
return
}
- // 6. Commit + push.
+ // 6. Commit + push. Retry genuine non-fast-forward races the same way
+ // apache/grails-github-actions#110 does for deploy-github-pages: fetch
+ // the new tip, require it to descend from the tip we cloned, rebase
+ // the unpublished local commit, and push again. Never force-push.
+ // deploy-github-pages itself is not a drop-in here: it publishes into
+ // docs/<snapshot|version>, and `git add $path/*` skips root .htaccess
+ // and .well-known.
+ String lastRemoteTip = captureGit(deployRoot, 'rev-parse', 'HEAD')
String commitMessage = "Updating ${slug} ${branch} branch for GitHub Actions run:${run}"
runGit(deployRoot, 'commit', '-m', commitMessage)
- // Re-use the credential-bearing URL so this push does not depend on
- // any global git credential helper state.
String pushUrl = "https://oauth2:${token}@github.com/${slug}.git"
- runGit(deployRoot, 'push', pushUrl, branch)
+ pushWithRetry(deployRoot, pushUrl, branch, lastRemoteTip)
+ }
+
+ private static final int MAX_PUSH_ATTEMPTS = 5
+
+ static boolean retryablePushRejection(String output) {
+ output.readLines().any { String line ->
+ line ==~ /^!\t.*\t\[rejected\] \((non-fast-forward|fetch first)\)$/
+ }
+ }
+
+ void pushWithRetry(File deployRoot, String pushUrl, String branch, String lastRemoteTip) {
+ String observedTip = lastRemoteTip
+ for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+ logger.lifecycle("Push attempt ${attempt}/${MAX_PUSH_ATTEMPTS}")
+ ByteArrayOutputStream combined = new ByteArrayOutputStream()
+ int exit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', '-c', 'core.hooksPath=', 'push', '--porcelain', pushUrl, "HEAD:refs/heads/${branch}".toString()]
+ spec.environment('LC_ALL', 'C')
+ spec.standardOutput = combined
+ spec.errorOutput = combined
+ spec.ignoreExitValue = true
+ }.exitValue
+ String output = new String(combined.toByteArray(), 'UTF-8')
+ if (!output.empty) {
+ logger.lifecycle(output)
+ }
+ if (exit == 0) {
+ logger.lifecycle('Deployment successful!')
+ return
+ }
+ boolean retryable = retryablePushRejection(output)
+ if (!retryable) {
+ throw new GradleException('Push failed without a retryable non-fast-forward rejection.')
+ }
+ if (attempt == MAX_PUSH_ATTEMPTS) {
+ throw new GradleException("Push failed after ${MAX_PUSH_ATTEMPTS} attempts.")
+ }
+ logger.lifecycle('Push rejected by a concurrent publisher, rebasing and retrying...')
+ if (!Boolean.getBoolean('website.publish.skipRetryBackoff')) {
+ int backoffSeconds = 1 << (attempt - 1)
+ Thread.sleep((backoffSeconds + new Random().nextInt(backoffSeconds + 1)) * 1000L)
+ }
+ runGit(deployRoot, 'fetch', '--no-tags', pushUrl, "refs/heads/${branch}")
+ String newRemoteTip = captureGit(deployRoot, 'rev-parse', 'FETCH_HEAD')
+ ByteArrayOutputStream ancestorOut = new ByteArrayOutputStream()
+ int ancestorExit = exec.exec { spec ->
+ spec.workingDir = deployRoot
+ spec.commandLine = ['git', 'merge-base', '--is-ancestor', observedTip, newRemoteTip]
+ spec.standardOutput = ancestorOut
+ spec.errorOutput = ancestorOut
+ spec.ignoreExitValue = true
+ }.exitValue
+ if (newRemoteTip == observedTip || ancestorExit != 0) {
+ throw new GradleException('Concurrent documentation branch update is not a descendant of the observed remote tip.')
Review Comment:
Fixed in 0424196bd3. The message no longer says "documentation" and includes both the observed tip and the new remote tip.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org