forked from cloudquery/cloudquery
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (171 loc) · 6.27 KB
/
source_aws.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
175
name: Source Plugin AWS Workflow
on:
pull_request:
paths:
- "plugins/source/aws/**"
- ".github/workflows/source_aws.yml"
push:
branches:
- main
paths:
- "plugins/source/aws/**"
- ".github/workflows/source_aws.yml"
jobs:
resolve-runner:
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.resolve.outputs.runner }}
steps:
- name: Check if should use large runner
id: large-runner
# We want to speed runs on the main branch which prime the cache
# We allow large runners only in this case to prevent forks from abusing them (it's enforced via runner groups access rules)
# IF YOU WANT TO USE A LARGE RUNNER YOU NEED TO ADD THE WORKFLOW TO THE `CloudQuery releases` GROUP IN https://github.com/organizations/cloudquery/settings/actions/runner-groups
if: github.event_name == 'push'
run: |
echo "runner=cloudquery-release-runner" >> $GITHUB_OUTPUT
- name: Resolve runner
id: resolve
run: |
RUNNER=${{ steps.large-runner.outputs.runner }}
echo "runner=${RUNNER:-"ubuntu-latest"}" >> $GITHUB_OUTPUT
plugins-source-aws:
timeout-minutes: 45
name: "plugins/source/aws"
needs: [resolve-runner]
permissions:
id-token: write
contents: read
runs-on: ${{ needs.resolve-runner.outputs.runner }}
defaults:
run:
working-directory: ./plugins/source/aws
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up Go 1.x
uses: erezrokah/setup-go@feat/add_cache_prefix
with:
go-version-file: plugins/source/aws/go.mod
cache: true
cache-dependency-path: plugins/source/aws/go.sum
cache-key-prefix: test-cache-
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
working-directory: plugins/source/aws
args: "--config ../../.golangci.yml"
skip-pkg-cache: true
skip-build-cache: true
- name: Get dependencies
run: go get -t -d ./...
- name: gen
if: github.event_name == 'pull_request'
run: make gen
- name: Fail if generation updated files
if: github.event_name == 'pull_request'
run: test "$(git status -s | wc -l)" -eq 0 || (git status -s; exit 1)
- name: Build
run: go build .
- name: Test
run: make test
# Sanity integration test, only for release PRs
- name: Setup CloudQuery
if: startsWith(github.head_ref, 'release-please--branches--main--components')
uses: cloudquery/setup-cloudquery@v3
with:
version: 'v3.5.0'
- name: Configure AWS credentials
if: startsWith(github.head_ref, 'release-please--branches--main--components')
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: arn:aws:iam::615713231484:role/cq-playground-aws-github-action
aws-region: us-east-1
- name: Run sync
if: startsWith(github.head_ref, 'release-please--branches--main--components')
run: cloudquery sync test/sanity.yml --log-console
validate-release:
timeout-minutes: 60
needs: [resolve-runner]
runs-on: ${{ needs.resolve-runner.outputs.runner }}
env:
CGO_ENABLED: 0
steps:
- name: Checkout
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
uses: actions/checkout@v3
- uses: actions/cache@v3
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-1.19.5-release-cache-${{ hashFiles('plugins/source/aws/go.sum') }}
restore-keys: |
${{ runner.os }}-go-1.19.5-release-cache-plugins-source-aws
- name: Set up Go
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
uses: actions/setup-go@v3
with:
go-version-file: plugins/source/aws/go.mod
- name: Install GoReleaser
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser-pro
version: latest
install-only: true
- name: Run GoReleaser Dry-Run
if: startsWith(github.head_ref, 'release-please--branches--main--components') || github.event_name == 'push'
run: goreleaser release --timeout 50m --snapshot --clean --skip-validate --skip-publish --skip-sign -f ./plugins/source/aws/.goreleaser.yaml
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
test-policies:
timeout-minutes: 30
needs: [resolve-runner]
runs-on: ${{ needs.resolve-runner.outputs.runner }}
defaults:
run:
working-directory: ./plugins/source/aws
services:
postgres:
image: postgres:11
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
uses: actions/checkout@v3
- name: Set up Go 1.x
uses: erezrokah/setup-go@feat/add_cache_prefix
with:
go-version-file: plugins/source/aws/go.mod
cache: true
cache-dependency-path: plugins/source/aws/go.sum
cache-key-prefix: policies-cache-
- name: Build
run: go build .
- name: Setup CloudQuery
uses: cloudquery/setup-cloudquery@v3
with:
version: 'v3.5.0'
- name: Migrate DB
run: cloudquery migrate test/policy_cq_config.yml
env:
CQ_DSN: postgresql://postgres:pass@localhost:5432/postgres
- name: Run all policies
run: cd policies && psql -h localhost -p 5432 -U postgres -d postgres -w -f ./policy.sql
env:
PGPASSWORD: pass