Skip to content

Validate Local Commits

Marcello de Sales edited this page Aug 13, 2018 · 4 revisions

Contents

  1. Requirements
  2. Commit your changes
  3. Validation upon "git push"
  4. Validation upon "git push" of new branches
  5. Fixing errors

Requirements

Requirements:

Commit your changes

As usual, make changes to your configuration files and commit the changes. No matter how many commits you have created, the Config Validator will be executed by Github Enterprise upon attempting to merge the changes. For instance, the following example shows multiple commits.

$ git log --oneline --decorate --graph --all
* e80c306 (HEAD -> develop) CFG-462: New broken change: .json file
* 1dc0b77 CFG-462: New broken change: .properties file
* b7963fa CFG-233: New broken change: .yml file
* 1cd8bc2 (origin/develop) CFG: Onboarding 'sp_boot_sample:4036368758221500096:QAL'

Those new 3 commits introduced errors. For example:

$ git show
commit e80c30606223ee39aeddf3f01086523f0288ed6d
Author: Marcello de Sales <Marcello.DeSales@gmail.com>
Date:   Mon Feb 27 22:10:30 2017 -0800

    CFG-462: New broken change: .json file

diff --git a/.matrix.json b/.matrix.json
index 16df728..0a45faf 100644
--- a/.matrix.json
+++ b/.matrix.json
@@ -1,8 +1,12 @@
+WRONG NAME ON JSON
 {
        "appName": "publisher",
        "profilesSequence": [
                "env",
                "dc",
+
+               "introduced error on json file"
+
                "onboard"
        ],
        "sigVersions": ["V2"],

$ git show 1dc0b77
commit 1dc0b7704d9191f08797cf4f34d4f116a5abe9e7
Author: Marcello de Sales <Marcello.DeSales@gmail.com>
Date:   Mon Feb 27 22:09:05 2017 -0800

    CFG-462: New broken change: .properties file

diff --git a/publisher.properties b/publisher.properties
index ce0c415..6c3de28 100644
--- a/publisher.properties
+++ b/publisher.properties
@@ -3,6 +3,8 @@
 # default logging level
 # logging.level.: warn
 
+ADDING WRONG COMMENT OR KEY 
+
 # disable management
 endpoints.enabled: true

commit b7963fac97c2a33cf1a9a76262137e258dcdcc5d
Author: Marcello de Sales <Marcello.DeSales@gmail.com>
Date:   Mon Feb 27 14:15:43 2017 -0800

    CFG-233: New broken change: .yml file

diff --git a/publisher-onboard_preprod.yml b/publisher-onboard_preprod.yml
index ae45a1b..9f84b22 100644
--- a/publisher-onboard_preprod.yml
+++ b/publisher-onboard_preprod.yml
@@ -1,4 +1,6 @@
----
+dsoidosid 
+
+sdoosid oi ---
 spring:
   cloud:
     config:

Sometimes those errors are invisible to naked eyes during the stressful times. The next section shows the result of the Config Validator execution.

Validation upon "git push"

The validation will be executed by Github Enterprise when the commit objects are received. When the validation identifies errors, the git push command will fail showing:

  • The error about the message returned by the validator.
  • The list of all files validated, including the parser's error message detailing why the file is invalid.
  • Valid files are listed prefixed with (v).
  • Invalid files are listed prefixed with (x).
  • The name of the branch that rejected the commits to be merged in the origin.

Here's an example of such event:

$ git push origin develop
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 1.06 KiB | 0 bytes/s, done.
Total 9 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 4 local objects.
remote: validate_config_files.py: failed with exit status 1
remote: ##################################################
remote: ###### Spring Cloud Config Validator 1.0.0 #######
remote: ##################################################
remote: Processing commit=e80c30606223ee39aeddf3f01086523f0288ed6d ref=refs/heads/develop
remote: => Validating 1cd8bc2daf38fd99d2b5779882fad83d3f76713f..e80c30606223ee39aeddf3f01086523f0288ed6d
remote: (x) File publisher.properties is invalid: local variable 'wspacere' referenced before assignment
remote: (x) File publisher-onboard_preprod.yml is invalid: mapping values are not allowed here
remote:   in "publisher-onboard_preprod.yml", line 4, column 7
remote: (x) File .matrix.json is invalid: No JSON object could be decoded
To git@github.company.com:servicesplatform-tools/spring-cloud-config-publisher-config.git
 ! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'git@github.company.com:servicesplatform-tools/spring-cloud-config-publisher-config.git'

At this point, the only way to push the changes to the config repo is to fix the syntax error in the file.

IMPORTANT

  • When the validator rejects a commit, the commit is NOT pushed to Github Enterprise.
  • The broken set of commits you are trying to push is still in your local workspace.
  • You MUST fix the errors before trying to push commits again.

Validation upon "git push" of new branches

Because branches are pointers in Git, there is no way to understand where the new branch has been branched off of. For this reason, when you execute git push of a new branch to the origin, the validator will validate all the current files in the current HEAD of the branch. For instance:

~/dev/github/intuit/servicesplatform-tools/spring-cloud-config-publisher-config on  feature/new-validation ⌚ 13:12:14
$ git push origin feature/new-validation
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 1.06 KiB | 0 bytes/s, done.
Total 9 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 4 local objects.
remote: validate_config_files.py: failed with exit status 1
remote: ##################################################
remote: ###### Intuit Spring Cloud Config Validator 1.0.0 #######
remote: ##################################################
remote: Validating new branch...
remote: Processing commit=e80c30606223ee39aeddf3f01086523f0288ed6d ref=refs/heads/feature/new-validation
remote: => Validating SHA e80c30606223ee39aeddf3f01086523f0288ed6d
remote: (v) File publisher-onboard_prod.yml is valid!
remote: (x) File publisher-onboard_preprod.yml is invalid: mapping values are not allowed here
remote:   in "publisher-onboard_preprod.yml", line 4, column 7
remote: (v) File publisher-e2e.yml is valid!
remote: (v) File publisher-prd.yml is valid!
remote: (v) File publisher-dev.yml is valid!
remote: (v) File publisher-qal.yml is valid!
remote: (v) File publisher-onboard_preprodtemp.yml is valid!
remote: (x) File publisher.properties is invalid: local variable 'wspacere' referenced before assignment
remote: (v) File publisher-prf.yml is valid!
remote: (x) File .matrix.json is invalid: No JSON object could be decoded
To git@github.company.com:servicesplatform-tools/spring-cloud-config-publisher-config.git
 ! [remote rejected] feature/new-validation -> feature/new-validation (pre-receive hook declined)
error: failed to push some refs to 'git@github.company.com:servicesplatform-tools/spring-cloud-config-publisher-config.git'

This validation will guarantee that new branches with broken configuration cannot be pushed until the errors are fixed.

IMPORTANT

  • When the validator rejects a commit, the commit is NOT pushed to Github Enterprise.
  • The broken set of commits you are trying to push is still in your local workspace.
  • You MUST fix the errors before trying to push commits again.

Fixing Errors

When you have local problems, you have different options:

  • Fix each individual file.
  • Create as many new commits as desired.
  • Try to push again.

If you prefer, you can execute the same validation script locally by downloading it.