1
+ version : " 1.0"
2
+ stages :
3
+ - clone
4
+ - prepare
5
+ - build
6
+ - test
7
+ - release
8
+ steps :
9
+
10
+ main_clone :
11
+ title : ' Cloning main repository...'
12
+ stage : clone
13
+ type : git-clone
14
+ repo : ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
15
+ revision : ${{CF_BRANCH}}
16
+ git : ${{GIT_CONTEXT}}
17
+
18
+ prepare_env_vars :
19
+ title : ' Preparing environment variables...'
20
+ stage : prepare
21
+ image : codefreshio/ci-helpers
22
+ working_directory : ${{main_clone}}
23
+ commands :
24
+ - cf_export SERVICE_VERSION=$(yq r service.yaml version)
25
+ - cf_export IMAGE_NAME=codefresh/cf-git-cloner
26
+
27
+ validate_version :
28
+ title : ' Validating the service version...'
29
+ stage : prepare
30
+ image : codefreshio/ci-helpers
31
+ fail_fast : false
32
+ commands :
33
+ - |
34
+ err() { echo -e "\e[31m$@\e[0m" ; return 1 ; }
35
+ ok() { echo -e "\e[32m$@\e[0m" ; return 0 ; }
36
+
37
+ current_version=${SERVICE_VERSION}
38
+ last_version=$(git describe --abbrev=0 --tags)
39
+ echo "Current version is $current_version, last version - $last_version"
40
+ semver-cli greater $current_version $last_version && ok "Version check ok" || err "Please the update the version in the service.yaml file"
41
+
42
+ build_image :
43
+ title : " Building the image..."
44
+ stage : build
45
+ type : build
46
+ working_directory : ${{main_clone}}
47
+ dockerfile : ./Dockerfile
48
+ image_name : ${{IMAGE_NAME}}
49
+ tag : ${{CF_BRANCH_TAG_NORMALIZED}}
50
+
51
+ approve_existing_version_update :
52
+ type : pending-approval
53
+ stage : release
54
+ title : " Are you sure you want to update already existing image version?"
55
+ description : |
56
+ "Used for reverting changes without raising the service version"
57
+ when :
58
+ branch :
59
+ only : [master]
60
+ steps :
61
+ - name : validate_version
62
+ on :
63
+ - failure
64
+
65
+ release :
66
+ type : parallel
67
+ stage : release
68
+ steps :
69
+
70
+ add_git_tag :
71
+ title : " Adding Git tag..."
72
+ stage : release
73
+ image : codefreshio/ci-helpers
74
+ commands :
75
+ - source /get-token/get-gh-token.sh
76
+ - |
77
+ curl --fail -X POST -d '{"ref": "refs/tags/${{SERVICE_VERSION}}","sha": "${{CF_REVISION}}"}' -H "Content-Type: application/json" -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}/git/refs
78
+ when :
79
+ branch :
80
+ only : [master]
81
+ steps :
82
+ - name : validate_version
83
+ on :
84
+ - success
85
+
86
+ push_image_prod :
87
+ type : push
88
+ title : " Pushing the image to the public registry..."
89
+ stage : release
90
+ image_name : ' ${{IMAGE_NAME}}'
91
+ registry : " ${{REGISTRY_INTEGRATION}}"
92
+ candidate : " ${{build_image}}"
93
+ tags :
94
+ - " ${{SERVICE_VERSION}}"
95
+ - " latest"
96
+ when :
97
+ branch :
98
+ only : [master]
0 commit comments