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

Development #68

Merged
merged 13 commits into from
May 16, 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
51 changes: 51 additions & 0 deletions .github/workflows/codegen_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
# Trigger analysis when pushing in master or pull requests, and when creating
# a pull request.
pull_request:
types: [opened, synchronize, reopened]

# Declare default permissions as read only.
permissions: read-all

name: Code Generation Check
jobs:
check-codegen:
permissions:
pull-requests: write
strategy:
matrix:
target: [ mocks, protobuf ]
fail-fast: false # Don't cancel running checks because one fails
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: jdx/mise-action@0c39a522dfbced3ed83924152c45804a71ce216f # v2.0.4
with:
experimental: true
- id: generate
run: mise run generate:${{ matrix.target }} --check
continue-on-error: true
- name: Comment PR - Failure
if: steps.generate.outcome == 'failure'
uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
with:
comment_tag: 'code_gen_${{ matrix.target }}'
mode: upsert
message: |
Generating the ${{ matrix.target }} code failed. This could be an indicator that the code generation is not up to date.
Please review the failed action before deciding to merge the PR.
- name: Comment PR - Success
if: steps.generate.outcome != 'failure'
uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 # v2.5.0
with:
comment_tag: 'code_gen_${{ matrix.target }}'
mode: upsert
message: |
It appears that the ${{ matrix.target }} code generation is up to date.
19 changes: 0 additions & 19 deletions .github/workflows/osv-scanner-pr.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/osv-scanner-schedule.yaml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/osv-scanner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: OSV-Scanner

# Declare default permissions as read only.
permissions: read-all

on:
pull_request:
branches: [ "main" ]
merge_group:
branches: [ "main" ]
schedule:
- cron: '26 17 * * 0'
push:
branches: [ "main" ]


jobs:
scan-scheduled:
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
permissions:
# Require writing security events to upload SARIF file to security tab
security-events: write
# Read commit contents
contents: read
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@75532bf0bf75464b047d80414dbce04449498365" # v1.7.3
with:
# Example of specifying custom arguments
scan-args: |-
-r
--skip-git
./
scan-pr:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
permissions:
# Require writing security events to upload SARIF file to security tab
security-events: write
# Read commit contents
contents: read
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@75532bf0bf75464b047d80414dbce04449498365" # v1.7.3
with:
# Example of specifying custom arguments
scan-args: |-
-r
--skip-git
./
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# Cody code completion
.idea/cody_history.xml

.DS_Store
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ linters:
# - wrapcheck
- sloglint
- tenv
- testifylint
linters-settings:
goimports:
local-prefixes: github.com/madsrc/sophrosyne
Expand Down
15 changes: 11 additions & 4 deletions .idea/golinter.xml

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

6 changes: 0 additions & 6 deletions .idea/sonarlint.xml

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

4 changes: 4 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ watchexec = "latest"
"go:golang.org/x/tools/cmd/goimports" = "latest"
"go:github.com/google/osv-scanner/cmd/osv-scanner" = "v1"
"pipx:pre-commit" = "latest"
protoc = "latest"
mockery = "latest"
protoc-gen-go = "latest"
protoc-gen-go-grpc = "latest"

[settings]
experimental = true
Expand Down
2 changes: 1 addition & 1 deletion .mise/tasks/build/dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["dist/sophrosyne", "dist/sophrosyne_linux_amd64", "dist/sophrosyne_linux_arm64]
# mise outputs=["dist/sophrosyne", "dist/sophrosyne_linux_amd64", "dist/sophrosyne_linux_arm64"]

goos=""
goarch=""
Expand Down
2 changes: 2 additions & 0 deletions .mise/tasks/clean
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

rm -rf build
rm -rf dist
rm -rf internal/mocks
find . -name '*.pb.go' -delete
2 changes: 0 additions & 2 deletions .mise/tasks/dev/format
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/sh
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/report.xml"]

check=1

Expand Down
41 changes: 41 additions & 0 deletions .mise/tasks/generate/mocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
# mise sources=[".mockery.yaml", "go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
# mise outputs=["build/.mocksentinel"]

set -e

mkdir -p build

check=1

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--check) check=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

mkdir -p build/backups
echo "Backing up mocks to build/backups/mocks..."
rm -rf build/backups/mocks
mv internal/mocks build/backups/mocks

mockery
touch build/.mocksentinel

if test "$check" = 0; then
echo "\nChecking mocks..."
changes=$(git status --porcelain internal/mocks)
if test -n "$changes"; then
echo "Mocks changed:"
git --no-pager diff internal/mocks
exit 1
fi
echo "Mocks have no changes according to git!"
fi
49 changes: 49 additions & 0 deletions .mise/tasks/generate/protobuf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
# mise sources=["proto/**/*.proto"]
# mise outputs=["build/.protobufsentinel"]

set -e

mkdir -p build

check=1

handle_argument() {
echo "Argument '$1' not supported" >&2; exit 1
}

while test "$#" -gt 0; do
case "$1" in
--check) check=0; shift 1;;

-*) echo "unknown option: $1" >&2; exit 1;;
*) handle_argument "$1"; shift 1;;
esac
done

mkdir -p internal/grpc/checks
mkdir -p build/backups/grpc
echo "Backing up GRPC files to build/backups/grpc/checks"
mv -f internal/grpc/checks build/backups/grpc/checks
rm -rf internal/grpc/checks

protoc \
--proto_path=proto \
--go_out=internal/grpc \
--go_opt=paths=source_relative \
--go-grpc_out=internal/grpc \
--go-grpc_opt=paths=source_relative \
proto/checks/checks.proto

touch build/.protobufsentinel

if test "$check" = 0; then
echo "\nChecking GRPC files..."
changes=$(git status --porcelain internal/grpc)
if test -n "$changes"; then
echo "GRPC files changed:"
git --no-pager diff internal/grpc
exit 1
fi
echo "GRPC files have no changes according to git!"
fi
7 changes: 7 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
all: True
dir: internal/mocks/{{ replaceAll .InterfaceDirRelative "internal" "internal_" }}
filename: "{{.InterfaceName}}.go"
packages:
github.com/madsrc/sophrosyne:
config:
recursive: True
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ require (
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
Loading
Loading