Skip to content

Commit b601860

Browse files
add workflow dispatch build number as input
1 parent 3b9d1a9 commit b601860

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ on:
33
push:
44
branches:
55
- main
6+
workflow_dispatch:
7+
inputs:
8+
build_number:
9+
description: "The build number to deploy (optional)"
10+
required: false
11+
type: string
612
jobs:
713
build-and-deploy:
814
runs-on: ubuntu-latest
@@ -16,23 +22,41 @@ jobs:
1622

1723
steps:
1824
- name: Checkout
25+
if: ${{ github.event.inputs.build_number == '' }}
1926
uses: actions/checkout@v4
2027
- name: JDK
28+
if: ${{ github.event.inputs.build_number == '' }}
2129
uses: actions/setup-java@v4
2230
with:
2331
distribution: 'temurin'
2432
java-version: '21'
2533
- name: Generate Build Number
2634
run: |
27-
BUILD_NUMBER=$(date +'%d%m%Y%H%M%S')
35+
if [ -n "${{ github.event.inputs.build_number }}"]; then
36+
BUILD_NUMBER = ${{ github.event.inputs.build_number }}
37+
echo "using provided build number: $BUILD_NUMBER"
38+
else
39+
BUILD_NUMBER=$(date +'%d%m%Y%H%M%S')
40+
echo "using generated build number: $BUILD_NUMBER"
41+
fi
2842
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
29-
echo "Generated Build Number: $BUILD_NUMBER"
3043
- name: Login to Docker Hub
3144
uses: docker/login-action@v3
3245
with:
3346
username: ${{ env.DOCKER_USERNAME }}
3447
password: ${{ env.DOCKER_PASSWORD }}
48+
- name: Check if provided docker image exists
49+
if: ${{ github.event.inputs.build_number != '' }}
50+
run: |
51+
IMAGE_NAME="${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:$BUILD_NUMBER"
52+
echo "checking if $IMAGE_NAME exists"
53+
if ! docker manifest inspect "$IMAGE_NAME" > /dev/null 2>&1; then
54+
echo "provided image $IMAGE_NAME does not exits. exiting..."
55+
exit 1
56+
fi
57+
echo "provided image $IMAGE_NAME exits ✅"
3558
- name: Maven Clean Verify
59+
if: ${{ github.event.inputs.build_number == '' }}
3660
run: mvn -B -ntp clean verify jib:build -Ddocker.image.tag=$BUILD_NUMBER
3761
- name: Setup SSH Agent
3862
uses: webfactory/[email protected]

0 commit comments

Comments
 (0)