-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (127 loc) · 5.2 KB
/
build.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
name: Build
on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows reuse of this workflow as a generic "Java build with Maven that publishes to main on merge"
workflow_call:
inputs:
javadoc-project-name:
description: Project subdirectory to upload the JavaDoc to in Google Cloud Storage.
required: true
type: string
outputs:
release-version:
description: The version of the new release built on the main branch.
value: ${{ jobs.build_main_branch.outputs.release-version }}
jobs:
build_feature_branch:
name: Build feature branch
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
- name: Determine Java version
uses: joshlong/java-version-export-github-action@v28
id: determine-java-version
- name: Setup Java and Maven
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ steps.determine-java-version.outputs.java_major_version }}
cache: maven
- name: Build with Maven verify
run: |
./mvnw --batch-mode verify javadoc:javadoc javadoc:aggregate
build_main_branch:
name: Build main branch
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
release-version: ${{ steps.set-version.outputs.release-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Determine Java version
uses: joshlong/java-version-export-github-action@v28
id: determine-java-version
- name: Setup Java and Maven
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ steps.determine-java-version.outputs.java_major_version }}
cache: 'maven'
server-id: reload
server-username: MAVEN_SERVER_USERNAME
server-password: MAVEN_SERVER_PASSWORD
- name: Read revision version from pom.xml
shell: bash
run: |
MAVEN_POM_REVISION_VERSION="$(./mvnw --batch-mode help:evaluate -Dexpression=revision -q -DforceStdout)"
echo "MAVEN_POM_REVISION_VERSION=$MAVEN_POM_REVISION_VERSION" >> $GITHUB_ENV
- name: Check if revision is already tagged
shell: bash
run: |
if git tag -l $MAVEN_POM_REVISION_VERSION | grep -q $MAVEN_POM_REVISION_VERSION; then
echo "Revision $MAVEN_POM_REVISION_VERSION is already tagged. Skipping deployment."
exit 0
else
DEPLOY_RELEASE=true
echo "DEPLOY_RELEASE=$DEPLOY_RELEASE" >> $GITHUB_ENV
fi
- name: Build merged feature without releasing it
if: env.DEPLOY_RELEASE != 'true'
run: |
./mvnw -Dchangelist= --batch-mode verify -DstagingDirectory="${GITHUB_WORKSPACE}/target/latest" site:site site:stage
- name: Build new release
if: env.DEPLOY_RELEASE == 'true'
run: |
./mvnw -Dchangelist= --batch-mode verify -DstagingDirectory="${GITHUB_WORKSPACE}/target/latest" site:site site:stage
test -d "${GITHUB_WORKSPACE}/target/latest"
rm -rf -- "${GITHUB_WORKSPACE}/target/${MAVEN_POM_REVISION_VERSION}" || :
cp --recursive --verbose -- "${GITHUB_WORKSPACE}/target/latest" "${GITHUB_WORKSPACE}/target/${MAVEN_POM_REVISION_VERSION}"
- name: Deploy new release
if: env.DEPLOY_RELEASE == 'true'
env:
MAVEN_SERVER_USERNAME: ${{ secrets.MAVEN_SERVER_USERNAME }}
MAVEN_SERVER_PASSWORD: ${{ secrets.MAVEN_SERVER_PASSWORD }}
run: |
./mvnw --batch-mode deploy -Dchangelist= -DskipTests=true -Dcheckstyle.skip=true -Dpmd.skip=true -Dspotbugs.skip=true
- name: Create new git tag
if: env.DEPLOY_RELEASE == 'true'
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ env.MAVEN_POM_REVISION_VERSION }}
message: Release ${{ env.MAVEN_POM_REVISION_VERSION }}
- name: Set version output
id: set-version
if: env.DEPLOY_RELEASE == 'true'
run: echo "release-version=${MAVEN_POM_REVISION_VERSION}" >> $GITHUB_OUTPUT
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.CLOUDBUILD_COMMON_GCP_KEY }}
- name: Upload latest JavaDoc copy to Google Cloud Storage
uses: google-github-actions/upload-cloud-storage@v2
with:
path: target/latest
destination: resilient-reload-javadoc/${{ inputs.javadoc-project-name || 'MavenSetup' }}
process_gcloudignore: false
- name: Upload versioned JavaDoc to Google Cloud Storage
if: env.DEPLOY_RELEASE == 'true'
uses: google-github-actions/upload-cloud-storage@v2
with:
path: target/${{ env.MAVEN_POM_REVISION_VERSION }}
destination: resilient-reload-javadoc/${{ inputs.javadoc-project-name || 'MavenSetup' }}
process_gcloudignore: false