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

INFOPLAT-1402 Beholder gh action #686

Merged
merged 16 commits into from
Oct 30, 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
5 changes: 5 additions & 0 deletions .changeset/quick-hornets-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ci-beholder-schema-validate": minor
---

First initial minor release
20 changes: 20 additions & 0 deletions actions/ci-beholder-schema-validate/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# BUILD step
FROM golang:1.23-alpine AS builder

RUN apk add --no-progress --no-cache \
gcc \
musl-dev \
linux-headers

# Switch to app dir
WORKDIR /app

COPY ./src ./

RUN go build -a -tags musl -o beholder-ci

# PACKAGE step
FROM alpine:latest

COPY --from=builder /app/beholder-ci /app/beholder-ci
ENTRYPOINT ["/app/beholder-ci"]
28 changes: 28 additions & 0 deletions actions/ci-beholder-schema-validate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ci-beholder-schema-validate

> Action to validate beholder schemas

## Running app in docker

you can demo the application by building the docker image

```shell
docker build -t ci-beholder:latest . --no-cache
```

then running the app in the container

```shell
docker run --rm -v ./src/beholder_config.txt:/opt/beholder_config.txt beholder-ci:latest validate -f /opt/beholder_config.txt
```

#### whats happening in the command above

- `run --rm` runs the container, and when the process running in the container
exits, delete the container
- `-v ./src/beholder_config.txt:/opt/beholder_config.txt` we are mounting a
local file to the container, at the location `/opt/`. In Github actions the
whole repo is mounted automatically to the container
- `beholder-ci:latest` image that we want to run
- `validate -f /opt/beholder_config.txt` is the command to the app we want to
run along with relevant flags`
15 changes: 15 additions & 0 deletions actions/ci-beholder-schema-validate/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# action.yml
name: "Beholder Schema Validation"
description: "Validate schemas for Beholder usage"
inputs:
beholder-config-file-path: # id of input
description: "path to beholder configuration yaml file"
required: true
outputs: {}
runs:
using: "docker"
image: "Dockerfile"
args:
- validate
- -f
- ${{ inputs.beholder-config-file-path }}
11 changes: 11 additions & 0 deletions actions/ci-beholder-schema-validate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ci-beholder-schema-validate",
"version": "0.0.0",
"description": "",
"private": true,
"scripts": {},
"author": "@hendoxc",
"license": "MIT",
"dependencies": {},
"repository": "https://github.com/smartcontractkit/.github"
}
7 changes: 7 additions & 0 deletions actions/ci-beholder-schema-validate/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "ci-beholder-schema-validate",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "actions/ci-beholder-schema-validate",
"targets": {}
}
31 changes: 31 additions & 0 deletions actions/ci-beholder-schema-validate/src/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
)


var rootCmd = &cobra.Command{
Use: "ci-beholder-schema-validate",
Short: "Schema validation",
Long: `Schema validation`,
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

var beholderFilePath string

func init() {

// add persistent flag for beholder file path
rootCmd.PersistentFlags().StringVarP(&beholderFilePath, "beholder-file", "f", "", "beholder file path")
_ = rootCmd.MarkPersistentFlagRequired("beholder-file")

}
32 changes: 32 additions & 0 deletions actions/ci-beholder-schema-validate/src/cmd/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"fmt"
"log"
"os"

"github.com/spf13/cobra"
)

var validateCmd = &cobra.Command{
Use: "validate",
Short: "Validate schemas",
Long: `Validate schemas`,
Run: runValidateCmd,
}

func init() {
rootCmd.AddCommand(validateCmd)
}

func runValidateCmd(cmd *cobra.Command, args []string) {

beholderFileContents, err := os.ReadFile(beholderFilePath)
if err != nil {
log.Panic(err)
}

fmt.Printf("beholderFileContents: %s", beholderFileContents)

}

10 changes: 10 additions & 0 deletions actions/ci-beholder-schema-validate/src/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module schema-validate

go 1.23.2

require github.com/spf13/cobra v1.8.1

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions actions/ci-beholder-schema-validate/src/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 10 additions & 0 deletions actions/ci-beholder-schema-validate/src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"schema-validate/cmd"
)


func main() {
cmd.Execute()
}
Loading