Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GHA workflows to build and lint the cmapisrv-mock #85

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Image build

on:
pull_request: {}
push:
branches:
- main

jobs:
build-and-push:
name: Build and Push
runs-on: ubuntu-latest

strategy:
matrix:
include:
- name: cmapisrv-mock
context: cmapisrv-mock
dockerfile: ./cmapisrv-mock/Dockerfile

steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0

- name: Login to quay.io
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
if: ${{ github.event_name == 'push' }}
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME_SCAFFOLDING }}
password: ${{ secrets.QUAY_PASSWORD_SCAFFOLDING }}

- name: Checkout Source Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Build and Push
uses: docker/build-push-action@c382f710d39a5bb4e430307530a720f50c2d3318 # v6.0.0
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: ${{ github.event_name == 'push' }}
platforms: linux/amd64,linux/arm64
tags: |
quay.io/${{ github.repository_owner }}/${{ matrix.name }}:${{ github.event.pull_request.head.sha || github.sha }}
42 changes: 42 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Lint Go files

on:
pull_request: {}

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

strategy:
matrix:
include:
- workdir: cmapisrv-mock

steps:
- name: Install Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
# renovate: datasource=golang-version depName=go
go-version: 1.22.4

- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false

- name: Check module vendoring
working-directory: ${{ matrix.workdir }}
run: |
go mod tidy
go mod vendor
test -z "$(git status --porcelain)" || (echo "please run 'go mod tidy && go mod vendor', and submit your changes"; exit 1)

- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
with:
# renovate: datasource=docker depName=golangci/golangci-lint
version: v1.59.1
skip-cache: true
working-directory: ${{ matrix.workdir }}
args: "--out-format colored-line-number --verbose --modules-download-mode=vendor"
8 changes: 2 additions & 6 deletions cmapisrv-mock/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ linters-settings:
- nilness
goimports:
local-prefixes: github.com/cilium
staticcheck:
go: "1.20"
unused:
go: "1.20"
goheader:
values:
regexp:
Expand Down Expand Up @@ -92,7 +88,7 @@ issues:
text: "SA9003: empty branch"
- linters: [staticcheck]
text: "SA2001: empty critical section"
- linters: [goerr113]
- linters: [err113]
text: "do not define dynamic errors, use wrapped static errors instead" # This rule to avoid opinionated check fmt.Errorf("text")
# Skip goimports check on generated files
- path: \\.(generated\\.deepcopy|pb)\\.go$
Expand All @@ -106,7 +102,7 @@ issues:
linters:
disable-all: true
enable:
- goerr113
- err113
- gofmt
- goimports
- govet
Expand Down
4 changes: 2 additions & 2 deletions cmapisrv-mock/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ ARG BASE_IMAGE=docker.io/library/alpine:3.19.1@sha256:c5b1261d6d3e43071626931fc0
ARG GOLANG_IMAGE=docker.io/library/golang:1.22.1@sha256:0b55ab82ac2a54a6f8f85ec8b943b9e470c39e32c109b766bbc1b801f3fa8d3b
ARG ETCD_SERVER_IMAGE=gcr.io/etcd-development/etcd:v3.5.12@sha256:cebe24b890641de3e7ff8a640c4597bdda321090c29f4dedcedaa8cadbbe08e1

FROM ${GOLANG_IMAGE} as builder
FROM ${GOLANG_IMAGE} AS builder
ADD . /go/src/github.com/cilium/scaffolding/cmapisrv-mock
WORKDIR /go/src/github.com/cilium/scaffolding/cmapisrv-mock
RUN make cmapisrv-mock
RUN strip cmapisrv-mock

FROM ${ETCD_SERVER_IMAGE} as etcd
FROM ${ETCD_SERVER_IMAGE} AS etcd

FROM ${BASE_IMAGE}

Expand Down
4 changes: 3 additions & 1 deletion cmapisrv-mock/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
DOCKER_IMAGE ?= quay.io/cilium/cmapisrv-mock:latest

.PHONY: all docker-image docker-image-load docker-image-push tests cmapisrv-mock local clean

all: local

docker-image:
Expand All @@ -15,7 +17,7 @@ docker-image-push: docker-image
tests:
go test -mod=vendor ./...

cmapisrv-mock: tests
cmapisrv-mock:
CGO_ENABLED=0 go build -mod=vendor -o $@ *.go

local: cmapisrv-mock
Expand Down
18 changes: 9 additions & 9 deletions cmapisrv-mock/vendor/github.com/hashicorp/hcl/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions cmapisrv-mock/vendor/github.com/hashicorp/hcl/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading