@@ -39,8 +39,8 @@ class IncrementGuard : Plugin<Project> {
3939 *
4040 * Only adds the check if the project is built on Travis CI and the job is a pull request.
4141 *
42- * The task will never run outside of Travis CI or when building individual branches . This is
43- * done to prevent unexpected CI fails when re-building `master` multiple times, creating git
42+ * The task only runs on non-master branches on GitHub Actions . This is done
43+ * to prevent unexpected CI fails when re-building `master` multiple times, creating git
4444 * tags, and in other cases that go outside of the "usual" development cycle.
4545 */
4646 override fun apply (target : Project ) {
@@ -50,25 +50,33 @@ class IncrementGuard : Plugin<Project> {
5050 tasks.getByName(" check" ).dependsOn(this )
5151
5252 shouldRunAfter(" test" )
53- if (! isTravisPullRequest ()) {
54- logger.info(" The build does not represent a Travis pull request job, the " +
55- " `checkVersionIncrement` task is disabled." )
53+ if (! shouldCheckVersion ()) {
54+ logger.info(" The build does not represent a GitHub Actions feature branch job, " +
55+ " the `checkVersionIncrement` task is disabled." )
5656 this .enabled = false
5757 }
5858 }
5959 }
6060
6161 /* *
62- * Returns `true` if the current build is a Travis job which represents a GitHub pull request.
62+ * Returns `true` if the current build is a GitHub Actions build which represents a push
63+ * to a feature branch.
6364 *
64- * Implementation note: the `TRAVIS_PULL_REQUEST` environment variable contains the pull
65- * request number rather than `"true"` in positive case, hence the check.
65+ * Returns `false` if the associated reference is not a branch (e.g. a tag) or if it has
66+ * the name which ends with `master`. So, on branches such as `master` and `2.x-jdk8-master`
67+ * this method would return `false`.
6668 *
67- * @see <a href="https://docs.travis-ci .com/user/environment-variables/#default- environment-variables">
68- * List of default environment variables provided for Travis builds</a>
69+ * @see <a href="https://docs.github .com/en/free-pro-team@latest/actions/reference/ environment-variables">
70+ * List of default environment variables provided for GitHub Actions builds</a>
6971 */
70- private fun isTravisPullRequest (): Boolean {
71- val isPullRequest = System .getenv(" TRAVIS_PULL_REQUEST" )
72- return isPullRequest != null && isPullRequest != " false"
72+ private fun shouldCheckVersion (): Boolean {
73+ val eventName = System .getenv(" GITHUB_EVENT_NAME" )
74+ if (" push" != eventName) {
75+ return false
76+ }
77+ val reference = System .getenv(" GITHUB_REF" ) ? : return false
78+ val matches = Regex (" refs/heads/(.+)" ).matchEntire(reference) ? : return false
79+ val branch = matches.groupValues[1 ]
80+ return ! branch.endsWith(" master" )
7381 }
7482}
0 commit comments