|
10 | 10 | type: string |
11 | 11 | required: false |
12 | 12 | default: "build-folder" |
| 13 | + upload_artifact: |
| 14 | + type: boolean |
| 15 | + required: false |
| 16 | + default: true |
| 17 | + dependency_repos: |
| 18 | + # Comma-separated list of dependency repositories to clone and build before building the main project. |
| 19 | + type: string |
| 20 | + required: false |
| 21 | + default: "" |
| 22 | + needs_hadoop_preparation: |
| 23 | + type: boolean |
| 24 | + required: false |
| 25 | + default: false |
| 26 | + hadoop_flavour: |
| 27 | + type: string |
| 28 | + required: false |
| 29 | + default: "" |
| 30 | + java_commons_libs_branch: |
| 31 | + type: string |
| 32 | + required: false |
| 33 | + default: "develop" |
13 | 34 | outputs: |
14 | 35 | version: |
15 | 36 | description: "Project version" |
16 | 37 | value: ${{ jobs.build-workflow.outputs.version }} |
| 38 | + cache_key: |
| 39 | + description: "Cache key used for Maven repository" |
| 40 | + value: ${{ jobs.build-workflow.outputs.cache_key }} |
17 | 41 |
|
18 | 42 | jobs: |
19 | 43 | build-workflow: |
20 | 44 | name: Build Java app |
21 | 45 | runs-on: ${{ vars.UBUNTU_VERSION }} |
22 | 46 | outputs: |
23 | 47 | version: ${{ steps.get_project_version.outputs.version }} |
| 48 | + cache_key: ${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}-${{ steps.clone_dependencies.outputs.dependencies_sha }} |
24 | 49 | steps: |
25 | 50 | - uses: actions/checkout@v4 |
| 51 | + name: Checkout main repository |
| 52 | + id: "checkout-main" |
| 53 | + ## This checkout pulls the code of the repository where this workflow is being used |
26 | 54 | with: |
27 | 55 | fetch-depth: '10' |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + if: ${{ inputs.dependency_repos != '' }} |
| 58 | + name: Checkout java-common-libs repository |
| 59 | + id: "checkout-java-common-libs" |
| 60 | + ## This checkout pulls the code of the java-common-libs repository to get the scripts |
| 61 | + ## Checkout to "java-common-libs" folder. |
| 62 | + ## Filter by ".github" folder |
| 63 | + with: |
| 64 | + repository: opencb/java-common-libs |
| 65 | + ref: ${{ inputs.java_commons_libs_branch }} |
| 66 | + path: java-common-libs |
| 67 | + fetch-depth: '1' |
28 | 68 | - name: Set up JDK 8 |
29 | 69 | uses: actions/setup-java@v4 |
30 | 70 | with: |
31 | 71 | distribution: 'temurin' |
32 | 72 | java-version: '8' |
33 | 73 | cache: 'maven' |
34 | | - - name: Install dependencies branches |
| 74 | + - name: Clone dependencies |
| 75 | + id: clone_dependencies |
| 76 | + if: ${{ inputs.dependency_repos != '' }} |
| 77 | + run: | |
| 78 | + if [ -f "java-common-libs/.github/workflows/scripts/get_same_branch.sh" ]; then |
| 79 | + chmod +x java-common-libs/.github/workflows/scripts/get_same_branch.sh |
| 80 | + export DEPENDENCIES_SHA=${{ github.sha }} |
| 81 | + java-common-libs/.github/workflows/scripts/get_same_branch.sh "${{ github.ref_name }}" "${{ inputs.dependency_repos }}" |
| 82 | + fi |
| 83 | + - name: Cache local Maven repository |
| 84 | + id: cache |
| 85 | + uses: actions/cache@v4 |
| 86 | + with: |
| 87 | + path: ~/.m2/repository |
| 88 | + key: ${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}-${{ steps.clone_dependencies.outputs.dependencies_sha }} |
| 89 | + restore-keys: | |
| 90 | + ${{ runner.os }}-maven-${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}- |
| 91 | + - name: Compile dependencies |
| 92 | + if: ${{ inputs.dependency_repos != '' }} |
35 | 93 | run: | |
36 | | - if [ -f "./.github/workflows/scripts/get_same_branch.sh" ]; then |
37 | | - chmod +x ./.github/workflows/scripts/get_same_branch.sh |
38 | | - ./.github/workflows/scripts/get_same_branch.sh ${{ github.ref_name }} |
| 94 | + if [ -f "java-common-libs/.github/workflows/scripts/compile_same_branch.sh" ]; then |
| 95 | + chmod +x java-common-libs/.github/workflows/scripts/compile_same_branch.sh |
| 96 | + java-common-libs/.github/workflows/scripts/compile_same_branch.sh "${{ inputs.dependency_repos }}" |
39 | 97 | fi |
| 98 | + - name: Prepare Hadoop profile |
| 99 | + if: ${{ inputs.needs_hadoop_preparation == true }} |
| 100 | + run: | |
| 101 | + chmod +x ./.github/workflows/scripts/prepare_hadoop.sh |
| 102 | + ./.github/workflows/scripts/prepare_hadoop.sh --hadoop-flavour "${{ inputs.hadoop_flavour || vars.HADOOP_FLAVOUR }}" |
| 103 | + env: |
| 104 | + THIRDPARTY_READ_TOKEN: ${{ secrets.THIRDPARTY_READ_TOKEN }} |
| 105 | + |
40 | 106 | - name: Maven Build (skip tests) |
41 | 107 | run: mvn -T 2 clean install -DskipTests ${{ inputs.maven_opts }} --no-transfer-progress |
42 | 108 | - uses: actions/upload-artifact@v4 |
| 109 | + if: ${{ inputs.upload_artifact == true }} |
43 | 110 | with: |
44 | 111 | name: ${{ inputs.build_folder }} |
45 | 112 | path: build |
|
49 | 116 | echo "version=`mvn help:evaluate -q -Dexpression=project.version -DforceStdout`" >> $GITHUB_OUTPUT |
50 | 117 | - name: test-version-from-check |
51 | 118 | run: echo "Project version is " ${{ steps.get_project_version.outputs.version }} |
| 119 | + |
0 commit comments