Skip to content

Commit

Permalink
feat: Add ci pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
kayano committed Dec 19, 2023
1 parent af908f5 commit e7a6976
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 20 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pr-validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: PR Validation

on:
pull_request:
branches:
- main

jobs:
run-reviewdog:
name: Run ReviewDog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: ReviewDog - GolangCI Lint
uses: reviewdog/action-golangci-lint@v2
with:
go_version_file: go.mod
tool_name: GolangCI Lint
golangci_lint_flags: --config=.golangci.yaml --timeout=10m
fail_on_error: true
run-tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Tests
run: make test-ci
44 changes: 44 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- id: release-please
name: Release Please
uses: google-github-actions/release-please-action@v4
with:
release-type: go

- name: Checkout
uses: actions/checkout@v4
if: steps.release-please.outputs.release_created
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
if: steps.release-please.outputs.release_created
with:
go-version-file: go.mod

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: steps.release-please.outputs.release_created

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: steps.release-please.outputs.release_created

- name: Run GoReleaser
if: steps.release-please.outputs.release_created
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 changes: 57 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
project_name: validator-exporter
before:
hooks:
- go mod tidy
env:
- CGO_ENABLED=0
builds:
- main: "./cmd/{{ .ProjectName }}/main.go"
binary: "{{ .ProjectName }}"
goos:
- linux
- darwin
goarch:
- amd64
- arm64
flags:
- -mod=readonly
- -trimpath
ldflags:
- -s -w
tags:
- netgo

universal_binaries:
- replace: false

dockers:
- use: buildx
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-amd64"
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm64
image_templates:
- "ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-arm64v8"
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
docker_manifests:
- name_template: ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-arm64v8
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM gcr.io/distroless/static-debian12:nonroot

COPY validator-exporter /usr/bin/validator-exporter

# metrics server
EXPOSE 8008

ENTRYPOINT [ "/usr/bin/validator-exporter" ]

CMD [ "--help" ]
42 changes: 22 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BUILD_FOLDER = build
DIST_FOLDER = dist
GORELEASER_VERSION = v1.21.0
GORELEASER_VERSION = v1.22.1
DOCKER := $(shell which docker)
PACKAGE_NAME = github.com/archway-network/validator-exporter

Expand Down Expand Up @@ -56,23 +56,25 @@ update:
@go build -o "$(TMPDIR)/validator-exporter" cmd/validator-exporter/main.go
@git diff -- go.mod go.sum

# release-dryrun:
# $(DOCKER) run \
# --rm \
# -v /var/run/docker.sock:/var/run/docker.sock \
# -v `pwd`:/go/src/$(PACKAGE_NAME) \
# -w /go/src/$(PACKAGE_NAME) \
# goreleaser/goreleaser-cross:$(GORELEASER_VERSION) \
# --skip-publish \
# --clean \
# --skip-validate

# release:
# $(DOCKER) run \
# --rm \
# -e GITHUB_TOKEN="$(GITHUB_TOKEN)" \
# -v /var/run/docker.sock:/var/run/docker.sock \
# -v `pwd`:/go/src/$(PACKAGE_NAME) \
# -w /go/src/$(PACKAGE_NAME) \
# goreleaser/goreleaser-cross:$(GORELEASER_VERSION) \
# --clean
release-dryrun:
$(DOCKER) run \
--rm \
-e GITHUB_TOKEN="$(GITHUB_TOKEN)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser:$(GORELEASER_VERSION) \
--clean \
--skip=publish,validate \
--snapshot

release:
$(DOCKER) run \
--rm \
-e GITHUB_TOKEN="$(GITHUB_TOKEN)" \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
ghcr.io/goreleaser/goreleaser:$(GORELEASER_VERSION) \
--clean

0 comments on commit e7a6976

Please sign in to comment.