-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linters:
ci/use
now checks for CI configurations at the Git root of…
… the given project, fixing false negative on this rule when analysing project in subfolder of a monorepo. Implements git.GetGitRoot() to retrieve the root of the Git repo. Refactors the CI linter's tests to be based on files generated in a temp dir, rather than in this repo.
- Loading branch information
Showing
15 changed files
with
153 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ciproviders_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/bvobart/mllint/setools/ciproviders" | ||
"github.com/bvobart/mllint/setools/git" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetect(t *testing.T) { | ||
dir := "." | ||
providers := ciproviders.Detect(dir) | ||
require.Equal(t, []ciproviders.Provider{ciproviders.GHActions{}}, providers) | ||
|
||
dir = os.TempDir() | ||
providers = ciproviders.Detect(dir) | ||
require.Equal(t, []ciproviders.Provider{}, providers) | ||
} | ||
|
||
func TestConfigFile(t *testing.T) { | ||
dir := "." | ||
provider := ciproviders.GHActions{} | ||
configDir := provider.ConfigFile(dir) | ||
require.Equal(t, path.Join(git.GetGitRoot(dir), ".github", "workflows"), configDir) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,14 @@ import ( | |
"io/ioutil" | ||
"math" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bvobart/mllint/api" | ||
"github.com/bvobart/mllint/setools/git" | ||
"github.com/bvobart/mllint/utils" | ||
"github.com/bvobart/mllint/utils/exec" | ||
) | ||
|
||
|
@@ -23,6 +26,34 @@ func TestDetect(t *testing.T) { | |
require.False(t, git.Detect(dir)) | ||
} | ||
|
||
func TestMakeGitInfo(t *testing.T) { | ||
dir := "." | ||
info := git.MakeGitInfo(dir) | ||
require.Equal(t, "[email protected]:bvobart/mllint.git", info.RemoteURL) | ||
|
||
dir = os.TempDir() | ||
require.Equal(t, api.GitInfo{}, git.MakeGitInfo(dir)) | ||
} | ||
|
||
func TestGetGitRoot(t *testing.T) { | ||
dir := "." | ||
rootDir := git.GetGitRoot(dir) | ||
require.True(t, strings.HasPrefix(utils.AbsolutePath(dir), rootDir)) | ||
|
||
dir = os.TempDir() | ||
rootDir = git.GetGitRoot(dir) | ||
require.Equal(t, dir, rootDir) | ||
|
||
// create Git repo in temp dir, expect that temp dir | ||
dir, err := ioutil.TempDir(os.TempDir(), "mllint-tests-git-root") | ||
require.NoError(t, err) | ||
_, err = exec.CommandOutput(dir, "git", "init") | ||
require.NoError(t, err) | ||
|
||
rootDir = git.GetGitRoot(dir) | ||
require.Equal(t, dir, rootDir) | ||
} | ||
|
||
func TestIsTracking(t *testing.T) { | ||
dir := "." | ||
require.True(t, git.IsTracking(dir, "git_test.go")) | ||
|