-
Notifications
You must be signed in to change notification settings - Fork 166
112 lines (99 loc) · 3.71 KB
/
build.yml
File metadata and controls
112 lines (99 loc) · 3.71 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
name: Build and test
on:
push:
paths-ignore:
- '.github/**'
- '**/*.md'
tags-ignore:
- '**'
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
skipTests:
description: "Skip unit tests?"
required: true
default: false
type: boolean
deploySnapshot:
description: "Deploy snapshot to Maven Central?"
required: true
default: false
type: boolean
runIntegrationTests:
description: "Run integration tests?"
required: true
default: false
type: boolean
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 20
env:
# Respect manual input for skipping unit tests (no effect for push/PR where inputs are empty)
SKIP_TESTS: ${{ github.event.inputs.skipTests }}
steps:
- uses: actions/checkout@v5
- name: Set Release version env variable
run: |
echo "TAG_NAME=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Set branch name env variable
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
BRANCH_NAME="${{ github.head_ref }}"
else
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
fi
if [ "$BRANCH_NAME" = "master" ]; then
echo "ARTIFACT_SUFFIX=" >> $GITHUB_ENV
else
# Sanitize branch name by replacing invalid characters with dashes
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[\/\\:*?"<>|]/-/g')
echo "ARTIFACT_SUFFIX=-$SANITIZED_BRANCH" >> $GITHUB_ENV
fi
# only build SNAPSHOTS, use release for tagged releases
- name: Check if tag contains SNAPSHOT
if: contains(env.TAG_NAME, 'SNAPSHOT') != true
run: |
echo "Tag '$TAG_NAME' does not contain 'SNAPSHOT', failing build."
exit 1
- name: Set up JDK 17
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-passphrase: MAVEN_GPG_PASSPHRASE
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
- name: Build package with maven
run: |
./mvnw --batch-mode $(if [ "$SKIP_TESTS" = "true" ]; then echo "-DskipTests"; fi) clean package
- name: Run integration tests (manual trigger only)
if: github.event_name == 'workflow_dispatch' && github.event.inputs.runIntegrationTests == 'true'
run: |
./mvnw --batch-mode -pl integration-test -am clean verify
- name: Deploy SNAPSHOT to maven central
if: (github.event_name == 'push' && github.ref == 'refs/heads/master') || (github.event_name == 'workflow_dispatch' && github.event.inputs.deploySnapshot == 'true')
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }}
run: |
./mvnw --batch-mode $(if [ "$SKIP_TESTS" = "true" ]; then echo "-DskipTests"; fi) clean deploy
- name: Upload sonar-pmd-plugin jar
uses: actions/upload-artifact@v4
with:
name: sonar-pmd-plugin-${{ env.TAG_NAME }}${{ env.ARTIFACT_SUFFIX }}
path: sonar-pmd-plugin/target/sonar-pmd-plugin-*.jar
- name: Upload sonar-pmd-lib jar
uses: actions/upload-artifact@v4
with:
name: sonar-pmd-lib-${{ env.TAG_NAME }}${{ env.ARTIFACT_SUFFIX }}
path: sonar-pmd-lib/target/sonar-pmd-lib-*.jar