Skip to content

Commit

Permalink
Initial CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
SIMULATAN committed Mar 28, 2024
1 parent 7c9be41 commit 19c4093
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
63 changes: 63 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
on: push

permissions:
packages: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Docker Metadata
id: docker-metadata
uses: docker/metadata-action@v5
with:
# won't be used but is required by the action
images: dummy
tags: |
type=semver,pattern=v{{major}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{version}}
type=ref,event=tag
type=ref,event=branch
type=ref,event=pr
- name: Setup gradle
uses: gradle/actions/setup-gradle@v3

- name: Build docker image
id: build-docker-image
run: |
additional_tags="$(echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr '\n' ' ' | sed 's/dummy://g')"
application_version="$(./gradlew properties -q | awk '/^version:/ {print $2}')"
# unique version like `2.6.1-69` - immutable
full_version="$application_version-${{github.run_number}}"
./gradlew \
-Pme.snoty.docker.tags="$full_version $additional_tags" \
-Pme.snoty.github.run="${{github.run_id}}:${{github.run_number}}" \
jibDockerBuild
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push docker image
run: docker push --all-tags ghcr.io/snotyme/snoty-backend

- name: Upload JAR
uses: actions/upload-artifact@v3
with:
name: artifacts
path: build/libs
27 changes: 26 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.github.simulatan.gradle.plugin.buildinfo.configuration.BuildInfoExtension
import io.github.simulatan.gradle.plugin.buildinfo.configuration.PropertiesOutputLocation
import org.eclipse.jgit.api.Git
import org.jetbrains.gradle.ext.Application
import org.jetbrains.gradle.ext.runConfigurations
import org.jetbrains.gradle.ext.settings
Expand Down Expand Up @@ -134,7 +135,7 @@ jib {
image = "eclipse-temurin:21-jre-alpine"
}
to {
val allTags = project.properties["snoty.docker.tags"]?.toString()?.split(" ")?.toSet()
val allTags = project.properties["me.snoty.docker.tags"]?.toString()?.trim()?.split(" ")?.toSet()
?: setOf(version.toString())
image = "ghcr.io/snotyme/snoty-backend:${allTags.first()}"
// workaround for the TERRIBLE design decisions of the JIB developers to
Expand All @@ -148,6 +149,30 @@ jib {
creationTime = "USE_CURRENT_TIMESTAMP"
appRoot = "/app"
workingDirectory = "/app"
ports = listOf("8080")
val (ghaRunId, ghaRunNumber) =
project.properties["me.snoty.github.run"]?.toString()?.split(":") ?: listOf(null, null)
labels = mapOf(
"org.opencontainers.image.title" to "snoty-backend",
"org.opencontainers.image.description" to "Backend for the snoty project",
"org.opencontainers.image.url" to "https://github.com/SnotyMe/snoty-backend/pkgs/container/snoty-backend",
*Git.open(project.rootDir).use { git ->
val headRef = git.repository.resolve("HEAD").name
arrayOf(
"org.opencontainers.image.revision" to headRef,
// source to https version of the git repository
"org.opencontainers.image.source" to git.repository.config.getString("remote", "origin", "url")
.replace(":", "/")
.replace("git@", "https://")
.replace(".git", "")
+ "/tree/$headRef"
)
},
*if (ghaRunId != null && ghaRunNumber != null) arrayOf(
"com.github.actions.run.id" to ghaRunId,
"com.github.actions.run.number" to ghaRunNumber
) else arrayOf()
)
}
}

Expand Down

0 comments on commit 19c4093

Please sign in to comment.