-
Notifications
You must be signed in to change notification settings - Fork 28
119 lines (115 loc) · 4.55 KB
/
build-java-app-workflow.yml
File metadata and controls
119 lines (115 loc) · 4.55 KB
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
name: Reusable workflow to build Java application
on:
workflow_call:
inputs:
maven_opts:
type: string
required: false
build_folder:
type: string
required: false
default: "build-folder"
upload_artifact:
type: boolean
required: false
default: true
dependency_repos:
# Comma-separated list of dependency repositories to clone and build before building the main project.
type: string
required: false
default: ""
needs_hadoop_preparation:
type: boolean
required: false
default: false
hadoop_flavour:
type: string
required: false
default: ""
java_commons_libs_branch:
type: string
required: false
default: "develop"
outputs:
version:
description: "Project version"
value: ${{ jobs.build-workflow.outputs.version }}
cache_key:
description: "Cache key used for Maven repository"
value: ${{ jobs.build-workflow.outputs.cache_key }}
jobs:
build-workflow:
name: Build Java app
runs-on: ${{ vars.UBUNTU_VERSION }}
outputs:
version: ${{ steps.get_project_version.outputs.version }}
cache_key: ${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}-${{ steps.clone_dependencies.outputs.dependencies_sha }}
steps:
- uses: actions/checkout@v4
name: Checkout main repository
id: "checkout-main"
## This checkout pulls the code of the repository where this workflow is being used
with:
fetch-depth: '10'
- uses: actions/checkout@v4
if: ${{ inputs.dependency_repos != '' }}
name: Checkout java-common-libs repository
id: "checkout-java-common-libs"
## This checkout pulls the code of the java-common-libs repository to get the scripts
## Checkout to "java-common-libs" folder.
## Filter by ".github" folder
with:
repository: opencb/java-common-libs
ref: ${{ inputs.java_commons_libs_branch }}
path: java-common-libs
fetch-depth: '1'
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
cache: 'maven'
- name: Clone dependencies
id: clone_dependencies
if: ${{ inputs.dependency_repos != '' }}
run: |
if [ -f "java-common-libs/.github/workflows/scripts/get_same_branch.sh" ]; then
chmod +x java-common-libs/.github/workflows/scripts/get_same_branch.sh
export DEPENDENCIES_SHA=${{ github.sha }}
java-common-libs/.github/workflows/scripts/get_same_branch.sh "${{ github.ref_name }}" "${{ inputs.dependency_repos }}"
fi
- name: Cache local Maven repository
id: cache
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}-${{ steps.clone_dependencies.outputs.dependencies_sha }}
restore-keys: |
${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}-
- name: Compile dependencies
if: ${{ inputs.dependency_repos != '' }}
run: |
if [ -f "java-common-libs/.github/workflows/scripts/compile_same_branch.sh" ]; then
chmod +x java-common-libs/.github/workflows/scripts/compile_same_branch.sh
java-common-libs/.github/workflows/scripts/compile_same_branch.sh "${{ inputs.dependency_repos }}"
fi
- name: Prepare Hadoop profile
if: ${{ inputs.needs_hadoop_preparation == true }}
run: |
chmod +x ./.github/workflows/scripts/prepare_hadoop.sh
./.github/workflows/scripts/prepare_hadoop.sh --hadoop-flavour "${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}"
env:
THIRDPARTY_READ_TOKEN: ${{ secrets.THIRDPARTY_READ_TOKEN }}
- name: Maven Build (skip tests)
run: mvn -T 2 clean install -DskipTests ${{ inputs.maven_opts }} --no-transfer-progress
- uses: actions/upload-artifact@v4
if: ${{ inputs.upload_artifact == true }}
with:
name: ${{ inputs.build_folder }}
path: build
- id: get_project_version
name: Get project version
run: |
echo "version=`mvn help:evaluate -q -Dexpression=project.version -DforceStdout`" >> $GITHUB_OUTPUT
- name: test-version-from-check
run: echo "Project version is " ${{ steps.get_project_version.outputs.version }}