1
+ ---
2
+
3
+ # This GitHub Actions workflow is designed to be triggered when a release is marked as a full release.
4
+ # The workflow performs the following tasks:
5
+ # 1. Checks if the tag already exists.
6
+ # 2. Updates the version in the pom.xml file.
7
+ # 3. Commits the changes to the repository.
8
+ # 4. Builds the project using Maven.
9
+ # 5. Runs tests.
10
+ # 6. Tags the commit with the release version.
11
+ # 7. Deploys the artifact to the Maven repository.
12
+ # 8. Builds and publishes a Docker image.
13
+ # 9. Creates a GitHub release.
14
+
15
+ # To make it work for your project, you need to adjust the pom.xml and add configuration file for GitHub release.
16
+ # Please find detailed instructions:
17
+ # https://github.com/Netcracker/qubership-workflow-hub?tab=readme-ov-file#maven-project-release-workflow
18
+
19
+ name : Release And Deploy Maven Artifact
20
+
21
+ on :
22
+ workflow_dispatch :
23
+ inputs :
24
+ version :
25
+ required : true
26
+ default : ' 1.0.0'
27
+ type : string
28
+ description : ' Release version (e.g., 1.0.0)'
29
+ java-version :
30
+ required : false
31
+ type : string
32
+ default : " 21"
33
+ description : ' Java version (e.g., 21)'
34
+ build-docker :
35
+ required : false
36
+ type : boolean
37
+ default : true
38
+ description : ' Release docker image if there is Docker file'
39
+ dry-run :
40
+ required : false
41
+ type : boolean
42
+ default : false
43
+ description : ' Dry run'
44
+
45
+ jobs :
46
+ check-tag :
47
+ runs-on : ubuntu-latest
48
+ steps :
49
+ - name : Input parameters
50
+ run : |
51
+ echo "Version: ${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
52
+ echo "Java version: ${{ github.event.inputs.java-version }}" >> $GITHUB_STEP_SUMMARY
53
+
54
+ - name : Checkout code
55
+ uses : actions/checkout@v4
56
+
57
+ - name : Check if tag exists
58
+ id : check_tag
59
+ uses : netcracker/qubership-workflow-hub/actions/tag-checker@main
60
+ with :
61
+ tag : ' v${{ github.event.inputs.version }}'
62
+ env :
63
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64
+
65
+ - name : Output result
66
+ run : |
67
+ echo "Tag exists: ${{ steps.check_tag.outputs.exists }}"
68
+ echo "Tag name: v${{ github.event.inputs.version }}"
69
+
70
+ - name : Fail if tag exists
71
+ if : steps.check_tag.outputs.exists == 'true'
72
+ run : |
73
+ echo "Tag already exists: v${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
74
+ echo "Tag already exists: v${{ github.event.inputs.version }}"
75
+ exit 1
76
+
77
+ update-pom-version :
78
+ needs : [check-tag]
79
+ runs-on : ubuntu-latest
80
+ outputs :
81
+ artifact_id : ${{ steps.config.outputs.artifact_id }}
82
+ steps :
83
+ - name : Checkout code
84
+ uses : actions/checkout@v4
85
+ with :
86
+ fetch-depth : 0
87
+
88
+ - name : Update pom.xml
89
+ id : config
90
+ uses : netcracker/qubership-workflow-hub/actions/pom-updater@main
91
+ with :
92
+ new_value : ${{ github.event.inputs.version }}
93
+
94
+ - name : Commit Changes
95
+ uses : netcracker/qubership-workflow-hub/actions/commit-and-push@main
96
+ with :
97
+ commit_message : " Update pom.xml version to ${{ github.event.inputs.version }}"
98
+
99
+ mvn-package :
100
+ needs : [update-pom-version]
101
+ uses : netcracker/qubership-workflow-hub/.github/workflows/maven-publish.yml@main
102
+ with :
103
+ maven-command : " --batch-mode package"
104
+ java-version : ${{ github.event.inputs.java-version }}
105
+ upload-artifact : true
106
+ artifact-id : ${{ needs.update-pom-version.outputs.artifact_id }}
107
+ secrets :
108
+ maven-username : ${{ secrets.MAVEN_USER }}
109
+ maven-token : ${{ secrets.MAVEN_PASSWORD }}
110
+ gpg-passphrase : ${{ secrets.MAVEN_GPG_PASSPHRASE }}
111
+ gpg-private-key : ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
112
+
113
+ tests :
114
+ needs : [mvn-package]
115
+ runs-on : ubuntu-latest
116
+ steps :
117
+ - name : Checkout code
118
+ uses : actions/checkout@v4
119
+
120
+ - name : Run tests
121
+ run : echo "Running tests here"
122
+
123
+ tag :
124
+ needs : [tests]
125
+ uses : netcracker/qubership-workflow-hub/.github/workflows/tag-creator.yml@main
126
+ with :
127
+ tag-name : " v${{ github.event.inputs.version }}"
128
+
129
+ mvn-deploy :
130
+ needs : [update-pom-version, tag]
131
+ uses : netcracker/qubership-workflow-hub/.github/workflows/maven-publish.yml@main
132
+ with :
133
+ maven-command : ${{ (github.event.inputs.dry-run == 'true' && '--batch-mode package') || '--batch-mode deploy' }}
134
+ java-version : ${{ github.event.inputs.java-version }}
135
+ upload-artifact : false
136
+ artifact-id : ${{ needs.update-pom-version.outputs.artifact_id }}
137
+ server-id : " central"
138
+ secrets :
139
+ maven-username : ${{ secrets.MAVEN_USER }}
140
+ maven-token : ${{ secrets.MAVEN_PASSWORD }}
141
+ gpg-passphrase : ${{ secrets.MAVEN_GPG_PASSPHRASE }}
142
+ gpg-private-key : ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
143
+
144
+ check-dockerfile :
145
+ runs-on : ubuntu-latest
146
+ needs : [update-pom-version, tag]
147
+ outputs :
148
+ dockerfile_exists : ${{ steps.check_dockerfile.outputs.df_exists }}
149
+ steps :
150
+ - uses : actions/checkout@v4
151
+ - name : " Check Dockerfile existence"
152
+ id : check_dockerfile
153
+ shell : bash
154
+ run : |
155
+ if [[ -f Dockerfile ]]; then
156
+ echo "df_exists=exists" >> "$GITHUB_OUTPUT"
157
+ else
158
+ echo "Dockerfile does not exist. Docker build stage will be skipped"
159
+ echo "df_exists=notexists" >> "$GITHUB_OUTPUT"
160
+ fi
161
+ echo "GITHUB_OUTPUT:"
162
+ cat "$GITHUB_OUTPUT"
163
+
164
+ docker-build-publish :
165
+ needs : [update-pom-version, tag, check-dockerfile]
166
+ if : ${{ github.event.inputs.build-docker == 'true' && needs.check-dockerfile.outputs.dockerfile_exists == 'exists' }}
167
+ uses : netcracker/qubership-workflow-hub/.github/workflows/docker-publish.yml@main
168
+ with :
169
+ ref : " v${{ github.event.inputs.version }}"
170
+ artifact-id : ${{ needs.update-pom-version.outputs.artifact_id }}
171
+ dry-run : ${{ inputs.dry-run }}
172
+ download-artifact : true
173
+
174
+ github-release :
175
+ needs : [tag]
176
+ uses : netcracker/qubership-workflow-hub/.github/workflows/release-drafter.yml@main
177
+ with :
178
+ version : ${{ github.event.inputs.version }}
179
+ publish : false
0 commit comments