-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (115 loc) · 3.53 KB
/
ci-go.yaml
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
name: CI (Go)
on:
push:
workflow_dispatch:
jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.21"
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Go linters
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=15m --verbose --enable whitespace,gocritic,goimports,revive
skip-pkg-cache: true
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.21"
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: |
curl -sSf 'https://atlasgo.sh?test=1' | env ATLAS_DEBUG=true sh
- name: Run tests
run: |
go test -race ./...
integration-tests:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build
uses: docker/build-push-action@v2
with:
context: .
file: ./.github/workflows/Dockerfile
tags: local
load: true
- run: docker images
- name: sanity
id: sanity
uses: ./internal/action
with:
url: sqlite://internal/testdata/test.db
cloud-dir: deploy-action-test
cloud-token: ${{ secrets.ATLAS_CLOUD_TEST_TOKEN }}
- name: Check Error and Compare Current with Target
run: |
error_output="${{ steps.sanity.outputs.error }}"
pending_output="${{ steps.sanity.outputs.pending_count }}"
applied_output="${{ steps.sanity.outputs.applied_count }}"
# Check that the "error" output is empty
if [ -z "$error_output" ]; then
echo "No error occurred in the action."
else
echo "Error occurred: $error_output"
exit 1
fi
# Check that the "pending" output "0"
if [ "$pending_output" -eq "0" ]; then
echo "No pending migrations."
else
echo "Pending migrations: $pending_output"
exit 1
fi
# Check that the "applied" output is "0"
if [ "$applied_output" -eq "0" ]; then
echo "No migrations applied."
else
echo "Migrations applied: $applied_output"
exit 1
fi
docker:
runs-on: ubuntu-latest
needs: [golangci-lint, unit-tests, integration-tests]
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
file: ./.github/workflows/Dockerfile
tags: arigaio/atlas-deploy-action:latest