Skip to content

Commit cc0050d

Browse files
committed
ci: update publish
Signed-off-by: Gigi Cheang <gigi.cheang@ibm.com>
1 parent 031a6b9 commit cc0050d

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,21 @@ jobs:
6868
run: |
6969
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.version }}" ]; then
7070
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
71+
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
72+
# When on main branch, get the latest release tag from GitHub
73+
LATEST_TAG=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
74+
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | \
75+
jq -r '.tag_name // empty')
76+
77+
if [ -z "$LATEST_TAG" ]; then
78+
echo "Error: Could not fetch latest release tag from GitHub"
79+
exit 1
80+
fi
81+
82+
echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT
83+
echo "Latest release version: $LATEST_TAG"
7184
else
85+
# For other branches, use the branch/tag name
7286
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
7387
fi
7488
@@ -112,14 +126,48 @@ jobs:
112126
run: |
113127
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ inputs.version }}" ]; then
114128
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
129+
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
130+
# When on main branch, get the latest release tag from GitHub
131+
LATEST_TAG=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
132+
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | \
133+
jq -r '.tag_name // empty')
134+
135+
if [ -z "$LATEST_TAG" ]; then
136+
echo "Error: Could not fetch latest release tag from GitHub"
137+
exit 1
138+
fi
139+
140+
echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT
141+
echo "Latest release version: $LATEST_TAG"
115142
else
143+
# For other branches, use the branch/tag name
116144
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
117145
fi
118146
147+
- name: Check if version exists in Maven Central
148+
id: check_version
149+
run: |
150+
VERSION="${{ steps.version.outputs.version }}"
151+
echo "Checking if version $VERSION exists in Maven Central..."
152+
153+
# Check if the main artifact exists in Maven Central
154+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
155+
"https://repo1.maven.org/maven2/com/ibm/cloud/continuous-delivery/${VERSION}/continuous-delivery-${VERSION}.pom")
156+
157+
if [ "$HTTP_CODE" = "200" ]; then
158+
echo "exists=true" >> $GITHUB_OUTPUT
159+
echo "Version $VERSION already exists in Maven Central. Skipping deployment."
160+
else
161+
echo "exists=false" >> $GITHUB_OUTPUT
162+
echo "Version $VERSION does not exist in Maven Central. Proceeding with deployment."
163+
fi
164+
119165
- name: Set Maven version
166+
if: steps.check_version.outputs.exists == 'false'
120167
run: mvn versions:set -DnewVersion=${{ steps.version.outputs.version }} -DgenerateBackupPoms=false
121168

122169
- name: Deploy to Maven Central
170+
if: steps.check_version.outputs.exists == 'false'
123171
env:
124172
# Required variables and secrets for publishing to Maven Central
125173
# GNU Privacy Guard variables

0 commit comments

Comments
 (0)