Skip to content

Commit

Permalink
ci: add automated testing and publishing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chachako committed Dec 7, 2023
1 parent a3449ec commit d091ef5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build & Publish

on:
workflow_dispatch:
inputs:
type:
description: 'Publish type'
required: true
type: choice
options:
- release
- snapshot
default: snapshot
push:

jobs:
build:
name: Build & Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Check & Test
uses: gradle/gradle-build-action@v2
with:
distributions-cache-enabled: true
configuration-cache-enabled: true
dependencies-cache-enabled: true
arguments: |
check
test
--stacktrace
--scan
- name: Clean project
run: ./gradlew clean

publish:
name: Publishing
needs: build
runs-on: ubuntu-latest
# Only publish on main branch
if: github.ref == 'refs/heads/main'

env:
RELEASE: ${{ github.event.inputs.type == 'release' }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Publish publications
uses: gradle/gradle-build-action@v2
with:
arguments: publish --stacktrace
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.MavenPublishPlugin
import com.vanniktech.maven.publish.SonatypeHost

val isCiEnv = System.getenv("CI") != null
val isRelease = System.getenv("RELEASE") != null
val isCi = providers.environmentVariable("CI").isPresent
val isSnapshot = isCi && providers.environmentVariable("RELEASE").orNull != "true"

plugins {
alias(libs.plugins.detekt)
Expand All @@ -38,13 +38,13 @@ plugins {

detekt {
buildUponDefaultConfig = true
parallel = isCiEnv
parallel = !isCi
config.setFrom(layout.projectDirectory.file("detekt.yml"))
}

allprojects {
group = "com.meowool"
version = "0.1.0" + if (isCiEnv && !isRelease) "-SNAPSHOT" else ""
version = "0.1.0" + if (isSnapshot) "-SNAPSHOT" else ""
project.configureAndroid()
project.configurePublish()
}
Expand Down

0 comments on commit d091ef5

Please sign in to comment.