Skip to content

Commit d437360

Browse files
authored
gha: add build and quality GHA actions (#10)
* gha: build and push image * Add CodeQL and Dependency Review Actions
1 parent 69aa956 commit d437360

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

.github/workflows/cd.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: cd
2+
on:
3+
push:
4+
branches:
5+
- master
6+
tags:
7+
- v*
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: checkout
18+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
19+
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
20+
with:
21+
go-version-file: go.mod
22+
cache: true
23+
- name: build package
24+
run: go build
25+
- name: build docker image
26+
run: docker build . --tag gravitational/missing-container-metrics:test
27+
28+
build_and_push_docker_image:
29+
runs-on: ubuntu-latest
30+
needs: [test]
31+
name: Build and push Docker image
32+
env:
33+
AWS_REGION: us-east-1
34+
AWS_ROLE: arn:aws:iam::146628656107:role/missing-container-metrics-github-action-ecr-role
35+
permissions:
36+
packages: write
37+
id-token: write
38+
steps:
39+
- name: Checkout repo
40+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v3
43+
- name: Setup docker buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Configure AWS credentials
47+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
48+
with:
49+
aws-region: ${{ env.AWS_REGION }}
50+
role-to-assume: ${{ env.AWS_ROLE }}
51+
- name: Login to ECR
52+
id: login-ecr
53+
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2
54+
with:
55+
registry-type: public
56+
57+
- name: Login to GitHub Container Registry
58+
id: login-ghcr
59+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Prepare docker labels and tags
66+
id: meta
67+
uses: docker/metadata-action@v5
68+
with:
69+
images: |
70+
${{ steps.login-ecr.outputs.registry }}/${{ github.repository }}
71+
ghcr.io/${{ github.repository }}
72+
flavor: |
73+
latest=false
74+
# Enable sha tag on branch push events and workflow dispatches.
75+
# Enable semver tags on tag push events, but don't overwrite major/minor tags for prereleases.
76+
tags: |
77+
type=sha,prefix={{branch}}-,suffix=-{{date 'YYYYMMDDTHHmmss'}},format=short,enable=${{ startsWith(github.ref, 'refs/heads/') }}
78+
type=semver,pattern={{major}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
79+
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}
80+
type=semver,pattern={{version}},enable=${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
81+
82+
- name: Build the Docker image and push
83+
uses: docker/build-push-action@v5
84+
with:
85+
push: true
86+
platforms: linux/amd64,linux/arm64
87+
tags: ${{ steps.meta.outputs.tags }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
cache-from: type=gha
90+
cache-to: type=gha,mode=max

.github/workflows/codeql.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ 'go' ]
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v5
31+
with:
32+
cache: false
33+
go-version-file: go.mod
34+
if: ${{ matrix.language == 'go' }}
35+
36+
- name: Initialize CodeQL
37+
uses: github/codeql-action/init@v3
38+
with:
39+
languages: ${{ matrix.language }}
40+
41+
- name: Autobuild
42+
uses: github/codeql-action/autobuild@v3
43+
44+
- name: Perform CodeQL Analysis
45+
uses: github/codeql-action/analyze@v3
46+
with:
47+
category: "/language:${{matrix.language}}"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Dependency Review
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
dependency-review:
8+
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
9+
uses: gravitational/shared-workflows/.github/workflows/dependency-review.yaml@main
10+
permissions:
11+
contents: read

0 commit comments

Comments
 (0)