-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (123 loc) · 4.41 KB
/
ci.yml
File metadata and controls
150 lines (123 loc) · 4.41 KB
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
name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: Download dependencies
run: go mod download
- name: Run tests
run: go test -race -v ./...
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.9.0
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
- name: Run gosec
# All false positives are suppressed with inline #nosec comments.
# No global exclusions — every suppression is documented at the call site.
run: gosec ./...
build:
runs-on: ubuntu-latest
needs: [test, lint]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: Build
run: go build -v ./...
scan:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
severity: 'CRITICAL,HIGH'
exit-code: '1'
deploy:
runs-on: ubuntu-latest
needs: [build, security, scan]
# Only deploy on version tag pushes (e.g. v1.0.0)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
name: production
url: ${{ steps.show-url.outputs.url }}
permissions:
contents: read
id-token: write # Required for Workload Identity Federation
env:
PROJECT_ID: "github-copy-code-examples"
SERVICE_NAME: "examples-copier"
REGION: "us-central1"
steps:
- uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: |
RAW_TAG="${GITHUB_REF#refs/tags/}"
# Cloud Run traffic tags: lowercase, a-z0-9-, max 63 chars, no leading/trailing -
TRAFFIC_TAG=$(echo "$RAW_TAG" | tr '.' '-' | tr '[:upper:]' '[:lower:]')
echo "tag=$RAW_TAG" >> $GITHUB_OUTPUT
echo "traffic_tag=$TRAFFIC_TAG" >> $GITHUB_OUTPUT
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Deploy to Cloud Run
run: |
gcloud run deploy $SERVICE_NAME \
--source . \
--region $REGION \
--project $PROJECT_ID \
--allow-unauthenticated \
--set-env-vars="^|^CONFIG_REPO_OWNER=grove-platform|CONFIG_REPO_NAME=github-copier|CONFIG_REPO_BRANCH=main|PEM_NAME=CODE_COPIER_PEM|WEBHOOK_SECRET_NAME=webhook-secret|MONGO_URI_SECRET_NAME=mongo-uri|WEBSERVER_PATH=/events|MAIN_CONFIG_FILE=.copier/main.yaml|USE_MAIN_CONFIG=true|DEPRECATION_FILE=deprecated_examples.json|COMMITTER_NAME=GitHub Copier App|COMMITTER_EMAIL=bot@mongodb.com|GOOGLE_CLOUD_PROJECT_ID=github-copy-code-examples|COPIER_LOG_NAME=code-copier-log|AUDIT_ENABLED=false|METRICS_ENABLED=true|GITHUB_APP_ID=${{ secrets.APP_ID }}|INSTALLATION_ID=${{ secrets.INSTALLATION_ID }}" \
--set-build-env-vars="VERSION=${{ steps.version.outputs.tag }}" \
--tag="${{ steps.version.outputs.traffic_tag }}" \
--max-instances=10 \
--cpu=1 \
--memory=512Mi \
--timeout=300s \
--concurrency=80 \
--port=8080 \
--platform=managed
- name: Show deployment URL
id: show-url
run: |
URL=$(gcloud run services describe $SERVICE_NAME \
--region $REGION \
--project $PROJECT_ID \
--format='value(status.url)')
echo "url=$URL" >> $GITHUB_OUTPUT
echo "Deployed ${{ steps.version.outputs.tag }} to: $URL"