forked from cloudquery/cq-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (158 loc) · 6.65 KB
/
test_integration.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
169
170
171
172
173
174
# DONT EDIT. This file is synced from https://github.com/cloudquery/.github/.github
name: test_integration
on:
push:
branches:
- main
repository_dispatch:
types: [test-command]
workflow_dispatch:
pull_request_target:
branches:
- main
env:
CGO_ENABLED: 0
CQ_NO_TELEMETRY: 1
jobs:
ok_to_test:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.manually_approved.outputs.result }}
steps:
- name: Check if was manually approved
id: manually_approved
run: |
manually_approved=${{ github.event_name == 'repository_dispatch' && github.event.client_payload.slash_command.args.named.sha != '' && contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.args.named.sha) }}
echo ::set-output name=result::"$manually_approved"
is_organization_member:
runs-on: ubuntu-latest
outputs:
status: ${{ steps.is_organization_member.outputs.result }}
steps:
- uses: yevgenypats/is-organization-member@646ee210c04d55d8b7f3a591722d06eb16310236
if: github.event_name == 'pull_request_target'
id: is_organization_member
with:
organization: cloudquery
username: ${{ github.event.pull_request.user.login }}
token: ${{ secrets.GH_PAT }}
- name: Skip if not member and event is pull_request_target
if: github.event_name != 'pull_request_target' || steps.is_organization_member.outputs.result == 'false'
run: |
echo "user is not part of org. Please run 'go test -run=TestIntegration -tags=integration ./..'"
echo "and paste the output in the PR"
test_integration:
permissions:
id-token: write
contents: read
needs: [is_organization_member, ok_to_test]
# Allow conditions in order
# 1. is_organization_member - for pull requests from CloudQuery employees
# 2. ok_to_test - for pull requests from external contributors (after manually approved)
# 3. `push` - when merging PRs to the main branch
# 4. `workflow_dispatch` - manually triggered from the GitHub Actions UI
if: |
(github.event_name == 'pull_request_target' && needs.is_organization_member.outputs.status == 'true') ||
(github.event_name == 'repository_dispatch' && needs.ok_to_test.outputs.status == 'true') ||
(github.event_name == 'push') ||
(github.event_name == 'workflow_dispatch')
strategy:
matrix:
dbversion: [ "postgres:10" ]
go: [ "1.18" ]
platform: [ ubuntu-latest ] # can not run in macOS and windowsOS
runs-on: ${{ matrix.platform }}
services:
postgres:
image: ${{ matrix.dbversion }}
env:
POSTGRES_PASSWORD: pass
POSTGRES_USER: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
if: github.event_name == 'pull_request_target'
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Checkout
if: github.event_name == 'repository_dispatch'
uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.slash_command.args.named.sha }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
src:
- '!(terraform/**/*|scripts/**/*)'
- name: Set up Go 1.x
if: steps.changes.outputs.src == 'true' || github.event_name != 'pull_request_target'
uses: actions/setup-go@v3
with:
go-version: ^${{ matrix.go }}
- name: Configure AWS credentials
if: steps.changes.outputs.src == 'true' || github.event_name != 'pull_request_target'
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::707066037989:role/cq-provider-aws-github-action
aws-region: us-east-1
- uses: actions/cache@v3
if: steps.changes.outputs.src == 'true' || github.event_name != 'pull_request_target'
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go }}-
- name: Integration Test
if: steps.changes.outputs.src == 'true' || github.event_name != 'pull_request_target'
run: go test -run=TestIntegration -tags=integration ./...
# The workflow was manually triggered via `ok_to_test` command so we need to update the check manually
- uses: myrotvorets/set-commit-status-action@9d8a3c71eee3231c4a182234c5c204563e5af3ac
if: ${{ github.event_name == 'repository_dispatch' && success() }}
with:
token: ${{ secrets.GH_CQ_BOT }}
status: "success"
sha: "${{ github.event.client_payload.slash_command.args.named.sha }}"
context: "test_integration (${{ matrix.dbversion }}, ${{ matrix.go }}, ${{ matrix.platform }})"
allowForks: true
# The workflow was manually triggered via `ok_to_test` command so we need to update the check manually
- uses: myrotvorets/set-commit-status-action@9d8a3c71eee3231c4a182234c5c204563e5af3ac
if: ${{ github.event_name == 'repository_dispatch' && failure() }}
with:
token: ${{ secrets.GH_CQ_BOT }}
status: "failure"
sha: "${{ github.event.client_payload.slash_command.args.named.sha }}"
context: "test_integration (${{ matrix.dbversion }}, ${{ matrix.go }}, ${{ matrix.platform }})"
allowForks: true
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
if: ${{ github.event_name == 'push' && failure() }}
env:
SLACK_CHANNEL: oss-tests
SLACK_COLOR: ${{ job.status }}
SLACK_MESSAGE: 'aws - E2E tests failed'
SLACK_TITLE: aws - E2E tests failed
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}