3
3
push :
4
4
branches :
5
5
- main
6
+ workflow_dispatch :
7
+ inputs :
8
+ build_number :
9
+ description : " The build number to deploy (optional)"
10
+ required : false
11
+ type : string
6
12
jobs :
7
13
build-and-deploy :
8
14
runs-on : ubuntu-latest
@@ -16,23 +22,41 @@ jobs:
16
22
17
23
steps :
18
24
- name : Checkout
25
+ if : ${{ github.event.inputs.build_number == '' }}
19
26
uses : actions/checkout@v4
20
27
- name : JDK
28
+ if : ${{ github.event.inputs.build_number == '' }}
21
29
uses : actions/setup-java@v4
22
30
with :
23
31
distribution : ' temurin'
24
32
java-version : ' 21'
25
33
- name : Generate Build Number
26
34
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
28
42
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
29
- echo "Generated Build Number: $BUILD_NUMBER"
30
43
- name : Login to Docker Hub
31
44
uses : docker/login-action@v3
32
45
with :
33
46
username : ${{ env.DOCKER_USERNAME }}
34
47
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 ✅"
35
58
- name : Maven Clean Verify
59
+ if : ${{ github.event.inputs.build_number == '' }}
36
60
run : mvn -B -ntp clean verify jib:build -Ddocker.image.tag=$BUILD_NUMBER
37
61
- name : Setup SSH Agent
38
62
uses :
webfactory/[email protected]
0 commit comments