Skip to content

Commit

Permalink
Fix CI (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm authored Mar 27, 2024
1 parent 4d0a2e6 commit 814926b
Show file tree
Hide file tree
Showing 18 changed files with 285 additions and 374 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ jobs:
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Ack, see https://github.com/github/codeql/issues/15647 - To remove when v1.22 will be correctly supported
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: ./go.mod
check-latest: true
cache: true
cache-dependency-path: ./go.sum

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- revive # see disabled linters below
- unused # see disabled linters below
disable:
- depguard # Should not be enabled by default but seems anyway .....
- structcheck # deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
- ifshort # deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner.
- interfacer # deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ help: ## ❓ Dislay this help
.PHONY: configure-dev-env
configure-dev-env: ## 🤖 Install required libraries for dev environment
configure-dev-env:
go install github.com/posener/goreadme/cmd/goreadme@latest
go install github.com/posener/goreadme/cmd/goreadme@v1
.PHONY: configure-test-env
configure-test-env: ## 🤖 Install required libraries for test environment (golint, staticcheck, etc)
configure-test-env: configure-dev-env
configure-test-env:
# Nothing to install currently
go install github.com/golangci/golangci-lint/cmd/[email protected]

##—— 📝 Documentation —————————————————————————————————————————————————
.PHONY: build-doc
Expand All @@ -60,7 +60,7 @@ build: ## 🗜️ Build package
#### Use build_o="..." to specify build options
$(eval build_o ?=)
build:
go build -v $(build_o)
go build -v -o github-tf $(build_o)

.PHONY: verify-deps
verify-deps: ## 🗜️ Verify dependencies
Expand Down
12 changes: 6 additions & 6 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ var (

## Functions

### func [ApplyBranchProtectionsTemplate](./repo_config_computer.go#L112)
### func [ApplyBranchProtectionsTemplate](./repo_config_computer.go#L110)

`func ApplyBranchProtectionsTemplate(config *GhRepoConfig, templates *TemplatesConfig) error`

### func [ApplyBranchesTemplate](./repo_config_computer.go#L63)
### func [ApplyBranchesTemplate](./repo_config_computer.go#L61)

`func ApplyBranchesTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) error`

Expand Down Expand Up @@ -340,7 +340,7 @@ var (

`type GhBranchConfig struct { ... }`

#### func [ApplyBranchTemplate](./repo_config_computer.go#L154)
#### func [ApplyBranchTemplate](./repo_config_computer.go#L152)

`func ApplyBranchTemplate(branchConfig *GhBranchConfig, templates *TemplatesConfig) (*GhBranchConfig, error)`

Expand Down Expand Up @@ -398,7 +398,7 @@ No schema validation will be performed, use loadBranchTemplateFromFile instead !

`type GhBranchProtectionConfig struct { ... }`

#### func [ApplyBranchProtectionTemplate](./repo_config_computer.go#L138)
#### func [ApplyBranchProtectionTemplate](./repo_config_computer.go#L136)

`func ApplyBranchProtectionTemplate(
branchProtectionConfig *GhBranchProtectionConfig,
Expand Down Expand Up @@ -454,11 +454,11 @@ No schema validation will be performed, use loadBranchProtectionTemplateFromFile

`type GhRepoConfig struct { ... }`

#### func [ApplyRepositoryTemplate](./repo_config_computer.go#L50)
#### func [ApplyRepositoryTemplate](./repo_config_computer.go#L48)

`func ApplyRepositoryTemplate(repoConfig *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)`

#### func [ComputeRepoConfig](./repo_config_computer.go#L11)
#### func [ComputeRepoConfig](./repo_config_computer.go#L9)

`func ComputeRepoConfig(base *GhRepoConfig, templates *TemplatesConfig) (*GhRepoConfig, error)`

Expand Down
10 changes: 4 additions & 6 deletions core/config_computer_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package core_test

import (
"fmt"
"errors"
"testing"

differ "github.com/andreyvit/diff"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestComputeConfig(t *testing.T) {
},
},
nil,
fmt.Errorf("error during computation:\n\t - repo #0: repository name is mandatory\n\t - repo #1: repository name is mandatory"),
errors.New("error during computation:\n\t - repo #0: repository name is mandatory\n\t - repo #1: repository name is mandatory"),
},
"Underlying computation error": {
&core.Config{
Expand All @@ -82,18 +82,16 @@ func TestComputeConfig(t *testing.T) {
},
},
nil,
fmt.Errorf("error during computation:\n\t - repository a_name: repository template not found as none available"),
errors.New("error during computation:\n\t - repository a_name: repository template not found as none available"),
},
}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel tests
tc := tc // Reinit var for parallel tests

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual, err := core.ComputeConfig(tc.value)
if tc.error != nil {
if err == nil {
Expand Down
16 changes: 4 additions & 12 deletions core/config_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ func TestConfig_GetRepo(t *testing.T) {
}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel tests
tc := tc // Reinit var for parallel tests

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := tc.value.GetRepo(tc.name)
if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -79,13 +77,11 @@ func TestTemplatesConfig_GetRepo(t *testing.T) {
}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel tests
tc := tc // Reinit var for parallel tests

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := tc.value.GetRepo(tc.name)
if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -123,13 +119,11 @@ func TestTemplatesConfig_GetBranch(t *testing.T) {
}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel tests
tc := tc // Reinit var for parallel tests

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := tc.value.GetBranch(tc.name)
if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -167,13 +161,11 @@ func TestTemplatesConfig_GetBranchProtection(t *testing.T) {
}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel tests
tc := tc // Reinit var for parallel tests

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := tc.value.GetBranchProtection(tc.name)
if diff := cmp.Diff(tc.expected, actual); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down
25 changes: 7 additions & 18 deletions core/gh2tf_repo_mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ func TestMapToRepositoryRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := core.MapToRepositoryRes(tc.value, valGen, tfRepoId)
if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -176,13 +174,11 @@ func TestMapToBranchRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := core.MapToBranchRes(tc.name, tc.value, valGen, tc.repo, tfId, tc.links...)
if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -270,13 +266,11 @@ func TestMapToDefaultBranchRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := core.MapToDefaultBranchRes(tc.value, valGen, tc.repo, tfId, tc.links...)
if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -380,13 +374,11 @@ func TestMapDefaultBranchToBranchProtectionRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := core.MapDefaultBranchToBranchProtectionRes(tc.value, valGen, tc.repo, tfId, tc.links...)
if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -475,15 +467,14 @@ func TestMapBranchToBranchProtectionRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

branchNameTmp := tc.name
actual := core.MapBranchToBranchProtectionRes(&branchNameTmp, tc.value, valGen, tc.repo, tfId, tc.links...)

if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
}
Expand Down Expand Up @@ -575,13 +566,11 @@ func TestMapToBranchProtectionRes(t *testing.T) {
diffOpts := []cmp.Option{cmp.AllowUnexported(tfsig.ValueGenerator{}), cmp.AllowUnexported(tfsig.IdentTokenMatcher{})}

for tcname, tc := range cases {
tcname := tcname // Reinit var for parallel test
tc := tc // Reinit var for parallel test

t.Run(
tcname,
func(t *testing.T) {
t.Parallel()

actual := core.MapToBranchProtectionRes(tc.value, valGen, tc.repo, tfId, tc.links...)
if diff := cmp.Diff(tc.expected, actual, diffOpts...); diff != "" {
t.Errorf("Config mismatch (-want +got):\n%s", diff)
Expand Down
Loading

0 comments on commit 814926b

Please sign in to comment.