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 PR linting and tests to CI #168

Draft
wants to merge 59 commits into
base: na/refactor-digitaloceanprovider
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d9def7b
feat: rewrite the docker provider
Zygimantass Jan 3, 2025
1ae9a8a
wip
nadim-az Jan 12, 2025
e2da3f5
cleanup
nadim-az Jan 13, 2025
b0db716
fixes
nadim-az Jan 13, 2025
3c77bca
mo fixes mo problems
nadim-az Jan 13, 2025
1c4694b
more cleanup after rebase
nadim-az Jan 13, 2025
cbef648
more cleanup after rebase
nadim-az Jan 13, 2025
478ec33
genesis functions should use RunCommandWhileStopped
nadim-az Jan 14, 2025
3eebd6c
runcommand should determine task state and how to run container accor…
nadim-az Jan 15, 2025
becf858
harden task tests
nadim-az Jan 15, 2025
1c0748a
harden provider tests
nadim-az Jan 15, 2025
d52f9bb
fix
nadim-az Jan 16, 2025
8fb965e
move serializable fields to state
nadim-az Jan 16, 2025
c3bd0c6
lint
nadim-az Jan 16, 2025
e2c0849
docker lint
nadim-az Jan 16, 2025
a0756ac
initialize missing fields after deserialization
nadim-az Jan 17, 2025
1ad307f
restore provider functionality
nadim-az Jan 17, 2025
6a7a2f5
remove docker changes
nadim-az Jan 20, 2025
fbedf8b
pr feedback
nadim-az Jan 20, 2025
ad10274
use zap fields in log statement
nadim-az Jan 20, 2025
37001a4
reorder import
nadim-az Jan 20, 2025
5f3c341
clean code plz
nadim-az Jan 20, 2025
e2070b2
use getState everywhere
nadim-az Jan 21, 2025
1ccfc04
fix: init provider state before using it in creating the firewall
Zygimantass Jan 21, 2025
3b1d53f
droplet id in task states should be a string
nadim-az Jan 21, 2025
7327e33
get public ip address through ifconfig instead of user input
nadim-az Jan 21, 2025
b5ec2e5
missing logger in restorechain
nadim-az Jan 21, 2025
dab8de5
test: add e2e test
nadim-az Jan 21, 2025
7e94622
refactor
nadim-az Jan 21, 2025
914fe17
create -> restore -> create
nadim-az Jan 21, 2025
cb8bf04
bug fix
nadim-az Jan 21, 2025
6dfffb5
test: e2e docker test
nadim-az Jan 19, 2025
039e546
genesis functions should use RunCommandWhileStopped
nadim-az Jan 14, 2025
95372fe
move serializable fields to state
nadim-az Jan 16, 2025
c8854ea
chore: remove provider reference from task struct
nadim-az Jan 17, 2025
e473bf9
fix bad rebase
nadim-az Jan 17, 2025
d459a71
lint
nadim-az Jan 17, 2025
cab9d1f
fix tests
nadim-az Jan 17, 2025
ff157d2
use network name
nadim-az Jan 19, 2025
56430ad
add back AllocatedIPs to state
nadim-az Jan 19, 2025
c5f58b7
bad rebase
nadim-az Jan 20, 2025
2c021ba
refactor image pull logic
nadim-az Jan 20, 2025
f1d66b7
use getState everywhere
nadim-az Jan 21, 2025
e73a6b4
remove provider name field from task state
nadim-az Jan 21, 2025
205e9fa
add test for remove task
nadim-az Jan 21, 2025
45a1916
move docker client to provider/clients
nadim-az Jan 21, 2025
4326553
removeTaskFunc moved to top-level provider package
nadim-az Jan 21, 2025
c42d0be
Merge pull request #166 from skip-mev/na/remove-provider-reference
nadim-az Jan 22, 2025
534ee12
Merge branch 'na/refactor-digitaloceanprovider' into na/e2e-test
nadim-az Jan 22, 2025
f16340b
Merge pull request #167 from skip-mev/na/e2e-test
nadim-az Jan 22, 2025
240346e
move tests to cosmos package
nadim-az Jan 22, 2025
3c1c13f
ci: add PR linting and tests to CI
nadim-az Jan 22, 2025
2fda0bb
add option for manual DO e2e tests dispatch
nadim-az Jan 22, 2025
d0d236f
set docker api version env var
nadim-az Jan 22, 2025
82556ba
set var on workflow level
nadim-az Jan 22, 2025
2a6d299
Merge branch 'na/refactor-digitaloceanprovider' into na/add-ci
nadim-az Jan 23, 2025
d2b179f
remove digitalocean_simapp from core package
nadim-az Jan 23, 2025
6c73d60
rebase galore
nadim-az Jan 23, 2025
97e861d
set docker version in different step
nadim-az Jan 23, 2025
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
47 changes: 47 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
contents: read

jobs:
main:
permissions:
pull-requests: read
statuses: write
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.

Details:

```
${{ steps.lint_pr_title.outputs.error_message }}
```

# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
delete: true
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: "Run tests"
on:
push:
branches:
- main
pull_request:
branches:
- '**'
types:
- opened
- edited
- synchronize
workflow_dispatch:

env:
DOCKER_API_VERSION: '1.45'

jobs:
docker-e2e:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Set up Docker
run: |
echo "DOCKER_API_VERSION=1.45" >> $GITHUB_ENV
- name: Debug Docker Setup
run: |
docker version
echo "DOCKER_API_VERSION=$DOCKER_API_VERSION"
- name: Run Docker E2E tests
run: |
make tidy
make docker-e2e

digitalocean-e2e:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
github.event_name == 'pull_request' && (
contains(github.event.pull_request.files.*.path, 'cosmos/') ||
contains(github.event.pull_request.files.*.path, 'core/provider/digitalocean/') ||
contains(github.event.pull_request.files.*.path, 'core/provider/clients/')
)
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Run DigitalOcean E2E tests
env:
DO_API_TOKEN: ${{ secrets.DO_API_TOKEN }}
DO_IMAGE_ID: ${{ vars.DO_IMAGE_ID }}
run: |
make tidy
make digitalocean-e2e

unit-test:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
- name: Set up Docker
run: |
echo "DOCKER_API_VERSION=1.45" >> $GITHUB_ENV
- name: Debug Docker Setup
run: |
docker version
echo "DOCKER_API_VERSION=$DOCKER_API_VERSION"
- name: Run unit tests
run: |
make tidy
make unit-test
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ tidy:
@cd ./core && go mod tidy
@cd ./cosmos && go mod tidy

test:
unit-test:
@cd ./core && go test ./... -race
@cd ./cosmos && go test ./... -race
@cd ./cosmos && go test `go list ./... | grep -v e2e` -race

docker-e2e:
@cd ./cosmos && go test ./tests/e2e/docker/... -race -v

digitalocean-e2e:
@cd ./cosmos && go test ./tests/e2e/digitalocean/... -race -v

e2e-test:
@cd ./cosmos && go test ./tests/e2e/... -race -v

govulncheck:
@echo "--> Running govulncheck"
Expand All @@ -28,4 +37,4 @@ format:
@find . -name '*.go' -type f -not -path "*.git*" | xargs go run github.com/client9/misspell/cmd/misspell -w
@find . -name '*.go' -type f -not -path "*.git*" | xargs go run golang.org/x/tools/cmd/goimports -w -local github.com/skip-mev/petri

.PHONY: format lint-fix lint govulncheck test tidy
.PHONY: format lint-fix lint govulncheck unit-test docker-e2e digitalocean-e2e e2e-test tidy
2 changes: 0 additions & 2 deletions core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jgautheron/goconst v1.7.0 // indirect
github.com/jingyugao/rowserrcheck v1.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSAS
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 h1:nHoRIX8iXob3Y2kdt9KsjyIb7iApSvb3vgsd93xb5Ow=
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0/go.mod h1:c1tRKs5Tx7E2+uHGSyyncziFjvGpgv4H2HrqXeUQ/Uk=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
github.com/improbable-eng/grpc-web v0.15.0/go.mod h1:1sy9HKV4Jt9aEs9JSnkWlRJPuPtwNr0l57L4f878wP8=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
3 changes: 1 addition & 2 deletions core/provider/digitalocean/droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"fmt"
"time"

"github.com/skip-mev/petri/core/v3/provider/clients"

"github.com/pkg/errors"

"github.com/digitalocean/godo"
"go.uber.org/zap"
"golang.org/x/crypto/ssh"

"github.com/skip-mev/petri/core/v3/provider"
"github.com/skip-mev/petri/core/v3/provider/clients"
"github.com/skip-mev/petri/core/v3/util"

"strconv"
Expand Down
5 changes: 2 additions & 3 deletions core/provider/digitalocean/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import (
"sync"
"time"

"github.com/docker/docker/api/types/image"
"github.com/skip-mev/petri/core/v3/provider/clients"

"github.com/digitalocean/godo"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"

"go.uber.org/zap"

"github.com/skip-mev/petri/core/v3/provider"
"github.com/skip-mev/petri/core/v3/provider/clients"
"github.com/skip-mev/petri/core/v3/util"
)

Expand Down
3 changes: 1 addition & 2 deletions core/provider/digitalocean/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"sync"
"time"

"github.com/skip-mev/petri/core/v3/provider/clients"

"golang.org/x/crypto/ssh"

"github.com/docker/docker/api/types/container"
Expand All @@ -23,6 +21,7 @@ import (
"go.uber.org/zap"

"github.com/skip-mev/petri/core/v3/provider"
"github.com/skip-mev/petri/core/v3/provider/clients"
"github.com/skip-mev/petri/core/v3/util"
)

Expand Down
3 changes: 1 addition & 2 deletions core/provider/docker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"sync"
"time"

"github.com/skip-mev/petri/core/v3/provider/clients"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/skip-mev/petri/core/v3/provider"
"github.com/skip-mev/petri/core/v3/provider/clients"
"github.com/skip-mev/petri/core/v3/util"
"go.uber.org/zap"
)
Expand Down
Loading