Skip to content

Commit eacfb48

Browse files
committed
build on all branches, but don't publish on all
1 parent 9a52088 commit eacfb48

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: Java CI with Maven
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ '*' ]
6+
tags: [ '*' ]
67
pull_request:
78
branches: [ master ]
89
workflow_dispatch:
@@ -24,7 +25,7 @@ jobs:
2425
- name: Setup Gradle
2526
uses: gradle/actions/setup-gradle@v5
2627
- name: Build
27-
run: ./gradlew --no-configuration-cache --no-parallel mavenCentralDeploy
28+
run: ./gradlew --no-configuration-cache --no-parallel githubActions
2829
env:
2930
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
3031
ORG_GRADLE_PROJECT_mavenCentralSnapshotsUsername: ${{ secrets.SONATYPE_USERNAME }}

build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,21 @@ val mavenCentralDeploy by tasks.registering(DefaultTask::class) {
114114
}
115115
}
116116
}
117+
118+
val githubActions by tasks.registering(DefaultTask::class) {
119+
group = "publishing"
120+
val deployRefPattern = """^refs/(?:tags/javacan-\d+.\d+.\d+|heads/master)$""".toRegex()
121+
val ref = System.getenv("GITHUB_REF")?.ifBlank { null }?.trim()
122+
123+
if (ref != null && deployRefPattern.matches(ref)) {
124+
logger.lifecycle("Job in $ref will deploy!")
125+
dependsOn(mavenCentralDeploy)
126+
} else {
127+
logger.lifecycle("Job will only build!")
128+
for (project in allprojects) {
129+
project.tasks.findByName("assemble")?.let {
130+
dependsOn(it)
131+
}
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)