Skip to content
94 changes: 94 additions & 0 deletions .github/workflows/internalArticatory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Internal Artifactory snapshot deploy

env:
JAVA_VERSION: '17'
MAVEN_VERSION: '3.6.3'
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}

on:
workflow_dispatch:
jobs:
build-and-deploy-artifactory:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: sapmachine
cache: maven
server-id: artifactory
server-username: CAP_DEPLOYMENT_USER
server-password: CAP_DEPLOYMENT_PASS
env:
CAP_DEPLOYMENT_USER: ${{ secrets.CAP_DEPLOYMENT_USER }}
CAP_DEPLOYMENT_PASS: ${{ secrets.CAP_DEPLOYMENT_PASS }}

- name: Set up Maven ${{ env.MAVEN_VERSION }}
uses: stCarolas/setup-maven@v5
with:
maven-version: ${{ env.MAVEN_VERSION }}

- name: Read current revision
id: read-revision
run: |
current_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
echo "Current version: $current_version"
echo "revision=$current_version" >> $GITHUB_OUTPUT
echo "updated_version=$current_version" >> $GITHUB_OUTPUT
- name: Bump version if needed
id: bump-version
# if: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/jenkins' }}
run: |
current_version="${{ steps.read-revision.outputs.revision }}"
if [[ $current_version != *-SNAPSHOT ]]; then
echo "Version lacks -SNAPSHOT; incrementing patch."
IFS='.' read -r major minor patch <<< "$(echo $current_version | tr '-' '.')"
new_patch=$((patch + 1))
new_version="${major}.${minor}.${new_patch}-SNAPSHOT"
sed -i "s|<revision>.*</revision>|<revision>${new_version}</revision>|" pom.xml
echo "Updated version to $new_version"
git config user.name github-actions
git config user.email github-actions@github.com
git add pom.xml
branch_name="${GITHUB_REF#refs/heads/}"
git commit -m "Increment version to ${new_version}" || echo "No changes to commit"
git push origin HEAD:"${branch_name}"
else
echo "Already a -SNAPSHOT version; no bump performed."
fi
updated_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
echo "updated_version=$updated_version" >> $GITHUB_OUTPUT
# Manual settings.xml generation removed; using setup-java injected server credentials.

- name: Deploy snapshot to Artifactory
if: ${{ endsWith(steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version, '-SNAPSHOT') }}
run: |
final_version="${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
echo "Deploying ${final_version} to Artifactory"
mvn -B -ntp -fae \
-Dmaven.install.skip=true -Dmaven.test.skip=true -DdeployAtEnd=true \
-DaltDeploymentRepository=artifactory::${{ env.ARTIFACTORY_URL }} deploy
env:
CAP_DEPLOYMENT_USER: ${{ secrets.CAP_DEPLOYMENT_USER }}
CAP_DEPLOYMENT_PASS: ${{ secrets.CAP_DEPLOYMENT_PASS }}

- name: Verify artifact in Artifactory
if: ${{ endsWith(steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version, '-SNAPSHOT') }}
run: |
group_path="com/sap/cds/sdm"
version="${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
echo "Checking metadata for $version"
curl -u "${{ secrets.CAP_DEPLOYMENT_USER }}:${{ secrets.CAP_DEPLOYMENT_PASS }}" -f -I \
"$ARTIFACTORY_URL/$group_path/$version/maven-metadata.xml" || { echo "Metadata not found"; exit 1; }
echo "Artifact metadata accessible for $version"
- name: Summary
run: |
echo "Revision: ${{ steps.read-revision.outputs.revision }}"
echo "Final version: ${{ steps.bump-version.outputs.updated_version || steps.read-revision.outputs.updated_version }}"
echo "Deployment target: ${{ env.ARTIFACTORY_URL }}"
99 changes: 99 additions & 0 deletions deploy-artifactory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
set -euo pipefail

########################################
# CONFIGURATION
########################################
JAVA_VERSION="${JAVA_VERSION:-17}"
MAVEN_VERSION="${MAVEN_VERSION:-3.6.3}"

# These MUST come from Jenkins
ARTIFACTORY_URL="${ARTIFACTORY_URL:?ARTIFACTORY_URL is required}"
CAP_DEPLOYMENT_USER="${CAP_DEPLOYMENT_USER:?CAP_DEPLOYMENT_USER is required}"
CAP_DEPLOYMENT_PASS="${CAP_DEPLOYMENT_PASS:?CAP_DEPLOYMENT_PASS is required}"

# Detect branch name (works in Jenkins or Git CLI)
GIT_BRANCH="${GIT_BRANCH:-${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD)}}"
echo "Running on branch: $GIT_BRANCH"

########################################
# CHECK JAVA & MAVEN
########################################
echo "Checking Java & Maven installations..."
java -version || { echo "❌ Java not found!"; exit 1; }
mvn -v || { echo "❌ Maven not found!"; exit 1; }

########################################
# READ CURRENT VERSION
########################################
echo "Reading current Maven project version..."
current_version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)
echo "Current version: $current_version"
updated_version="$current_version"

########################################
# BUMP VERSION IF NEEDED
########################################
if [[ "$GIT_BRANCH" == "develop" || "$GIT_BRANCH" == "internal-repo" ]]; then
if [[ "$current_version" != *-SNAPSHOT ]]; then
echo "Version lacks -SNAPSHOT; incrementing patch."
IFS='.' read -r major minor patch <<< "$(echo "$current_version" | tr '-' '.')"
new_patch=$((patch + 1))
new_version="${major}.${minor}.${new_patch}-SNAPSHOT"
sed -i "s|<revision>.*</revision>|<revision>${new_version}</revision>|" pom.xml
echo "Updated version to $new_version"

git config user.name "jenkins-bot"
git config user.email "jenkins@local"
git add pom.xml
git commit -m "Increment version to ${new_version}" || echo "No changes to commit"
git push origin "HEAD:${GIT_BRANCH}"
updated_version="$new_version"
else
echo "Already a -SNAPSHOT version; no bump performed."
fi
else
echo "Branch $GIT_BRANCH not eligible for version bump."
fi

########################################
# DEPLOY SNAPSHOT TO ARTIFACTORY
########################################
if [[ "$updated_version" == *-SNAPSHOT ]]; then
echo "Deploying ${updated_version} to Artifactory..."
mvn -B -ntp -fae \
-Dmaven.install.skip=true \
-Dmaven.test.skip=true \
-DdeployAtEnd=true \
-DaltDeploymentRepository="artifactory::default::${ARTIFACTORY_URL}" \
-Dusername="${CAP_DEPLOYMENT_USER}" \
-Dpassword="${CAP_DEPLOYMENT_PASS}" \
deploy
else
echo "Skipping deploy — not a SNAPSHOT version."
fi

########################################
# VERIFY ARTIFACT IN ARTIFACTORY
########################################
if [[ "$updated_version" == *-SNAPSHOT ]]; then
group_path="com/sap/cds/sdm"
metadata_url="${ARTIFACTORY_URL}/${group_path}/${updated_version}/maven-metadata.xml"
echo "Verifying artifact metadata at: $metadata_url"

curl -u "${CAP_DEPLOYMENT_USER}:${CAP_DEPLOYMENT_PASS}" -f -I "$metadata_url" \
|| { echo "❌ Metadata not found at $metadata_url"; exit 1; }

echo "✅ Artifact metadata accessible for $updated_version"
else
echo "Skipping verification — not a SNAPSHOT version."
fi

########################################
# SUMMARY
########################################
echo "----------------------------------------"
echo "📦 Revision: $current_version"
echo "📦 Final version: $updated_version"
echo "📤 Deployment target: $ARTIFACTORY_URL"
echo "----------------------------------------"
16 changes: 0 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,6 @@
</profile>
</profiles>
<distributionManagement>
<!-- <snapshotRepository>
<id>artifactory</id>
<name>Artifactory_DMZ-snapshots</name>
<url>https://common.repositories.cloud.sap/artifactory/cap-sdm-java</url>
</snapshotRepository>
<repository>
<id>artifactory</id>
<name>Artifactory_DMZ</name>
<url>https://common.repositories.cloud.sap/artifactory/cap-sdm-java</url>
</repository> -->
<!-- GitHub Packages Repositories -->
<!-- <repository>
<id>github-release</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/cap-java/sdm</url>
</repository> -->
<snapshotRepository>
<id>github-snapshot</id>
<name>GitHub Packages Snapshots</name>
Expand Down
Loading