Skip to content

Commit

Permalink
Merge pull request #281 from ArangoGutierrez/restructure_ci
Browse files Browse the repository at this point in the history
Restructure Github Actions
  • Loading branch information
ArangoGutierrez authored Feb 13, 2025
2 parents 9a28600 + 3cb736f commit de8a35d
Show file tree
Hide file tree
Showing 23 changed files with 286 additions and 156 deletions.
8 changes: 8 additions & 0 deletions .github/codeql/codeql-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
paths:
- pkg
- cmd
- internal
- test
paths-ignore:
- pkg/provisioner/provisioner.go
- cmd/cli/dryrun/dryrun.go
39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2025 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: CI Pipeline

on:
push:
branches:
- "pull-request/[0-9]+"
- main
- release-*

jobs:
code-scanning:
uses: ./.github/workflows/code_scanning.yaml

golang:
uses: ./.github/workflows/golang.yaml

image:
uses: ./.github/workflows/image.yaml
needs: [golang, code-scanning]
secrets: inherit

e2e-test:
needs: golang
secrets: inherit
uses: ./.github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@
name: "CodeQL"

on:
workflow_call: {}
pull_request:
types:
- opened
- synchronize
branches:
- main
- release-*
push:
branches:
- main
- release-*
schedule:
- cron: '31 11 * * 4'

Expand All @@ -40,14 +37,18 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
config-file: ./.github/codeql/codeql-config.yaml
languages: go
build-mode: manual

- shell: bash
run: |
make build-cli
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/e2e.yml → .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
name: End-to-end Tests

on:
workflow_run:
workflows: [Go]
types:
- completed
branches:
- "pull-request/[0-9]+"
- main
- release-*
workflow_call:
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_SSH_KEY:
required: true

jobs:
e2e-test:
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/go.yml

This file was deleted.

78 changes: 78 additions & 0 deletions .github/workflows/golang.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##

name: Go

on:
workflow_call: {}
pull_request:
types:
- opened
- synchronize
branches:
- main
- release-*

jobs:
variables:
runs-on: ubuntu-latest
outputs:
GOLANG_VERSION: ${{ steps.go_version.outputs.GOLANG_VERSION }}
steps:
- uses: actions/checkout@v4
name: Checkout code

- name: Get Golang version
id: go_version
run: |
GOLANG_VERSION=$(./hack/golang-version.sh)
echo "GOLANG_VERSION=${GOLANG_VERSION##GOLANG_VERSION := }" >> $GITHUB_OUTPUT
check:
runs-on: ubuntu-latest
needs: variables
steps:
- uses: actions/checkout@v4
name: Checkout code

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ needs.variables.outputs.GOLANG_VERSION }}

- name: Lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: -v --timeout 5m
skip-cache: true

- name: Check golang modules
run: |
make check-modules
build:
name: Build
needs: variables
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ needs.variables.outputs.GOLANG_VERSION }}

- run: make build-cli
11 changes: 1 addition & 10 deletions .github/workflows/image.yml → .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@
name: Image

on:
pull_request:
branches:
- 'main'
- 'release-*'
push:
tags:
- 'v*.*.*'
branches:
- 'main'
- 'release-*'
workflow_call:

jobs:
docker:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: AWS Periodic Cleanup
name: Periodic actions

on:
schedule:
Expand Down
22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
timeout: 10m

linters:
enable:
- contextcheck
- errcheck
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- staticcheck
- unconvert
disable: []

linters-settings:
goimports:
local-prefixes: github.com/NVIDIA/holodeck
40 changes: 39 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.PHONY: build fmt verify release
.PHONY: build fmt verify release lint vendor mod-tidy mod-vendor mod-verify check-vendor

GO_CMD ?= go
GO_FMT ?= gofmt
Expand All @@ -27,6 +27,44 @@ IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)

PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

# Apply go fmt to the codebase
fmt:
go list -f '{{.Dir}}' $(MODULE)/... \
| xargs gofmt -s -l -w

goimports:
go list -f {{.Dir}} $(MODULE)/... \
| xargs goimports -local $(MODULE) -w

lint:
golangci-lint run ./...

mod-tidy:
@for mod in $$(find . -name go.mod); do \
echo "Tidying $$mod..."; ( \
cd $$(dirname $$mod) && go mod tidy \
) || exit 1; \
done

mod-verify:
@for mod in $$(find . -name go.mod); do \
echo "Verifying $$mod..."; ( \
cd $$(dirname $$mod) && go mod verify | sed 's/^/ /g' \
) || exit 1; \
done

mod-vendor: mod-tidy
@for mod in $$(find . -name go.mod -not -path "./deployments/*"); do \
echo "Vendoring $$mod..."; ( \
cd $$(dirname $$mod) && go mod vendor \
) || exit 1; \
done

vendor: mod-vendor

check-modules: | mod-tidy mod-verify mod-vendor
git diff --quiet HEAD -- $$(find . -name go.mod -o -name go.sum -o -name vendor)

build-action:
@rm -rf bin
GOOS=linux $(GO_CMD) build -o /go/bin/$(BINARY_NAME) cmd/action/main.go
Expand Down
14 changes: 10 additions & 4 deletions cmd/action/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package ci

import (
"crypto/rand"
"fmt"
"math/rand"
"log"
"os"

"github.com/NVIDIA/holodeck/api/holodeck/v1alpha1"
Expand Down Expand Up @@ -57,7 +58,7 @@ func Run(log *logger.FunLogger) error {
log.Info("Environment condition is Terminated no need to run Holodeck")
return nil
} else if err != nil {
log.Warning(err.Error())
log.Warning("%s", err.Error())
}
if err := cleanup(log); err != nil {
return err
Expand Down Expand Up @@ -138,10 +139,15 @@ func setCfgName(cfg *v1alpha1.Environment) {

func generateUID() string {
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"

b := make([]byte, 8)

_, err := rand.Read(b)
if err != nil {
log.Fatalf("failed to generate secure random UID: %v", err)
}

for i := range b {
b[i] = charset[rand.Intn(len(charset))]
b[i] = charset[int(b[i])%len(charset)]
}

return string(b)
Expand Down
Loading

0 comments on commit de8a35d

Please sign in to comment.