Repository navigation
129 lines (112 loc) · 4.13 KB
/
Copy pathcd.yaml
File metadata and controls
129 lines (112 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
name: CD
on:
workflow_dispatch:
pull_request:
types:
- closed
branches:
- main
permissions:
id-token: write
contents: write
packages: write
jobs:
check:
name: check pr status
runs-on: ubuntu-22.04
steps:
- name: check if PR is merged
uses: zmynx/github-actions/.github/actions/git/check-merge@feature/gha
ci:
needs: [check]
name: continuous integration
uses: zmynx/github-actions/.github/workflows/ci-pytest.yaml@feature/gha
secrets: inherit
cd:
name: continuous-deployment
needs: [check, ci]
runs-on: ubuntu-22.04
outputs:
new_tag: ${{ steps.semver.outputs.new_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
## Require permission to write to id-token
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_PROD }}
role-session-name: GitHub-Actions-OIDC
role-duration-seconds: 1200
aws-region: ${{ vars.AWS_REGION }}
- name: Connect to ECR
id: ecr-login
uses: zmynx/github-actions/.github/actions/aws/ecr-login@feature/gha
with:
aws_region: ${{ vars.AWS_REGION }}
- name: Semantic Versioning
id: semver
uses: zmynx/github-actions/.github/actions/git/semver-v2@feature/gha
with:
fallback_version: "${{ format('{0}-{1}', github.base_ref, '1.0.0') }}"
prefix: "${{ format('{0}-', github.base_ref) }}"
## Require permission to write to id-token
- name: Publish
id: publish-to-ecr
uses: zmynx/github-actions/.github/actions/aws/publish-to-ecr@feature/gha
with:
ecr_repo_name: prod.${{ github.event.repository.name }}
ecr_registry: ${{ steps.ecr-login.outputs.registry }}
image_tag: ${{ steps.semver.outputs.new_tag }}
- name: Git Config
uses: zmynx/github-actions/.github/actions/git/git-config@feature/gha
- name: Git Tag
uses: zmynx/github-actions/.github/actions/git/git-tag@feature/gha
with:
tag: "${{ format('{0}-{1}', github.base_ref, steps.semver.outputs.new_tag) }}"
cd-helm:
name: continuous-delivery
needs: [check, ci, cd]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: smipin/gitops
ref: main
token: ${{ secrets.CD_API_KEY }}
fetch-depth: 0
- name: Update application version
run: yq e '.appVersion = "${{ needs.cd.outputs.new_tag }}"' -i charts/${{ github.event.repository.name }}/Chart.yaml
- name: Update chart version
run: yq e '.version = "${{ needs.cd.outputs.new_tag }}"' -i charts/${{ github.event.repository.name }}/Chart.yaml
- name: Git Config
uses: zmynx/github-actions/.github/actions/git/git-config@feature/gha
- name: commit
id: commit
run: |
git add .
git commit -m "Update chart version to ${{ needs.cd.outputs.new_tag }}"
git push origin main
slack:
needs: [ci, cd, cd-helm]
runs-on: ubuntu-22.04
if: always()
steps:
- name: Send slack message
uses: zmynx/github-actions/.github/actions/shared/send-slack-message@feature/gha
with:
result: ${{ needs.cd-helm.result }}
title: "CD result:"
channel: spikerz-pipline
slack_webhook: ${{ secrets.SLACK_WEBHOOK_PROD }}
extra_message: |
${{ needs.cd-helm.result == 'success' && format('✅ *{0}* has been deployed to *prod* environment successfully.', github.event.repository.name) || format('❌ *{0}* has falied to deploy to *prod* environment.', github.event.repository.name) }}
*Version:* ${{ format('{0}-{1}', github.base_ref, needs.cd.outputs.new_tag ) }}
*Commit:* ${{ github.sha }}
*Commit message:* ${{ github.event.pull_request.title }}
*PR merged by:* ${{ github.event.pull_request.merged_by.login }}