Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
Add GH actions for pull request workflow (#14)
Browse files Browse the repository at this point in the history
* Fix Dockerfiles
* Add pull_request_workflow GH action
* Fix indentation in bash scripts
  • Loading branch information
leo8a committed Oct 24, 2023
1 parent 87187ad commit d9abbf9
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 90 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/bashate_and_shellcheck.yaml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/pull_request_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]


jobs:

golang_lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "stable"
- run: make deps-update
- run: make fmt
- run: make vet
- run: make lint
# - run: make vendor-diff
- run: make golangci-lint

golang_unittests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "stable"
- run: make generate
- run: make unit-test

bash_lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: make build # Creates the ./bin directory required by shellcheck afterward
- run: make shellcheck
- run: make bashate
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /workspace
COPY go.mod go.sum ./
COPY vendor/ vendor/

# Copy the go source
# Copy the Go source installation_configuration_files
COPY main.go main.go
COPY cmd/ cmd/
COPY internal/ internal/
Expand All @@ -24,12 +24,16 @@ RUN curl -sL https://github.com/kubernetes-sigs/cri-tools/releases/download/$CRI


########### Runtime ##########
FROM registry.ci.openshift.org/ocp/4.13:tools
FROM registry.access.redhat.com/ubi9/ubi:latest

WORKDIR /

COPY --from=builder /workspace/ibu-imager .
COPY --from=builder /workspace/crictl /usr/bin/
COPY installation_configuration_files/ installation_configuration_files/

RUN yum -y install jq && \
yum clean all && \
rm -rf /var/cache/yum

ENTRYPOINT ["./ibu-imager"]
31 changes: 29 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ IMAGE_TAG_BASE ?= quay.io/lochoa/ibu-imager
# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)

# Unittests variables
TEST_FORMAT ?= standard-verbose
GOTEST_FLAGS = --format=$(TEST_FORMAT)
GINKGO_FLAGS = -ginkgo.focus="$(FOCUS)" -ginkgo.v -ginkgo.skip="$(SKIP)"

default: help

.PHONY: fmt
Expand All @@ -27,6 +32,11 @@ vet: ## Run go vet against code.
@echo "Running go vet"
go vet ./...

.PHONY: lint
lint: ## Run golint against code.
@echo "Running golint"
hack/lint.sh

.PHONY: deps-update
deps-update: ## Run go mod tidy and vendor against code.
go mod tidy && go mod vendor
Expand All @@ -41,16 +51,33 @@ bashate: ## Run bashate
@echo "Running bashate"
hack/bashate.sh

lint: vendor-diff
golangci-lint run -v
.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint against code.
@echo "Running golangci-lint"
hack/golangci-lint.sh

vendor-diff:
go mod vendor && git diff --exit-code vendor

.PHONY: generate
generate:
@echo "Running mockgen"
bash -c 'pushd "$(GOPATH)" && \
go install github.com/golang/mock/mockgen@latest && \
popd'
go generate $(shell go list ./...)
$(MAKE) fmt

_test: $(REPORTS)
gotestsum $(GOTEST_FLAGS) $(TEST) $(GINKGO_FLAGS) -timeout $(TIMEOUT)

unit-test: ## Run unittests
@echo "Running unittests"
bash -c 'pushd "$(GOPATH)" && \
go install gotest.tools/gotestsum@latest && \
popd'
$(MAKE) _test TEST_SCENARIO=unit TIMEOUT=30m TEST="$(or $(TEST),$(shell go list ./...))"

##@ Build

build: deps-update fmt vet ## Build manager binary.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IBU Imager

[![Lint Bash Scripts](https://github.com/leo8a/ibu-imager/actions/workflows/bashate_and_shellcheck.yaml/badge.svg)](https://github.com/leo8a/ibu-imager/actions/workflows/bashate_and_shellcheck.yaml)
[![CI](https://github.com/leo8a/ibu-imager/actions/workflows/pull_request_workflow.yml/badge.svg)](https://github.com/leo8a/ibu-imager/actions/workflows/pull_request_workflow.yml)

This application will assist users to easily create an OCI seed image for the Image-Based Upgrade (IBU) workflow, using
a simple CLI.
Expand Down
40 changes: 0 additions & 40 deletions dev.Dockerfile

This file was deleted.

10 changes: 4 additions & 6 deletions hack/clean.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/bash

sudo rm -rf /var/tmp/container_list.done \
/var/tmp/backup && \
/var/tmp/backup && \
sudo rm -f /usr/local/bin/prepare-installation-configuration.sh \
/usr/local/bin/installation-configuration.sh && \
/usr/local/bin/installation-configuration.sh && \
sudo systemctl disable installation-configuration.service && \
sudo systemctl disable prepare-installation-configuration.service && \
rm -f /etc/systemd/system/installation-configuration.service \
/etc/systemd/system/prepare-installation-configuration.service && \
/etc/systemd/system/prepare-installation-configuration.service && \
sudo podman rmi quay.io/alosadag/ibu-seed-sno0:oneimage --force && \
sudo systemctl enable --now kubelet && \
sudo systemctl enable --now crio


sudo systemctl enable --now crio
18 changes: 8 additions & 10 deletions hack/golangci-lint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
#!/bin/bash

which golangci-lint
if [ $? -ne 0 ]; then
echo "Downloading golangci-lint tool"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b $(go env GOPATH)/bin v1.51.1
export GOCACHE=/tmp/
export GOLANGCI_LINT_CACHE=/tmp/.cache


if [ $? -ne 0 ]; then
echo "Install from script failed. Trying go install"
go install github.com/golangci/golangci-lint/cmd/[email protected]
if [ $? -ne 0 ]; then
if ! which golangci-lint &> /dev/null; then
echo "Downloading golangci-lint tool..."
if ! curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -d -b "$(go env GOPATH)/bin" v1.51.1; then
echo "Install from script failed. Trying 'go install'..."
if ! go install github.com/golangci/golangci-lint/cmd/[email protected]; then
echo "Install of golangci-lint failed"
exit 1
fi
fi
fi

export GOCACHE=/tmp/
export GOLANGCI_LINT_CACHE=/tmp/.cache
golangci-lint run --verbose --print-resources-usage --modules-download-mode=vendor --timeout=5m0s
20 changes: 20 additions & 0 deletions hack/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

RETVAL=0
GENERATED_FILES="zz_generated.*.go"


cd $GOPATH || fatal "Failed to enter $GOPATH directory"
if ! which golint &> /dev/null; then
echo "Downloading golint tool..."
go install golang.org/x/lint/golint@latest
fi

for file in $(find . -path ./vendor -prune -o -type f -name '*.go' -print | grep -E -v "$GENERATED_FILES"); do
golint -set_exit_status "$file"
if [[ $? -ne 0 ]]; then
RETVAL=1
fi
done

exit $RETVAL

0 comments on commit d9abbf9

Please sign in to comment.