Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export git_dir in .g10k-deploy.json #170

Closed
wants to merge 1 commit into from
Closed

Export git_dir in .g10k-deploy.json #170

wants to merge 1 commit into from

Conversation

raphink
Copy link
Contributor

@raphink raphink commented Aug 21, 2020

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 xorpaul self-assigned this Aug 21, 2020
@xorpaul
Copy link
Owner

xorpaul commented Aug 21, 2020

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
Copy link
Owner

xorpaul commented Aug 21, 2020

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

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 😏

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

@xorpaul xorpaul closed this Aug 21, 2020
@raphink
Copy link
Contributor Author

raphink commented Aug 21, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants