Skip to content

Commit 255bb9a

Browse files
Add GitHub Actions workflow to publish build artifacts to Artifactory (#354)
* Add deploy script for Artifactory with version bump * Add 'jenkins' branch to workflow triggers * Clean up pom.xml by removing unused repository comments Removed commented-out repository configurations for Artifactory and GitHub Packages. * Use secret for Artifactory URL in workflow * Update internalArticatory.yml * Update main-build.yml * updated the workflow file * updated the workflow to run on demand only * updated the workflow --------- Co-authored-by: yashmeet29 <[email protected]>
1 parent e920ef9 commit 255bb9a

File tree

3 files changed

+193
-16
lines changed

3 files changed

+193
-16
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Internal Artifactory snapshot deploy
2+
3+
env:
4+
JAVA_VERSION: '17'
5+
MAVEN_VERSION: '3.6.3'
6+
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
7+
8+
on:
9+
workflow_dispatch:
10+
jobs:
11+
build-and-deploy-artifactory:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Java ${{ env.JAVA_VERSION }}
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: ${{ env.JAVA_VERSION }}
23+
distribution: sapmachine
24+
cache: maven
25+
server-id: artifactory
26+
server-username: CAP_DEPLOYMENT_USER
27+
server-password: CAP_DEPLOYMENT_PASS
28+
env:
29+
CAP_DEPLOYMENT_USER: ${{ secrets.CAP_DEPLOYMENT_USER }}
30+
CAP_DEPLOYMENT_PASS: ${{ secrets.CAP_DEPLOYMENT_PASS }}
31+
32+
- name: Set up Maven ${{ env.MAVEN_VERSION }}
33+
uses: stCarolas/setup-maven@v5
34+
with:
35+
maven-version: ${{ env.MAVEN_VERSION }}
36+
37+
- name: Read current revision
38+
id: read-revision
39+
run: |
40+
current_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
41+
echo "Current version: $current_version"
42+
echo "revision=$current_version" >> $GITHUB_OUTPUT
43+
echo "updated_version=$current_version" >> $GITHUB_OUTPUT
44+
- name: Bump version if needed
45+
id: bump-version
46+
# if: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/jenkins' }}
47+
run: |
48+
current_version="${{ steps.read-revision.outputs.revision }}"
49+
if [[ $current_version != *-SNAPSHOT ]]; then
50+
echo "Version lacks -SNAPSHOT; incrementing patch."
51+
IFS='.' read -r major minor patch <<< "$(echo $current_version | tr '-' '.')"
52+
new_patch=$((patch + 1))
53+
new_version="${major}.${minor}.${new_patch}-SNAPSHOT"
54+
sed -i "s|<revision>.*</revision>|<revision>${new_version}</revision>|" pom.xml
55+
echo "Updated version to $new_version"
56+
git config user.name github-actions
57+
git config user.email [email protected]
58+
git add pom.xml
59+
branch_name="${GITHUB_REF#refs/heads/}"
60+
git commit -m "Increment version to ${new_version}" || echo "No changes to commit"
61+
git push origin HEAD:"${branch_name}"
62+
else
63+
echo "Already a -SNAPSHOT version; no bump performed."
64+
fi
65+
updated_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
66+
echo "updated_version=$updated_version" >> $GITHUB_OUTPUT
67+
# Manual settings.xml generation removed; using setup-java injected server credentials.
68+
69+
- name: Deploy snapshot to Artifactory
70+
if: ${{ endsWith(steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version, '-SNAPSHOT') }}
71+
run: |
72+
final_version="${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
73+
echo "Deploying ${final_version} to Artifactory"
74+
mvn -B -ntp -fae \
75+
-Dmaven.install.skip=true -Dmaven.test.skip=true -DdeployAtEnd=true \
76+
-DaltDeploymentRepository=artifactory::${{ env.ARTIFACTORY_URL }} deploy
77+
env:
78+
CAP_DEPLOYMENT_USER: ${{ secrets.CAP_DEPLOYMENT_USER }}
79+
CAP_DEPLOYMENT_PASS: ${{ secrets.CAP_DEPLOYMENT_PASS }}
80+
81+
- name: Verify artifact in Artifactory
82+
if: ${{ endsWith(steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version, '-SNAPSHOT') }}
83+
run: |
84+
group_path="com/sap/cds/sdm"
85+
version="${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
86+
echo "Checking metadata for $version"
87+
curl -u "${{ secrets.CAP_DEPLOYMENT_USER }}:${{ secrets.CAP_DEPLOYMENT_PASS }}" -f -I \
88+
"$ARTIFACTORY_URL/$group_path/$version/maven-metadata.xml" || { echo "Metadata not found"; exit 1; }
89+
echo "Artifact metadata accessible for $version"
90+
- name: Summary
91+
run: |
92+
echo "Revision: ${{ steps.read-revision.outputs.revision }}"
93+
echo "Final version: ${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
94+
echo "Deployment target: ${{ env.ARTIFACTORY_URL }}"

deploy-artifactory.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
########################################
5+
# CONFIGURATION
6+
########################################
7+
JAVA_VERSION="${JAVA_VERSION:-17}"
8+
MAVEN_VERSION="${MAVEN_VERSION:-3.6.3}"
9+
10+
# These MUST come from Jenkins
11+
ARTIFACTORY_URL="${ARTIFACTORY_URL:?ARTIFACTORY_URL is required}"
12+
CAP_DEPLOYMENT_USER="${CAP_DEPLOYMENT_USER:?CAP_DEPLOYMENT_USER is required}"
13+
CAP_DEPLOYMENT_PASS="${CAP_DEPLOYMENT_PASS:?CAP_DEPLOYMENT_PASS is required}"
14+
15+
# Detect branch name (works in Jenkins or Git CLI)
16+
GIT_BRANCH="${GIT_BRANCH:-${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}}"
17+
echo "Running on branch: $GIT_BRANCH"
18+
19+
########################################
20+
# CHECK JAVA & MAVEN
21+
########################################
22+
echo "Checking Java & Maven installations..."
23+
java -version || { echo "❌ Java not found!"; exit 1; }
24+
mvn -v || { echo "❌ Maven not found!"; exit 1; }
25+
26+
########################################
27+
# READ CURRENT VERSION
28+
########################################
29+
echo "Reading current Maven project version..."
30+
current_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
31+
echo "Current version: $current_version"
32+
updated_version="$current_version"
33+
34+
########################################
35+
# BUMP VERSION IF NEEDED
36+
########################################
37+
if [[ "$GIT_BRANCH" == "develop" || "$GIT_BRANCH" == "internal-repo" ]]; then
38+
if [[ "$current_version" != *-SNAPSHOT ]]; then
39+
echo "Version lacks -SNAPSHOT; incrementing patch."
40+
IFS='.' read -r major minor patch <<< "$(echo "$current_version" | tr '-' '.')"
41+
new_patch=$((patch + 1))
42+
new_version="${major}.${minor}.${new_patch}-SNAPSHOT"
43+
sed -i "s|<revision>.*</revision>|<revision>${new_version}</revision>|" pom.xml
44+
echo "Updated version to $new_version"
45+
46+
git config user.name "jenkins-bot"
47+
git config user.email "jenkins@local"
48+
git add pom.xml
49+
git commit -m "Increment version to ${new_version}" || echo "No changes to commit"
50+
git push origin "HEAD:${GIT_BRANCH}"
51+
updated_version="$new_version"
52+
else
53+
echo "Already a -SNAPSHOT version; no bump performed."
54+
fi
55+
else
56+
echo "Branch $GIT_BRANCH not eligible for version bump."
57+
fi
58+
59+
########################################
60+
# DEPLOY SNAPSHOT TO ARTIFACTORY
61+
########################################
62+
if [[ "$updated_version" == *-SNAPSHOT ]]; then
63+
echo "Deploying ${updated_version} to Artifactory..."
64+
mvn -B -ntp -fae \
65+
-Dmaven.install.skip=true \
66+
-Dmaven.test.skip=true \
67+
-DdeployAtEnd=true \
68+
-DaltDeploymentRepository="artifactory::default::${ARTIFACTORY_URL}" \
69+
-Dusername="${CAP_DEPLOYMENT_USER}" \
70+
-Dpassword="${CAP_DEPLOYMENT_PASS}" \
71+
deploy
72+
else
73+
echo "Skipping deploy — not a SNAPSHOT version."
74+
fi
75+
76+
########################################
77+
# VERIFY ARTIFACT IN ARTIFACTORY
78+
########################################
79+
if [[ "$updated_version" == *-SNAPSHOT ]]; then
80+
group_path="com/sap/cds/sdm"
81+
metadata_url="${ARTIFACTORY_URL}/${group_path}/${updated_version}/maven-metadata.xml"
82+
echo "Verifying artifact metadata at: $metadata_url"
83+
84+
curl -u "${CAP_DEPLOYMENT_USER}:${CAP_DEPLOYMENT_PASS}" -f -I "$metadata_url" \
85+
|| { echo "❌ Metadata not found at $metadata_url"; exit 1; }
86+
87+
echo "✅ Artifact metadata accessible for $updated_version"
88+
else
89+
echo "Skipping verification — not a SNAPSHOT version."
90+
fi
91+
92+
########################################
93+
# SUMMARY
94+
########################################
95+
echo "----------------------------------------"
96+
echo "📦 Revision: $current_version"
97+
echo "📦 Final version: $updated_version"
98+
echo "📤 Deployment target: $ARTIFACTORY_URL"
99+
echo "----------------------------------------"

pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,6 @@
348348
</profile>
349349
</profiles>
350350
<distributionManagement>
351-
<!-- <snapshotRepository>
352-
<id>artifactory</id>
353-
<name>Artifactory_DMZ-snapshots</name>
354-
<url>https://common.repositories.cloud.sap/artifactory/cap-sdm-java</url>
355-
</snapshotRepository>
356-
<repository>
357-
<id>artifactory</id>
358-
<name>Artifactory_DMZ</name>
359-
<url>https://common.repositories.cloud.sap/artifactory/cap-sdm-java</url>
360-
</repository> -->
361-
<!-- GitHub Packages Repositories -->
362-
<!-- <repository>
363-
<id>github-release</id>
364-
<name>GitHub Packages</name>
365-
<url>https://maven.pkg.github.com/cap-java/sdm</url>
366-
</repository> -->
367351
<snapshotRepository>
368352
<id>github-snapshot</id>
369353
<name>GitHub Packages Snapshots</name>

0 commit comments

Comments
 (0)