-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (140 loc) · 5.35 KB
/
deploy_buddies_ci.yml
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Pipeline CI - Deploy Buddy
on:
pull_request_review:
types: [submitted]
pull_request:
types: [closed]
workflow_dispatch:
jobs:
verify-if-pull-request-is-approved:
runs-on: ubuntu-latest
steps:
- name: Verify if the pull request is approved
if: |
(github.event_name == 'pull_request_review' && github.event.review.state == 'approved') ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true) ||
(github.event_name == 'workflow_dispatch')
run: |
echo "Este PR foi aprovado."
verify-if-pull-request-is-from-development-branch:
needs: verify-if-pull-request-is-approved
runs-on: ubuntu-latest
steps:
- name: Verify if the pull request is sent by the development branch
if: github.event_name == 'pull_request'
run: |
if [[ ${{ github.event.pull_request.head.ref }} == "development" ]]; then
echo "Este PR vem da branch develop."
else
echo "Este PR não vem da branch develop."
exit 1
fi
unit-tests:
needs: verify-if-pull-request-is-from-development-branch
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.22.2'
- name: Run tests and generate coverage report
run: |
cd src/sample-app-test-go
chmod +x run_tests.sh
./run_tests.sh
- name: Upload test report
uses: actions/upload-artifact@v2
with:
name: test-report
path: src/sample-app-test-go/test-report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: src/sample-app-test-go/coverage.html
- name: Upload coverage out file
uses: actions/upload-artifact@v2
with:
name: coverage-out
path: src/sample-app-test-go/coverage.out
build-and-push-image-into-ecr:
needs: unit-tests
# needs: verify-if-pull-request-is-from-development-branch
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Determine IMAGE_TAG
id: set-tag
run: |
if [ "${{ github.event.inputs.action-type }}" == "release" ]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
elif [ "${{ github.event.inputs.action-type }}" == "rollback" ]; then
echo "IMAGE_TAG=rollback" >> $GITHUB_ENV
else
echo "IMAGE_TAG=unknown" >> $GITHUB_ENV
fi
- name: Delete Existing Image
run: |
aws ecr batch-delete-image --repository-name builds --image-ids imageTag=$IMAGE_TAG || echo "No image found with tag $IMAGE_TAG, or deletion not required."
- name: Verifies
run: |
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}"
echo "IMAGE_TAG=$IMAGE_TAG"
- name: Build the Docker image
run: |
docker build -t ${{ steps.login-ecr.outputs.registry }}/builds:$IMAGE_TAG -f src/server/Dockerfile src/server
- name: Push the Docker image to Amazon ECR
run: |
docker push ${{ steps.login-ecr.outputs.registry }}/builds:$IMAGE_TAG
create-github-release:
needs: build-and-push-image-into-ecr
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Install GitHub CLI
run: |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.PERSONAL_ACCESS_TOKEN }}" | gh auth login --with-token
- name: Set Release Tag and Name
id: set-release
run: |
DATE=$(date +'%Y-%m-%d')
VERSION=1
TAG="release-${DATE}-${VERSION}"
# Check if the tag already exists e increment the version number if necessary
while gh release view $TAG > /dev/null 2>&1; do
VERSION=$((VERSION + 1))
TAG="release-${DATE}-${VERSION}"
done
echo "RELEASE_TAG=$TAG" >> $GITHUB_ENV
echo "RELEASE_NAME=Release $DATE-${VERSION}" >> $GITHUB_ENV
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: ${{ env.RELEASE_NAME }}
draft: false
prerelease: false
body: "New release for ${{ env.RELEASE_NAME }}"