forked from sentrysoftware/metricshub-jre-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (112 loc) · 4.14 KB
/
build-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Build and Deploy JRE
on:
workflow_call:
inputs:
deploy:
type: boolean
description: Deploy JRE to Maven and Docker Repositories
required: true
default: false
workflow_dispatch:
inputs:
deploy:
type: boolean
description: Deploy JRE to Maven and Docker Repositories
required: true
default: false
env:
JDK_VERSION: 17.0.12+7
jobs:
build-jre:
name: Build JRE
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JDK_VERSION }}
distribution: temurin
java-package: jdk
cache: maven
- name: Build Linux JRE
if: runner.os == 'Linux'
run: |
jlinkModules=$(cat modules.txt | tr '\n' ',')
jlink --strip-debug --no-header-files --no-man-pages --add-modules $jlinkModules --output jre-linux
echo "JRE_OS_NAME=linux">>${GITHUB_ENV}
cd jre-linux/ && zip -r ../metricshub-jre-linux.zip .
- name: Build Windows JRE
if: runner.os == 'Windows'
run: |
$jlinkModules=(Get-Content modules.txt) -join ','
jlink --strip-debug --no-header-files --no-man-pages --add-modules $jlinkModules --output jre-windows
echo "JRE_OS_NAME=windows" >> $env:GITHUB_ENV
Compress-Archive -Path jre-windows\* -DestinationPath metricshub-jre-windows.zip
- name: Attach JRE Archive to the Build
uses: actions/upload-artifact@v4
with:
name: metricshub-jre-${{ env.JDK_VERSION }}-${{ env.JRE_OS_NAME }}
path: metricshub-jre-${{ env.JRE_OS_NAME }}.zip
- name: Maven Deploy Archives
if: ${{ inputs.deploy }}
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
mvn deploy:deploy-file -Durl=https://maven.pkg.github.com/${{ env.GITHUB_REPOSITORY_OWNER }}/${{ env.GITHUB_REPOSITORY }} -Dfile=metricshub-jre-${{ env.JRE_OS_NAME }}.zip -DgroupId=org.sentrysoftware -DartifactId=metricshub-jre-${{ env.JRE_OS_NAME }} -Dversion=${{ env.JDK_VERSION }} -Dpackaging=jlink "-Ddescription=MetricsHub JRE for ${{ runner.os }}"
build-jre-docker:
name: Build JRE (docker)
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker
uses: docker/setup-buildx-action@v3
-
# Docker Images Does Not Contains the plus (+) sign
# Must be replaced with underscore (_)
name: Prepare Environment Variables
run: |
echo "JDK_IMAGE_TAG=${{ env.JDK_VERSION }}" | sed 's/+/_/g' >> $GITHUB_ENV
echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
with:
build-args: |
JDK_VERSION=${{ env.JDK_IMAGE_TAG }}
platforms: linux/amd64,linux/arm64
push: ${{ inputs.deploy }}
tags: |
${{ vars.DOCKERHUB_ORG }}/metricshub-jre:latest
${{ vars.DOCKERHUB_ORG }}/metricshub-jre:${{ env.JDK_IMAGE_TAG }}
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:latest
ghcr.io/${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}:${{ env.JDK_IMAGE_TAG }}