Skip to content

Commit 228a063

Browse files
authored
Refactor GitHub actions (#702)
* remove VERSION.txt and refactor github actions * combine gradle & docker build into one job * combine push and build * use eclipse-temurin:18 as docker base image for linux/arm/v7 & linux/arm64/v8 images
1 parent e892afe commit 228a063

File tree

7 files changed

+50
-72
lines changed

7 files changed

+50
-72
lines changed

.github/workflows/build.yml

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ name: Build
22

33
on:
44
push:
5-
paths-ignore:
6-
- '**.md'
5+
branches: [ '**' ]
6+
paths-ignore: [ '**.md' ]
7+
workflow_call:
8+
secrets:
9+
DOCKERHUB_USERNAME:
10+
DOCKERHUB_TOKEN:
711

812
jobs:
9-
gradle:
13+
build:
1014
runs-on: ubuntu-latest
11-
outputs:
12-
rundocker: ${{ steps.rundocker.outputs.rundocker }}
15+
env:
16+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
17+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
1318
steps:
1419
- name: Checkout
1520
uses: actions/checkout@v3
@@ -33,29 +38,8 @@ jobs:
3338
name: Lavalink.jar
3439
path: LavalinkServer/build/libs/Lavalink.jar
3540

36-
- name: Check Docker Build
37-
id: rundocker
38-
env:
39-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
40-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
41-
run: |
42-
echo "Run docker build: ${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}"
43-
echo "::set-output name=rundocker::${{ env.DOCKERHUB_USERNAME != '' && env.DOCKERHUB_TOKEN != '' }}"
44-
45-
docker:
46-
needs: gradle
47-
runs-on: ubuntu-latest
48-
if: needs.gradle.outputs.rundocker == 'true'
49-
steps:
50-
- name: Checkout
51-
uses: actions/checkout@v2
52-
53-
- name: Download Artifacts
54-
uses: actions/download-artifact@v2
55-
with:
56-
name: Lavalink.jar
57-
5841
- name: Docker Meta
42+
if: env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN
5943
id: meta
6044
uses: docker/metadata-action@v4
6145
with:
@@ -68,43 +52,27 @@ jobs:
6852
type=sha,prefix=
6953
7054
- name: Set up QEMU
55+
if: env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN
7156
uses: docker/setup-qemu-action@v2
7257

7358
- name: Set up Docker Buildx
59+
if: env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN
7460
uses: docker/setup-buildx-action@v2
7561

7662
- name: Login to DockerHub
63+
if: env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN
7764
uses: docker/login-action@v2
7865
with:
79-
username: ${{ secrets.DOCKERHUB_USERNAME }}
80-
password: ${{ secrets.DOCKERHUB_TOKEN }}
66+
username: ${{ env.DOCKERHUB_USERNAME }}
67+
password: ${{ env.DOCKERHUB_TOKEN }}
8168

82-
- name: Build and push
69+
- name: Build and Push
70+
if: env.DOCKERHUB_USERNAME && env.DOCKERHUB_TOKEN
8371
uses: docker/build-push-action@v3
8472
with:
8573
file: LavalinkServer/docker/Dockerfile
8674
context: .
87-
platforms: linux/amd64
75+
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
8876
push: true
8977
tags: ${{ steps.meta.outputs.tags }}
9078
labels: ${{ steps.meta.outputs.labels }}
91-
92-
release:
93-
needs: gradle
94-
permissions:
95-
contents: write
96-
runs-on: ubuntu-latest
97-
if: startsWith(github.ref, 'refs/tags/')
98-
steps:
99-
- name: Checkout
100-
uses: actions/checkout@v2
101-
102-
- name: Download Artifacts
103-
uses: actions/download-artifact@v2
104-
with:
105-
name: Lavalink.jar
106-
107-
- name: Upload Artifacts to GitHub Release
108-
uses: softprops/action-gh-release@v1
109-
with:
110-
files: Lavalink.jar

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
uses: ./.github/workflows/build.yml
10+
secrets:
11+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
12+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
13+
14+
release:
15+
needs: build
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
21+
- name: Download Artifacts
22+
uses: actions/download-artifact@v2
23+
with:
24+
name: Lavalink.jar
25+
26+
- name: Upload Artifacts to GitHub Release
27+
uses: softprops/action-gh-release@v1
28+
with:
29+
files: Lavalink.jar

LavalinkServer/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
/debug_token
77
build/*
88
/out/
9-
VERSION.txt

LavalinkServer/build.gradle.kts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,10 @@ tasks {
7474
}
7575

7676
processResources {
77-
val buildNumber = if (System.getenv("CI") != null) {
78-
System.getenv("BUILD_NUMBER") ?: "Unknown"
79-
} else {
80-
"Unofficial"
81-
}
82-
8377
val tokens = mapOf(
8478
"project.version" to project.version,
8579
"project.groupId" to project.group,
8680
"project.artifactId" to "Lavalink-Server",
87-
"env.BUILD_NUMBER" to buildNumber,
8881
"env.BUILD_TIME" to System.currentTimeMillis().toString()
8982
)
9083

@@ -137,11 +130,3 @@ fun versionFromTag(): String = Grgit.open(mapOf("currentDir" to project.rootDir)
137130

138131
return if (headTag != null && clean) headTag.name else "${git.head().id}-SNAPSHOT"
139132
}
140-
141-
//create a simple version file that we will be reading to create appropriate docker tags
142-
fun versionTxt() {
143-
val versionTxt = File("$projectDir/VERSION.txt")
144-
versionTxt.writeText("${project.version}\n")
145-
}
146-
147-
versionTxt()

LavalinkServer/docker/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM azul/zulu-openjdk:18
1+
FROM eclipse-temurin:18
22

33
# Run as non-root user
44
RUN groupadd -g 322 lavalink && \
@@ -10,6 +10,6 @@ RUN chown -R lavalink:lavalink /opt/Lavalink
1010

1111
USER lavalink
1212

13-
COPY Lavalink.jar Lavalink.jar
13+
COPY LavalinkServer/build/libs/Lavalink.jar Lavalink.jar
1414

1515
ENTRYPOINT ["java", "-Djdk.tls.client.protocols=TLSv1.1,TLSv1.2", "-Xmx4G", "-jar", "Lavalink.jar"]

LavalinkServer/src/main/java/lavalink/server/Launcher.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ object Launcher {
6969
val commitTime = dtf.format(Instant.ofEpochMilli(gitRepoState.commitTime * 1000))
7070

7171
val version = appInfo.version.takeUnless { it.startsWith("@") } ?: "Unknown"
72-
val buildNumber = appInfo.buildNumber.takeUnless { it.startsWith("@") } ?: "Unofficial"
7372

7473
return buildString {
7574
if (vanity) {
@@ -83,7 +82,6 @@ object Launcher {
8382
}
8483
appendln()
8584
append("${indentation}Version: "); appendln(version)
86-
append("${indentation}Build: "); appendln(buildNumber)
8785
if (gitRepoState.isLoaded) {
8886
append("${indentation}Build time: "); appendln(buildTime)
8987
append("${indentation}Branch "); appendln(gitRepoState.branch)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
22
33
4-
buildNumber[email protected]_NUMBER@
54
buildTime[email protected]_TIME@

0 commit comments

Comments
 (0)