diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2e6f2c5 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,53 @@ +name: Publish + +on: + release: + types: [ published ] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: '7.1' + arguments: build -x test -x ktlintKotlinScriptCheck -x ktlintTestSourceSetCheck -x ktlintMainSourceSetCheck + - name: Cleanup Gradle Cache + # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. + # Restoring these files from a GitHub Actions cache might cause problems for future builds. + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties + + - name: Test + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: '7.1' + arguments: test + + - name: Publish + uses: eskatos/gradle-command-action@v1 + with: + gradle-version: '7.1' + arguments: publish + env: + GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 866f09c..6040d45 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ on: - 'main' jobs: - Test: + test: runs-on: ubuntu-latest steps: diff --git a/build.gradle.kts b/build.gradle.kts index 1a54510..058f62b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { id("org.sonarqube") version "+" } -group "io.github.flecomte" +group = "io.github.flecomte" version = versioning.info.run { if (dirty) { versioning.info.full @@ -42,29 +42,33 @@ val sourcesJar by tasks.registering(Jar::class) { } publishing { - if (versioning.info.dirty == false) { - repositories { - maven { - name = "skilningur" - group = "io.github.flecomte" - url = uri("https://maven.pkg.github.com/flecomte/skilningur") - credentials { - username = System.getenv("GITHUB_USERNAME") - password = System.getenv("GITHUB_TOKEN") - } + repositories { + maven { + name = "access-control" + url = uri("https://maven.pkg.github.com/flecomte/access-control") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") } } - - publications { - create("skilningur") { - from(components["java"]) - artifact(sourcesJar) - } - } - } else { - org.slf4j.LoggerFactory.getLogger("gradle") - .error("The git is DIRTY (${versioning.info.full})") } + + publications { + create("access-control") { + from(components["java"]) + artifact(sourcesJar) + } + } +} + +tasks.withType().configureEach { + onlyIf { + versioning.info.run { + !dirty && tag != null && tag.matches("""[0-9]+\.[0-9]+\.[0-9]+""".toRegex()) + } + } + + dependsOn(tasks.test) } repositories {