Add publish in CI

This commit is contained in:
2021-06-29 22:55:14 +02:00
parent ce55c58430
commit e4be8b90fe
3 changed files with 79 additions and 22 deletions

53
.github/workflows/publish.yml vendored Normal file
View File

@@ -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 }}

View File

@@ -9,7 +9,7 @@ on:
- 'main'
jobs:
Test:
test:
runs-on: ubuntu-latest
steps:

View File

@@ -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")
name = "access-control"
url = uri("https://maven.pkg.github.com/flecomte/access-control")
credentials {
username = System.getenv("GITHUB_USERNAME")
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
create<MavenPublication>("skilningur") {
create<MavenPublication>("access-control") {
from(components["java"])
artifact(sourcesJar)
}
}
} else {
org.slf4j.LoggerFactory.getLogger("gradle")
.error("The git is DIRTY (${versioning.info.full})")
}
tasks.withType<PublishToMavenRepository>().configureEach {
onlyIf {
versioning.info.run {
!dirty && tag != null && tag.matches("""[0-9]+\.[0-9]+\.[0-9]+""".toRegex())
}
}
dependsOn(tasks.test)
}
repositories {