-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (161 loc) · 5.37 KB
/
main.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
name: build-container
on:
push:
branches:
- '**'
tags:
- 'v*'
jobs:
test:
runs-on: ubuntu-24.04
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: sidecar
POSTGRES_USER: sidecar
POSTGRES_PASSWORD: sidecar
ports:
- 5432:5432
# Add health check to ensure postgres is ready before running tests
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: make deps
- name: Run tests
env: # Pass the database connection details to the tests
SIDECAR_DATABASE_HOST: localhost
SIDECAR_DATABASE_PORT: 5432
SIDECAR_DATABASE_USER: sidecar
SIDECAR_DATABASE_PASSWORD: sidecar
run: make ci-test
lint:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run linter
run: |
make deps
go env GOPATH
export PATH=$PATH:$(go env GOPATH)/bin
echo $PATH
make lint
build-container:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set release version
env:
REF: ${{ github.ref }}
run: |
if [[ $REF == refs/tags/* ]]; then
echo -n "${REF#refs/tags/}" > .release_version
else
v=$(git rev-parse --short HEAD) && echo -n $v > .release_version
fi
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: "public.ecr.aws/z6g0f8n7"
REPOSITORY: ${{ github.event.repository.name }}
run: |
VERSION=$(cat .release_version)
if [[ $GITHUB_REF == refs/heads/master || $GITHUB_REF == refs/tags/* ]]; then
docker buildx build --platform "linux/amd64,linux/arm64" -t $REGISTRY/$REPOSITORY:$VERSION -t $REGISTRY/$REPOSITORY:latest --push .
else
docker buildx build --platform "linux/amd64" -t $REGISTRY/$REPOSITORY:$VERSION --push .
fi
build-create-release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [build-container, lint, test]
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set release version
env:
REF: ${{ github.ref }}
run: |
if [[ $REF == refs/tags/* ]]; then
echo -n "${REF#refs/tags/}" > .release_version
else
v=$(git rev-parse --short HEAD) && echo -n $v > .release_version
fi
- name: Build binary
run: |
VERSION=$(cat .release_version)
echo "Building binary for version $VERSION"
make release
./scripts/bundleReleases.sh $VERSION
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BUCKET_NAME: ${{ vars.RELEASE_BUCKET_NAME }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
REF: ${{ github.ref }}
run: |
set -x
ls -al ./release
echo "Upload URL: ${{ steps.create_release.outputs.upload_url }}"
export upload_url=$(echo "${{ steps.create_release.outputs.upload_url }}" | sed -e "s/{?name,label}//")
for asset_name in $(ls ./release | grep '.tar');
do
asset="./release/${asset_name}"
echo "Uploading ${asset_name}..."
curl --fail \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: $(file -b --mime-type "$asset")" \
--data-binary @"$asset" \
"${upload_url}?name=$asset_name"
done
release-helm-chart:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs: [lint, test]
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Release Helm Chart
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
run: |
./scripts/releaseChart.sh