-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (92 loc) · 3.5 KB
/
deploy.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
name: CI/CD
on: [push]
jobs:
test:
runs-on: ubuntu-latest
name: Test CopyCat
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Test CopyCat
run: go test -v ./...
env:
DUMMY_HOST: ${{ secrets.TESTING_HOST }}
DUMMY_KEY: ${{ secrets.TESTING_KEY }}
DUMMY_SECRET: ${{ secrets.TESTING_SECRET }}
DUMMY_BUCKET: ${{ secrets.TESTING_BUCKET }}
DUMMY_REGION: ${{ secrets.TESTING_REGION }}
conditional_check:
runs-on: ubuntu-latest
name: Conditional check
outputs:
src_changed: ${{ steps.check_src_changed.outputs.src_changed }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Check for source file changes
shell: pwsh
id: check_src_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD
# Check if a go file has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '.go$' }
$HasDiff = $SourceDiff.Length -gt 0
echo $HasDiff
echo "src_changed=$HasDiff" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [test]
name: Build binaries
if: ${{ needs.conditional_check.outputs.src_changed }} == 'True'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build CopyCat
run: |
make build-all
env:
VERSION_LOG: ${{ secrets.COPYCAT_VERSION_PATH }}
VERSION_HOST: ${{ secrets.COPYCAT_VERSION_HOST }}
- name: Set version tag
run: go run ./... version-clean > CURRENT_VERSION
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: copycat-release
path: |
bin
CURRENT_VERSION
deploy:
runs-on: ubuntu-latest
needs: [build]
name: Deploy CopyCat
if: ${{ needs.conditional_check.outputs.src_changed }} == 'True'
steps:
- name: Download copycat build
uses: actions/download-artifact@v3
with:
name: copycat-release
- name: Deploy to S3
run: |
old_version=$(cat CURRENT_VERSION)
aws s3 --recursive mv ${{ secrets.AWS_ROOT_BUCKET }}/latest/ ${{ secrets.AWS_ROOT_BUCKET }}/${old_version}/
aws s3 mv ${{ secrets.AWS_ROOT_BUCKET }}/CURRENT_VERSION ${{ secrets.AWS_ROOT_BUCKET }}/${old_version}/
aws s3 sync ./bin ${{ secrets.AWS_ROOT_BUCKET }}/latest/
aws s3 cp CURRENT_VERSION ${{ secrets.AWS_ROOT_BUCKET }}/
aws s3api put-object-tagging --bucket ${{ secrets.AWS_BUCKET_NAME }} --key ${{ secrets.AWS_ROOT_PATH }}/CURRENT_VERSION --tagging ${{ secrets.AWS_OBJECT_TAGGING }}
aws s3api list-objects --bucket ${{ secrets.AWS_BUCKET_NAME }} --query 'Contents[].{Key:Key}' --prefix ${{ secrets.AWS_ROOT_PATH }}/latest --output text | xargs -n 1 aws s3api put-object-tagging --bucket ${{ secrets.AWS_BUCKET_NAME }} --tagging ${{ secrets.AWS_OBJECT_TAGGING }} --key
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
VERSION_LOG: ${{ secrets.DEPLOY_VERS_LOG }}
VERSION_HOST: ${{ secrets.DEPLOY_VERS_HOST }}