|
| 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 github-actions@github.com |
| 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 }}" |
0 commit comments