Skip to content

Commit

Permalink
GitHub Actions and Gradle for Publishing Snapshot and Release (#1)
Browse files Browse the repository at this point in the history
* publish, lint and test

* rm println

* rerun-tasks

* Update publish-release.yml

* get authToken in gradle
  • Loading branch information
davin111 authored Feb 6, 2023
1 parent 0f13e61 commit 1262c7d
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Run Lint
run: |
./gradlew clean ktlintCheck
36 changes: 36 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish

on:
release:
types: [ published ]

jobs:
deploy:
name: Publish
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Publish release
run: |
./gradlew clean publish -Pversion=${{ github.event.release.tag_name }}
- name: Update snapshot version
run: |
./gradlew updateVersion -PreleaseVersion=${{ github.event.release.tag_name }} --rerun-tasks
- name: Commit gradle.properties
run: |
git config --global user.name 'truffle-kotlin'
git config --global user.email '[email protected]'
git add ./gradle.properties
git commit -m "Automated commit by GitHub Actions"
git push
24 changes: 24 additions & 0 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish

on:
push:
branches: [ master ]

jobs:
deploy:
name: Publish
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Publish snapshot
run: |
./gradlew clean publish
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Run Lint
run: |
./gradlew clean test
54 changes: 54 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.Properties

plugins {
id("org.springframework.boot") version "3.0.1" apply false
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.8.0"
kotlin("plugin.spring") version "1.8.0"
id("org.jlleitschuh.gradle.ktlint") version "10.0.0"
id("maven-publish")
}

java.sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -45,6 +50,40 @@ allprojects {
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
}

publishing {
val authToken = ByteArrayOutputStream().use {
runCatching {
exec {
commandLine = (
"aws codeartifact get-authorization-token " +
"--domain wafflestudio --domain-owner 405906814034 " +
"--query authorizationToken --region ap-northeast-1 --output text"
).split(" ")
standardOutput = it
}
}
it.toString()
}

repositories {
maven {
version = properties["version"]!!
name = "wafflestudio"
url = uri("https://wafflestudio-405906814034.d.codeartifact.ap-northeast-1.amazonaws.com/maven/truffle-kotlin/")
credentials {
username = "aws"
password = authToken
}
}
}

publications {
register<MavenPublication>("truffle-kotlin") {
from(components["java"])
}
}
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
Expand All @@ -56,3 +95,18 @@ allprojects {
useJUnitPlatform()
}
}

task("updateVersion") {
properties["releaseVersion"]?.let { releaseVersion ->
val newSnapshotVersion = (releaseVersion as String).split(".").let {
"${it[0]}.${it[1].toInt() + 1}.0-SNAPSHOT"
}

val file = File(rootDir, "gradle.properties")
val prop = Properties().apply { load(FileInputStream(file)) }
if (prop.getProperty("version") != newSnapshotVersion) {
prop.setProperty("version", newSnapshotVersion)
prop.store(FileOutputStream(file), null)
}
}
}
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
group=com.wafflestudio.truffle.sdk
version=1.0.0-SNAPSHOT
#Thu Jan 26 02:26:27 KST 2023
kotlin.code.style=official
version=1.0.0-SNAPSHOT
group=com.wafflestudio.truffle.sdk

0 comments on commit 1262c7d

Please sign in to comment.