-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (100 loc) · 4.74 KB
/
Copy pathinternalArticatory.yml
File metadata and controls
107 lines (100 loc) · 4.74 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
name: Internal Artifactory snapshot deploy
env:
JAVA_VERSION: '21'
MAVEN_VERSION: '3.6.3'
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
on:
workflow_dispatch:
inputs:
deploy_branch:
description: 'Specify the branch foe which snapshot required'
required: true
jobs:
build-and-deploy-artifactory:
environment: maven-central
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.deploy_branch }}
- 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') }}
env:
CAP_DEPLOYMENT_USER: ${{ secrets.CAP_DEPLOYMENT_USER }}
CAP_DEPLOYMENT_PASS: ${{ secrets.CAP_DEPLOYMENT_PASS }}
run: |
set +x
echo "::add-mask::$CAP_DEPLOYMENT_USER"
echo "::add-mask::$CAP_DEPLOYMENT_PASS"
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 "$CAP_DEPLOYMENT_USER:$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 }}"