Skip to content

Commit cf2854a

Browse files
Test updated build-gradle
1 parent 6bc2a67 commit cf2854a

File tree

3 files changed

+435
-2
lines changed

3 files changed

+435
-2
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
name: Build Gradle
3+
description: GitHub Action to build, analyze, and deploy a Gradle project with SonarQube integration
4+
inputs:
5+
public:
6+
description: Deprecated. Use `artifactory-reader-role`, `artifactory-deployer-role`, and `artifactory-deploy-repo` instead.
7+
default: ${{ github.event.repository.visibility == 'public' && 'true' || 'false' }}
8+
artifactory-deploy-repo:
9+
description: Deployment repository. Defaults to `sonarsource-private-qa` for private repositories, and `sonarsource-public-qa` for
10+
public repositories.
11+
default: ''
12+
artifactory-reader-role:
13+
description: Suffix for the Artifactory reader role in Vault. Defaults to `private-reader` for private repositories,
14+
and `public-reader` for public repositories.
15+
default: ''
16+
artifactory-deployer-role:
17+
description: Suffix for the Artifactory deployer role in Vault. Defaults to `qa-deployer` for private repositories, and
18+
`public-deployer` for public repositories.
19+
default: ''
20+
gradle-args:
21+
description: Additional arguments to pass to Gradle
22+
deploy-pull-request:
23+
description: Whether to deploy pull request artifacts
24+
default: 'false'
25+
skip-tests:
26+
description: Whether to skip running tests
27+
default: 'false'
28+
use-develocity:
29+
description: Whether to use Develocity for build tracking.
30+
default: 'false'
31+
develocity-url:
32+
description: URL for Develocity
33+
default: https://develocity.sonar.build/
34+
repox-url:
35+
description: URL for Repox
36+
default: https://repox.jfrog.io
37+
repox-artifactory-url:
38+
description: URL for Repox Artifactory API (overrides repox-url/artifactory if provided)
39+
default: ''
40+
sonar-platform:
41+
description: SonarQube variant (next, sqc-eu, sqc-us, or none). Use 'none' to skip sonar scans.
42+
default: next
43+
run-shadow-scans:
44+
description: If true, run sonar scanner on all 3 platforms using the provided URL and token.
45+
If false, run on the platform provided by SONAR_PLATFORM.
46+
default: 'false'
47+
cache-paths:
48+
description: Cache paths to use (multiline). If provided, overrides the default Gradle cache directories
49+
default: |-
50+
~/.gradle/caches
51+
~/.gradle/wrapper
52+
disable-caching:
53+
description: Whether to disable Gradle caching entirely
54+
default: 'false'
55+
56+
outputs:
57+
project-version:
58+
description: The release version set as Gradle project version in gradle.properties
59+
value: ${{ steps.build.outputs.project-version }}
60+
BUILD_NUMBER:
61+
description: The build number, incremented or reused if already cached
62+
value: ${{ steps.config-gradle.outputs.BUILD_NUMBER }}
63+
64+
runs:
65+
using: composite
66+
steps:
67+
- uses: SonarSource/ci-github-actions/get-build-number@v1
68+
id: get_build_number
69+
- name: Vault
70+
id: secrets
71+
uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
72+
with:
73+
# yamllint disable rule:line-length
74+
secrets: |
75+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/next url | NEXT_URL;' || '' }}
76+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/next token | NEXT_TOKEN;' || '' }}
77+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/sonarqube-us url | SQC_US_URL;' || '' }}
78+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/sonarqube-us token | SQC_US_TOKEN;' || '' }}
79+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/sonarcloud url | SQC_EU_URL;' || '' }}
80+
${{ inputs.sonar-platform != 'none' && 'development/kv/data/sonarcloud token | SQC_EU_TOKEN;' || '' }}
81+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_DEPLOYER_ROLE }} username | ARTIFACTORY_DEPLOY_USERNAME;
82+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_DEPLOYER_ROLE }} access_token | ARTIFACTORY_DEPLOY_ACCESS_TOKEN;
83+
development/kv/data/sign key | SIGN_KEY;
84+
development/kv/data/sign passphrase | PGP_PASSPHRASE;
85+
development/kv/data/sign key_id | SIGN_KEY_ID;
86+
# yamllint enable rule:line-length
87+
88+
- name: Setup environment for deployment
89+
shell: bash
90+
env:
91+
# Deployment secrets
92+
ARTIFACTORY_DEPLOY_REPO: ${{ inputs.artifactory-deploy-repo != '' && inputs.artifactory-deploy-repo ||
93+
github.event.repository.visibility == 'public' && 'sonarsource-public-qa' || 'sonarsource-private-qa' }}
94+
ARTIFACTORY_DEPLOY_USERNAME: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_DEPLOY_USERNAME }}
95+
ARTIFACTORY_DEPLOY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_DEPLOY_ACCESS_TOKEN }}
96+
run: |
97+
echo "ARTIFACTORY_DEPLOY_REPO=$ARTIFACTORY_DEPLOY_REPO" >> "$GITHUB_ENV"
98+
echo "ARTIFACTORY_DEPLOY_USERNAME=$ARTIFACTORY_DEPLOY_USERNAME" >> "$GITHUB_ENV"
99+
echo "ARTIFACTORY_DEPLOY_ACCESS_TOKEN=$ARTIFACTORY_DEPLOY_ACCESS_TOKEN" >> "$GITHUB_ENV"
100+
echo "ARTIFACTORY_DEPLOY_PASSWORD=$ARTIFACTORY_DEPLOY_ACCESS_TOKEN" >> "$GITHUB_ENV" # deprecated, backward compliance
101+
102+
- name: Configure Gradle
103+
uses: ./.actions/config-gradle
104+
id: config-gradle
105+
with:
106+
artifactory-reader-role: ${{ inputs.artifactory-reader-role }}
107+
use-develocity: ${{ inputs.use-develocity }}
108+
develocity-url: ${{ inputs.develocity-url }}
109+
repox-url: ${{ inputs.repox-url }}
110+
repox-artifactory-url: ${{ inputs.repox-artifactory-url }}
111+
cache-paths: ${{ inputs.cache-paths }}
112+
disable-caching: ${{ inputs.disable-caching }}
113+
114+
- name: Build, analyze and deploy
115+
id: build
116+
shell: bash
117+
env:
118+
# GitHub context
119+
PULL_REQUEST: ${{ github.event.pull_request.number || '' }}
120+
PULL_REQUEST_SHA: ${{ github.event.pull_request.base.sha || '' }}
121+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
122+
123+
# Action inputs
124+
DEPLOY_PULL_REQUEST: ${{ inputs.deploy-pull-request }}
125+
SKIP_TESTS: ${{ inputs.skip-tests }}
126+
GRADLE_ARGS: ${{ inputs.gradle-args }}
127+
128+
# Vault secrets - always fetch all platforms
129+
NEXT_URL: ${{ fromJSON(steps.secrets.outputs.vault).NEXT_URL }}
130+
NEXT_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).NEXT_TOKEN }}
131+
SQC_US_URL: ${{ fromJSON(steps.secrets.outputs.vault).SQC_US_URL }}
132+
SQC_US_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).SQC_US_TOKEN }}
133+
SQC_EU_URL: ${{ fromJSON(steps.secrets.outputs.vault).SQC_EU_URL }}
134+
SQC_EU_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).SQC_EU_TOKEN }}
135+
SONAR_PLATFORM: ${{ inputs.sonar-platform }}
136+
RUN_SHADOW_SCANS: ${{ inputs.run-shadow-scans }}
137+
138+
ORG_GRADLE_PROJECT_signingKey: ${{ fromJSON(steps.secrets.outputs.vault).SIGN_KEY }}
139+
ORG_GRADLE_PROJECT_signingPassword: ${{ fromJSON(steps.secrets.outputs.vault).PGP_PASSPHRASE }}
140+
ORG_GRADLE_PROJECT_signingKeyId: ${{ fromJSON(steps.secrets.outputs.vault).SIGN_KEY_ID }}
141+
run: ${GITHUB_ACTION_PATH}/build.sh
142+
143+
- name: Archive problems report
144+
if: always()
145+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
146+
with:
147+
name: problems-report-${{ github.job }}${{ strategy.job-index }}
148+
path: build/reports/problems/problems-report.html
149+
if-no-files-found: ignore
150+
151+
- name: Generate workflow summary
152+
if: always()
153+
shell: bash
154+
env:
155+
ARTIFACTORY_URL: ${{ inputs.repox-artifactory-url != '' && inputs.repox-artifactory-url ||
156+
format('{0}/artifactory', inputs.repox-url) }}
157+
run: |
158+
build_name="${GITHUB_REPOSITORY#*/}"
159+
echo "## πŸ—οΈ Gradle Build Summary" >> $GITHUB_STEP_SUMMARY
160+
if [[ "${{ steps.build.conclusion }}" == "success" ]]; then
161+
echo "βœ… **Build SUCCESS**" >> $GITHUB_STEP_SUMMARY
162+
else
163+
echo "❌ **Build FAILED**" >> $GITHUB_STEP_SUMMARY
164+
fi
165+
echo "### πŸ“‹ Build Information" >> $GITHUB_STEP_SUMMARY
166+
echo "- **Project**: \`$build_name\`" >> $GITHUB_STEP_SUMMARY
167+
echo "- **Version**: \`${PROJECT_VERSION}\`" >> $GITHUB_STEP_SUMMARY
168+
echo "- **Build Number**: \`${BUILD_NUMBER}\`" >> $GITHUB_STEP_SUMMARY
169+
echo "- **Branch**: \`${GITHUB_REF}\`" >> $GITHUB_STEP_SUMMARY
170+
echo "- **Commit**: \`$GITHUB_SHA\`" >> $GITHUB_STEP_SUMMARY
171+
172+
if [[ "${{ steps.build.outputs.should-deploy }}" == true ]]; then
173+
echo "### πŸš€ Deployment" >> $GITHUB_STEP_SUMMARY
174+
ARTIFACTORY_BROWSE_URL="${ARTIFACTORY_URL%/*}/ui/builds/$build_name/$BUILD_NUMBER"
175+
echo "πŸ”— **[Browse artifacts in Artifactory](${ARTIFACTORY_BROWSE_URL})**" >> $GITHUB_STEP_SUMMARY
176+
fi

0 commit comments

Comments
Β (0)