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

Github Actions Test #100

Merged
merged 8 commits into from
Oct 5, 2023
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
4 changes: 4 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
- name: Delete git global config
if: always()
run: |
rm ~/.gitconfig
24 changes: 23 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ on:
jobs:
checks:
name: run
runs-on: self-hosted
runs-on: [ self-hosted, dpdk ]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Download metalbond using the script
run: ./hack/rel_download.sh -dir=build -owner=onmetal -repo=metalbond -pat=${{ secrets.BOT_PAT }}

- name: Install metalbond
run: sudo dpkg -i build/metalbond*.deb

- name: Start metalbond
run: metalbond server --listen [::1]:4711 --http [::1]:4712 --keepalive 3 &

- name: Run dp-service
run: docker run --rm --entrypoint ./dp_service.py --privileged -p1337:1337 --mount type=bind,source=/dev/hugepages,target=/dev/hugepages ghcr.io/onmetal/dp-service-tester --no-init &

- uses: actions/setup-go@v4
with:
go-version-file: go.mod
Expand All @@ -28,3 +41,12 @@ jobs:
ssh-private-key: ${{ secrets.BOT_PRIVATE_KEY }}
- run: ./hack/setup-git-redirect.sh
- run: make test
- name: Delete git global config
if: always()
run: |
rm ~/.gitconfig
- name: Cleanup services
if: always()
run: |
killall metalbond
for i in $(docker ps -q); do docker stop $i; done
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ addlicense: ## Add license headers to all go files.
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: checklicense
checklicense: ## Check that every file has a license header present.
find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'OnMetal authors' {} +
Expand All @@ -73,20 +77,17 @@ lint: ## Run golangci-lint against code.
golangci-lint run ./...

.PHONY: check
check: manifests generate addlicense lint test
check: manifests generate fmt addlicense lint test ## Generate manifests, code, lint, add licenses, test

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
.PHONY: test
test: envtest manifests generate fmt checklicense ## Run tests.
test: envtest manifests generate fmt vet ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v ./... -coverprofile cover.out -ginkgo.v -ginkgo.label-filter=$(labels) -ginkgo.randomize-all

.PHONY: check
check: generate fmt addlicense lint test ## Lint and run tests.

##@ Build

.PHONY: build
build: manifests generate fmt addlicense lint ## Build the binary
build: manifests generate fmt lint ## Build the binary
go build -ldflags "-X main.buildVersion=${shell git describe --tags}'" -o bin/metalnet ./main.go

.PHONY: run
Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
ctxGrpc context.Context
dpserviceAddr string = "127.0.0.1:1337"
testNode string = "testNode"
metalnetDir string = "/var/lib/metalnet"
metalnetDir string = "/tmp/var/lib/metalnet"
netFnsManager *netfns.Manager
conn *grpc.ClientConn
dpdkProtoClient dpdkproto.DPDKonmetalClient
Expand Down
84 changes: 84 additions & 0 deletions hack/rel_download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
# This script uses a Personal Access Token (PAT) to access a GitHub repository.
# It takes the following parameters in the style "-parameter=PARAMETER_VALUE":
# 1. -dir : Destination directory. A directory path (relative to the current directory) where the files will be downloaded.
# 2. -owner : Repository owner. The username of the owner of the repository on GitHub.
# 3. -repo : Repository name. The name of the repository on GitHub.
# 4. -pat : Personal Access Token (PAT). A token provided by GitHub to access the repository.
# 5. -release : (Optional) Release tag. By default, it is set to "latest".
# Example usage:
# ./hack/rel_download.sh -dir=exporter -owner=onmetal -repo=prometheus-dpdk-exporter -pat=MY_PAT

set -e

if [ "$#" -lt 4 ]; then
echo "Usage: $0 -dir=<Destination Directory> -owner=<Repository Owner> -repo=<Repository Name> -pat=<Personal Access Token> [-release=<Release Tag>]"
exit 1
fi

# Process parameters
for i in "$@"
do
case $i in
-dir=*)
DIRECTORY="${i#*=}"
shift
;;
-owner=*)
REPO_OWNER="${i#*=}"
shift
;;
-repo=*)
REPO_NAME="${i#*=}"
shift
;;
-pat=*)
PAT="${i#*=}"
shift
;;
-release=*)
RELEASE="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done

RELEASE=${RELEASE:-latest}

if [ ! -d "$DIRECTORY" ]; then
mkdir -p "$DIRECTORY"
fi

if [ -z "$PAT" ]; then
touch $DIRECTORY/dummy_$DIRECTORY
echo "No PAT defined. Will not download the packages"
exit 0
fi

# Use curl to access the GitHub API and get the asset ID.
ASSET_ID=$(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $PAT" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/$RELEASE | jq -r '.assets[] | select (.name | contains("_amd64")) | .id')

if [ -z "$ASSET_ID" ]; then
echo "Failed to copy the release binary to $DIRECTORY"
exit 1
fi

# Use curl to download the asset using the asset ID.
curl -s -L -H "Accept: application/octet-stream" -H "Authorization: Bearer $PAT" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/assets/$ASSET_ID -o $DIRECTORY/$REPO_NAME.deb

#tar -xzf $DIRECTORY/$DIRECTORY.tar.gz -C $DIRECTORY
#rm $DIRECTORY/$DIRECTORY.tar.gz
#rm -rf $DIRECTORY/LICENSE*
#rm -rf $DIRECTORY/README.md

#if [ "$?" -eq 0 ]; then
# echo "Release binary successfully copied to $DIRECTORY"
#else
# echo "Failed to copy the release binary to $DIRECTORY"
# exit 1
#fi

exit 0
Loading