-
Notifications
You must be signed in to change notification settings - Fork 37
126 lines (111 loc) · 4.29 KB
/
reusable-maven.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
name: Reusable workflow for maven packages
on:
workflow_call:
inputs:
path_to_package:
required: true
type: string
dependencies:
description: "List of paths to dependencies. Entries are relative to the java directory and separated by comma (no whitespaces)."
required: false
type: string
defaults:
run:
working-directory: java
jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
- name: Build dependencies
if: ${{ inputs.dependencies != '' }}
run: |
IFS=',' read -r -a dirs <<< "${{ inputs.dependencies }}"
for dir in "${dirs[@]}"
do
cd "$dir"
mvn clean install --no-transfer-progress
cd -
done
- name: Verify package
run: |
cd ${{ inputs.path_to_package }}
mvn verify -fae --no-transfer-progress
- name: Check mvn licenses
run: |
cd ${{ inputs.path_to_package }}
mvn org.eclipse.dash:license-tool-plugin:license-check -Ddash.iplab.token=${{ secrets.DASH_LICENSES_PAT }} -Ddash.projectId=ecd.theia
publish:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'release'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Run Version Check
id: version_check
run: |
cd ${{ inputs.path_to_package }}
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
if [[ "$VERSION" == *-SNAPSHOT ]]; then
echo "is_snapshot_version=true" >> $GITHUB_OUTPUT
else
echo "is_snapshot_version=false" >> $GITHUB_OUTPUT
fi
# Only continue from here when the version matches the event, so either:
# - main merge with snapshot version
# - release with proper version
- name: Set up JDK 17
if: |
(github.event_name == 'push' && steps.version_check.outputs.is_snapshot_version == 'true') ||
(github.event_name == 'release' && steps.version_check.outputs.is_snapshot_version == 'false')
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
- name: Build dependencies
if: |
${{ inputs.dependencies != '' }} &&
(
(github.event_name == 'push' && steps.version_check.outputs.is_snapshot_version == 'true') ||
(github.event_name == 'release' && steps.version_check.outputs.is_snapshot_version == 'false')
)
run: |
IFS=',' read -r -a dirs <<< "${{ inputs.dependencies }}"
for dir in "${dirs[@]}"
do
cd "$dir"
mvn clean install --no-transfer-progress
cd -
done
- name: Publish package to GitHub Packages
if: |
(github.event_name == 'push' && steps.version_check.outputs.is_snapshot_version == 'true') ||
(github.event_name == 'release' && steps.version_check.outputs.is_snapshot_version == 'false')
run: |
cd ${{ inputs.path_to_package }}
mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Authenticate to Google Cloud
if: |
(github.event_name == 'push' && steps.version_check.outputs.is_snapshot_version == 'true') ||
(github.event_name == 'release' && steps.version_check.outputs.is_snapshot_version == 'false')
uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f #v2.1.7
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: Publish package to Google Artifact Registry
if: |
(github.event_name == 'push' && steps.version_check.outputs.is_snapshot_version == 'true') ||
(github.event_name == 'release' && steps.version_check.outputs.is_snapshot_version == 'false')
run: |
cd ${{ inputs.path_to_package }}
mvn --batch-mode deploy -Partifact-registry
env:
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}