1
+ name : CI/CD Release Pipeline
2
+ on :
3
+ workflow_dispatch :
4
+ inputs :
5
+ environment :
6
+ description : ' Select environment target'
7
+ required : true
8
+ type : choice
9
+ options :
10
+ - prod
11
+ release_version :
12
+ description : ' Specify the release version (e.g., 1.2.3) or leave blank for automatic increment'
13
+ required : false
14
+ type : string
15
+
16
+ jobs :
17
+ pre-release :
18
+ environment : ${{ github.event.inputs.environment }}
19
+ runs-on : ubuntu-latest
20
+ outputs :
21
+ release_tag : ${{ steps.release_version.outputs.version }}
22
+ steps :
23
+ - name : Checkout code
24
+ uses : actions/checkout@v3
25
+ with :
26
+ ref : ${{ github.ref }}
27
+
28
+ - name : Set up Git
29
+ run : |
30
+ git config --global user.name "GitHub Actions"
31
+ git config --global user.email "actions@github.com"
32
+
33
+ - name : Determine Release Version
34
+ id : release_version
35
+ env :
36
+ RELEASE_VERSION : ${{ github.event.inputs.release_version }}
37
+ run : |
38
+ echo "version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
39
+
40
+ iac :
41
+ needs : pre-release
42
+ uses : ./.github/workflows/iac.yaml
43
+ permissions :
44
+ id-token : write
45
+ contents : read
46
+ with :
47
+ environment : ${{ github.event.inputs.environment }}
48
+ working_directory : ./iac/${{ github.event.inputs.environment }}
49
+ cloud_resource_name : ${{ github.event.repository.name }}
50
+ terraform_version : 1.9.8
51
+ terragrunt_version : 0.68.10
52
+ secrets : inherit
53
+
54
+ ci :
55
+ needs : [iac, pre-release]
56
+ uses : ./.github/workflows/ci.yaml
57
+ permissions :
58
+ id-token : write
59
+ contents : read
60
+ with :
61
+ environment : ${{ github.event.inputs.environment }}
62
+ working_directory : ./
63
+ ecr_repository : ${{ github.event.repository.name }}
64
+ image_version : ${{ needs.pre-release.outputs.release_tag }}
65
+ secrets : inherit
66
+
67
+ cd :
68
+ needs : [ci]
69
+ uses : ./.github/workflows/cd.yaml
70
+ permissions :
71
+ id-token : write
72
+ contents : write
73
+ with :
74
+ environment : ${{ github.event.inputs.environment }}
75
+ working_directory : ./k8s
76
+ image : ${{ needs.ci.outputs.image_output }}
77
+ secrets : inherit
78
+
79
+ release :
80
+ needs : [ cd, pre-release]
81
+ environment : ${{ github.event.inputs.environment }}
82
+ permissions :
83
+ contents : write
84
+ runs-on : ubuntu-latest
85
+ steps :
86
+ - name : Checkout code
87
+ uses : actions/checkout@v3
88
+ with :
89
+ ref : ${{ github.ref }}
90
+ fetch-depth : 0
91
+
92
+ - name : Set up Git
93
+ run : |
94
+ git config --global user.name "GitHub Actions"
95
+ git config --global user.email "actions@github.com"
96
+
97
+ - name : Create Tag and Push
98
+ env :
99
+ VERSION : ${{ needs.pre-release.outputs.release_tag }}
100
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
101
+ run : |
102
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
103
+ echo "Current branch: $CURRENT_BRANCH"
104
+ # Create the tag
105
+ git tag -a "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}"
106
+ # Push the tag only
107
+ git push origin "refs/tags/${{ env.VERSION }}"
108
+ #git push origin "refs/tags/${{ env.VERSION }}" $CURRENT_BRANCH # for updating main branch
109
+
110
+ - name : Install GitHub CLI
111
+ run : |
112
+ sudo apt-get update
113
+ sudo apt-get install -y gh
114
+
115
+ - name : Create GitHub Release
116
+ env :
117
+ VERSION : ${{ needs.pre-release.outputs.release_tag }}
118
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
119
+ run : |
120
+ gh release create "${{ env.VERSION }}" --notes "Release ${{ env.VERSION }}"
0 commit comments