This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read configuration as tracked in previous run
This commit makes sure that the previous run's configuration path is saved. It also makes sure the path is read at the previous run's revision to match existing headers based on previous run's config data. It also makes sure that the tracking file is not touched when there is no file to process. Fixes #27.
- Loading branch information
Florent Biville
committed
Jan 29, 2019
1 parent
624c017
commit ece3139
Showing
25 changed files
with
939 additions
and
540 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
#!/bin/bash | ||
set -e | ||
set -euo pipefail | ||
|
||
dep ensure | ||
rm vcs_mocks/*.go || true && rm fs_mocks/*.go || true \ | ||
&& go get github.com/vektra/mockery/.../ \ | ||
|
||
rm helper_mocks/*.go || true \ | ||
&& rm vcs_mocks/*.go || true \ | ||
&& rm fs_mocks/*.go || true \ | ||
&& rm core_mocks/*.go || true | ||
|
||
go get github.com/vektra/mockery/.../ \ | ||
&& mockery -output helper_mocks -outpkg helper_mocks -dir helper -name Clock \ | ||
&& mockery -output vcs_mocks -outpkg vcs_mocks -dir vcs -name Vcs \ | ||
&& mockery -output vcs_mocks -outpkg vcs_mocks -dir vcs -name VersioningClient \ | ||
&& mockery -output fs_mocks -outpkg fs_mocks -dir fs -name FileWriter \ | ||
&& mockery -output fs_mocks -outpkg fs_mocks -dir fs -name FileReader \ | ||
&& mockery -output fs_mocks -outpkg fs_mocks -dir fs -name File \ | ||
&& mockery -output fs_mocks -outpkg fs_mocks -dir fs -name PathMatcher \ | ||
&& mockery -output fs_mocks -outpkg fs_mocks -dir fs -name ExecutionTracker | ||
&& mockery -output core_mocks -outpkg core_mocks -dir core -name ExecutionTracker | ||
|
||
go build ./... | ||
go clean -testcache && go test -v ./... | ||
rm headache 2> /dev/null || true && go build |
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,59 @@ | ||
package core | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/fbiville/headache/fs" | ||
jsonsch "github.com/xeipuuv/gojsonschema" | ||
"log" | ||
) | ||
|
||
type ConfigurationLoader struct { | ||
Reader fs.FileReader | ||
} | ||
|
||
func (cl *ConfigurationLoader) ReadConfiguration(configFile *string) (*Configuration, error) { | ||
err := cl.validateConfiguration(configFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
payload, err := cl.Reader.Read(*configFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
configuration, err := cl.UnmarshallConfiguration(payload) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return configuration, err | ||
} | ||
|
||
func (cl *ConfigurationLoader) UnmarshallConfiguration(configurationPayload []byte) (*Configuration, error) { | ||
result := Configuration{} | ||
err := json.Unmarshal(configurationPayload, &result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &result, nil | ||
} | ||
|
||
func (cl *ConfigurationLoader) validateConfiguration(configFile *string) error { | ||
schema := loadSchema() | ||
if schema == nil { | ||
return nil | ||
} | ||
jsonSchemaValidator := JsonSchemaValidator{ | ||
Schema: schema, | ||
FileReader: cl.Reader, | ||
} | ||
return jsonSchemaValidator.Validate("file://" + *configFile) | ||
} | ||
|
||
func loadSchema() *jsonsch.Schema { | ||
schema, err := jsonsch.NewSchema(jsonsch.NewReferenceLoader("https://fbiville.github.io/headache/v1.0.0-M01/schema.json")) | ||
if err != nil { | ||
log.Printf("headache configuration warning: cannot load schema, skipping configuration validation. See reason below:\n\t%v\n", err) | ||
return nil | ||
} | ||
return schema | ||
} |
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
Oops, something went wrong.