generated from overmindtech/source-template
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (131 loc) · 4.74 KB
/
test-build.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
name: Test & Build
on: push
jobs:
test:
name: Test
runs-on: depot-ubuntu-22.04-8
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.x
check-latest: true
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Go Generate
run: go generate ./...
- name: Vet
run: go vet ./...
# get .golangci.yml from github.com/overmindtech/golangci-lint_config
- name: Get .golangci.yml from github.com/overmindtech/golangci-lint_configs
run: |
curl -sfL https://raw.githubusercontent.com/overmindtech/golangci-lint_config/main/.golangci.yml -o .golangci.yml
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.1
args: --timeout 3m
skip-cache: true # the linters require all code generation and dependecies to be present, but the cache implementation completely falls over when there is already existing content. See https://github.com/golangci/golangci-lint-action/issues/23, https://github.com/golangci/golangci-lint-action/issues/863, https://github.com/golangci/golangci-lint-action/issues/984
- name: Test
run: go test -v -race ./...
scan-container:
name: Scan Container
runs-on: depot-ubuntu-24.04
# this is for container scanning with aws inspector
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout@v2
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # also fetch tags and branches for `git describe`
- uses: depot/setup-action@v1
- name: Build Docker image
uses: depot/build-push-action@v1
with:
project: xnsnw3m20t
context: .
file: "build/package/Dockerfile"
push: false
tags: app:latest
load: true
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: "eu-west-2"
role-to-assume: "${{ secrets.AWS_INSPECTOR_ROLE }}"
- name: Invoke Amazon Inspector Scan
id: inspector
uses: aws-actions/vulnerability-scan-github-action-for-amazon-inspector@main
with:
artifact_type: 'container'
artifact_path: 'app:latest'
display_vulnerability_findings: "enabled"
sbomgen_version: "latest"
build:
name: Build
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
needs:
- test
- scan-container
permissions:
contents: read # required for checkout
id-token: write # mint AWS credentials through OIDC
packages: write
strategy:
fail-fast: false
matrix:
include:
- dockerfile: Dockerfile
image_name: stdlib-source
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/overmindtech/${{ matrix.image_name }}
docker.cloudsmith.io/overmind/service/${{ matrix.image_name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Cloudsmith Container Registry
uses: docker/login-action@v3
with:
registry: docker.cloudsmith.io
username: ${{ secrets.CLOUDSMITH_SERVICE_USER }}
password: ${{ secrets.CLOUDSMITH_API_KEY }}
- uses: depot/setup-action@v1
- name: Build and push
id: push
uses: depot/build-push-action@v1
with:
project: xnsnw3m20t
file: build/package/${{ matrix.dockerfile }}
context: .
sbom: true
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Prepare Deployment
run: |
echo "ghcr.io/overmindtech/${{ matrix.image_name }}@${{ steps.push.outputs.digest }}" | tee ${{ matrix.image_name }}.imageref
- name: Upload Deployment File
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.image_name }}.imageref
path: ${{ matrix.image_name }}.imageref