xorpaul / g10k

my r10k fork in Go
Apache License 2.0
125 stars 50 forks source link

Export git_dir in .g10k-deploy.json #170

Closed raphink closed 4 years ago

raphink commented 4 years ago

When executing Git commands in the context of Puppet (for example to retrieve the commit message in config_version or to generate a serial based on the last commit reference of a file in the repo), it's useful to know where the Git dir is located so you don't need to hardcode it.

This PR stores the location of the Git dir in the .g10k-deploy.json file so it can be retrieved easily.

E.g. config_version script, before:

require 'json'
deploy_info = JSON.parse(File.read("#{__dir__}/.g10k-deploy.json"))
sha = deploy_info['signature']
git_dir = '/etc/puppetlabs/code/cache/environments/main.git'  # 😱
message = `git --git-dir #{git_dir} log -1 --pretty='%s' "#{sha}"`.chomp

after:

require 'json'
deploy_info = JSON.parse(File.read("#{__dir__}/.g10k-deploy.json"))
sha = deploy_info['signature']
git_dir = deploy_info['git_dir']    # 😁
message = `git --git-dir #{git_dir} log -1 --pretty='%s' "#{sha}"`.chomp
xorpaul commented 4 years ago

Sounds good to me, but I need to fix the hashdeep verification files for the tests, before I can merge this.

 g10k_test.go:2615: hashdeep terminated with 1, but we expected exit status 0
        Output: /tmp/out/full_single/.g10k-deploy.json: No match
        /tmp/out/example_single/.g10k-deploy.json: No match
        /tmp/out/example_single_git/.g10k-deploy.json: No match
        /tmp/out/example_single_git/.g10k-deploy.json: Known file not used
        /tmp/out/full_single/.g10k-deploy.json: Known file not used
        /tmp/out/example_single/.g10k-deploy.json: Known file not used
        hashdeep: Audit failed
           Input files examined: 0
          Known files expecting: 0
                  Files matched: 240
        Files partially matched: 0
                    Files moved: 0
                New files found: 3
          Known files not found: 3
xorpaul commented 4 years ago

I've tried to add the fixed hashdeep verification files to this MR, but I failed :disappointed:

But I've added your code changes and also added the remote Git repository URL of the control repository to the .g10k-deploy.json file.

{
  "name": "blacklist",
  "signature": "a9fb286a6beb56130c735f86a0c41f100c1ec4dc",
  "started_at": "0001-01-01T00:00:00Z",
  "finished_at": "0001-01-01T00:00:00Z",
  "deploy_success": true,
  "puppetfile_checksum": "7ef69e22328d867a31301d545a391e75e3f9b5a48036b6e5f531a069a987cc74",
  "git_dir": "cache/environments/example.git",
  "git_url": "https://github.com/xorpaul/g10k-environment.git"
}

Maybe this is helpful to someone somewhere :smirk:

Check out the new release: https://github.com/xorpaul/g10k/releases/tag/v0.8.12

raphink commented 4 years ago

Not sure why you chose to close and code again instead of merging this, but thanks for implementing anyway!

Is it normal that git_dir is a relative path in your output?