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

ci: add ci/cd process #3

Merged
merged 15 commits into from
Jan 19, 2024
7 changes: 7 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/

# NOTE: Order is important; the last matching pattern takes the
# most precedence.

# Primary repo maintainers
* @ojo-network/core-devs
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10

- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
reviewers:
- ojo-network/core-devs
labels:
- "A:Automerge"
- "T:Dependencies"
44 changes: 44 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Configuration for probot-stale: https://github.com/probot/stale

# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30

# Limit to only `issues` or `pulls`
only: pulls

# Number of days of inactivity before a PR becomes stale.
daysUntilStale: 30

# Number of days of inactivity before an Issue or Pull Request with the stale
# label is closed.
#
# Set to false to disable. If disabled, issues still need to be closed manually,
# but will remain marked as stale.
daysUntilClose: 7

# Only issues or PRs with all of these labels are checked if stale. Defaults to
# `[]` (disabled).
onlyLabels: []

# Issues or Pull Requests with these labels will never be considered stale.
# Set to `[]` to disable
exemptLabels:
- "S:Pinned"

# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false

# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: false

# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: false

# Label to use when marking as stale
staleLabel: "S:Stale"

# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This PR has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build
on:
pull_request:
push:
branches:
- main

# This workflow makes amd64 and arm64 binaries for macOS and Linux.
jobs:
build:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/ojo-network/indexer
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
strategy:
matrix:
arch: [amd64, arm64]
targetos: [darwin, linux]
name: ethereum-api ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: 1.19
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- name: Compile
run: |
go mod download
go build .
- uses: actions/upload-artifact@v3
with:
name: ethereum-api ${{ matrix.targetos }} ${{ matrix.arch }}
path: ethereum-api
16 changes: 16 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint
on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
name: Run PR Title Linter
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Lint
on:
pull_request:
push:
branches:
- main
jobs:
golangci:
name: Run golangci-lint
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/ojo-network/indexer
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.53
args: --timeout 5m

super-linter:
name: Run super-linter
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files
# within `super-linter`.
fetch-depth: 0
- name: Run super-linter
uses: github/super-linter@v5
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_MARKDOWN: true
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58 changes: 58 additions & 0 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This workflow helps with creating releases.
# This job will only be triggered when a tag (vX.X.x) is pushed
name: Release Docker
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v[0-9]+\\.[0-9]+\\.[0-9]+" # Official release version tags e.g. v2.0.5
- "v[0-9]+\\.[0-9]+\\.[0-9]+-rc[0-9]+" # Release candidate tags e.g. v1.0.3-rc4

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Authenticate to Google Cloud
id: auth
uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: '${{ secrets.OJO_GCR_WORKLOAD_IDENTITY_PROVIDER }}'
service_account: '${{ secrets.OJO_GCR_SERVICE_ACCOUNT }}'
token_format: 'access_token'
access_token_lifetime: '300s'

- name: Login to Artifact Registry
uses: docker/[email protected]
with:
registry: us-west4-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
us-west4-docker.pkg.dev/ojo-network/ethereum-api/ethereum-api
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: GH_ACCESS_TOKEN=${{secrets.GH_ACCESS_TOKEN}}
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Tests
on:
pull_request:
push:
branches:
- main
- release/**

jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"

test:
runs-on: ubuntu-latest
env:
GOPRIVATE: github.com/ojo-network/indexer
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: '1.20'
cache: true
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- name: Test
if: env.GIT_DIFF
run: |
make test-unit
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# OSX
*.DS_Store

# build
main
build/

config.yaml

.netrc
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Build Image
FROM golang:1.20-alpine AS builder

ARG GH_ACCESS_TOKEN

RUN apk add --no-cache build-base git

WORKDIR /app

COPY go.mod go.sum ./
COPY .netrc /root/.netrc

RUN git config --global url."https://${GH_ACCESS_TOKEN}:[email protected]/".insteadOf "https://github.com/"
ENV export GOPRIVATE=github.com/ojo-network/indexer

RUN go mod download
Expand Down
Loading
Loading