GithubHelp home page GithubHelp logo

kitabisa / go-ci Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 12 KB

A Go package that tells you whether the current environment is within a CI/CD pipeline.

License: Apache License 2.0

Go 100.00%

go-ci's Introduction

go-ci

GoDoc tests

A Go package that provides utilities for detecting and handling CI/CD environments. It also has testing helper functions to conditionally skip or fail tests/benchmarks/fuzzing based on the CI/CD status.

Usage

Use IsCI or IsNotCI to check if the current environment is within a CI/CD pipeline.

go get github.com/kitabisa/go-ci@latest

Note

See CICDEnvVars for currently supported CI/CD pipelines.

Testing helper function

Import the go-ci package into your *_test.go files.

import (
	"testing"

	"github.com/kitabisa/go-ci"
	"github.com/stretchr/testify/assert"
)

func shouldSkip(t *testing.T) {
	assert.True(t, t.Skipped())
	t.Logf("Skipping '%s' test in CI/CD environment", t.Name())
}

func TestFuncShoulNotInCI(t *testing.T) {
	defer shouldSkip(t)

	t.Setenv("CI", "true")
	ci.SkipTestIfCI(t)

	// do your test...
}

Important

Please note that the checking mechanism uses a cache, so do NOT simulating CI/CD environment variables in actual test cases.

Available testing helper functions

func FailBenchmarkIfCI(b *testing.B)
func FailBenchmarkIfNotCI(b *testing.B)
func FailFuzzIfCI(f *testing.F)
func FailFuzzIfNotCI(f *testing.F)
func FailTestIfCI(t *testing.T)
func FailTestIfNotCI(t *testing.T)
func SkipBenchmarkIfCI(b *testing.B)
func SkipBenchmarkIfNotCI(b *testing.B)
func SkipFuzzIfCI(f *testing.F)
func SkipFuzzIfNotCI(f *testing.F)
func SkipTestIfCI(t *testing.T)
func SkipTestIfNotCI(t *testing.T)

Benchmark

$ go test -race -run="^$" -bench .
goos: linux
goarch: amd64
pkg: github.com/kitabisa/go-ci
cpu: 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz
BenchmarkIsCI/true-16         	39761295	        28.22 ns/op	       0 B/op	       0 allocs/op
BenchmarkIsCI/false-16        	42846458	        34.67 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/kitabisa/go-ci	3.680s

License

go-ci is released by @dwisiswant0 under the Apache 2.0 license. See LICENSE.

go-ci's People

Contributors

dwisiswant0 avatar

Stargazers

Lucas Bremgartner avatar Muh Zaqi Ikhwanul Kiram avatar Vishnu Ganesan avatar Orkan Alat avatar Can Evgin avatar  avatar

Watchers

Sactio Swastioyono avatar  avatar Firdaus Rachman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.