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

Add support for git-xargs registered environment variables based on arguments and flags #127

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

andyfeller
Copy link
Contributor

Description

Fixes #115.

These changes add support for git-xargs registered environment variables based on arguments and flags intended for use by the commands and scripts called by git-xargs. These environment variables start with XARGS_ to avoid collision with other use cases and include:

  • XARGS_DRY_RUN: whether --dry-run flag was provided
  • XARGS_REPO_NAME: the name of the target repository being processed
  • XARGS_REPO_OWNER: the owner of the target repository being processed

TODOs

Read the Gruntwork contribution guidelines.

  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added support for environment variables registered by git-xargs based on flags and arguments

Migration Guide

Closes gruntwork-io#115

These changes add support for git-xargs registered environment variables
based on arguments and flags intended for use by the commands and
scripts called by git-xargs.  These environment variables start with
`XARGS_` to avoid collision with other use cases and include:

- `XARGS_REPO_NAME`: the name of the repository targeted
- `XARGS_DRY_RUN`: whether `--dry-run` flag was provided

Additionally, these changes contain a basic test to ensure this feature
works as expected going forward.
While updating documentation, I realized that the original intent of
issue 115 might require the repository owner information as well as the
repository name.  This expands the initial changes and performs some
minor refactoring.
@andyfeller andyfeller changed the title Issue 115 env vars Add support for git-xargs registered environment variables based on arguments anf flags Jun 28, 2023
@carusooo
Copy link

This would address my use-case. Very much appreciated

@andyfeller
Copy link
Contributor Author

cc: @karlwithak1

@andyfeller andyfeller changed the title Add support for git-xargs registered environment variables based on arguments anf flags Add support for git-xargs registered environment variables based on arguments and flags Jun 28, 2023
@zackproser
Copy link
Contributor

@andyfeller Thanks for your PR! Your changes LGTM, so I've kicked off tests

@zackproser
Copy link
Contributor

@andyfeller would you kindly chmod +x your test-env-var script - then tests should pass! Thanks

@andyfeller
Copy link
Contributor Author

@zackproser : I'm currently working on my personal laptop being out of office, the script appears to match the permissions of the others on WSL:

andyfeller@WIN-29L6KJF8DED:/mnt/c/Users/andre/Documents/Workspace/andyfeller/git-xargs/data/test/_testscripts$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal
andyfeller@WIN-29L6KJF8DED:/mnt/c/Users/andre/Documents/Workspace/andyfeller/git-xargs/data/test/_testscripts$ ls -l
total 4
-rwxrwxrwx 1 andyfeller andyfeller 1249 Jun 28 08:29 add-license.sh
-rwxrwxrwx 1 andyfeller andyfeller   83 Jun 28 08:29 bad-perm.sh
-rwxrwxrwx 1 andyfeller andyfeller  306 Jun 28 09:30 test-env-vars.sh
-rwxrwxrwx 1 andyfeller andyfeller   59 Jun 28 08:29 test-python.py
-rwxrwxrwx 1 andyfeller andyfeller   55 Jun 28 08:29 test-ruby.rb
-rwxrwxrwx 1 andyfeller andyfeller  293 Jun 28 08:29 test-stdout-stderr.sh

This appears to differ on Git Bash for Windows:

andre@WIN-29L6KJF8DED MINGW64 ~/Documents/Workspace/andyfeller/git-xargs/data/test/_testscripts (issue-115-env-vars)
$ ll
total 9
-rwxr-xr-x 1 andre 197609 1249 Jun 28 08:29 add-license.sh*
-rwxr-xr-x 1 andre 197609   83 Jun 28 08:29 bad-perm.sh*
-rwxr-xr-x 1 andre 197609  306 Jun 28 09:30 test-env-vars.sh*
-rwxr-xr-x 1 andre 197609   59 Jun 28 08:29 test-python.py*
-rwxr-xr-x 1 andre 197609   55 Jun 28 08:29 test-ruby.rb*
-rwxr-xr-x 1 andre 197609  293 Jun 28 08:29 test-stdout-stderr.sh*

When trying to change the mode of the file, git is saying there are no changes to be committed 😞. I know this might be a Windows / Linux / Mac translation issue, so I'd appreciate a hand as I won't be back on my work machine until this weekend at the earliest.

@andyfeller
Copy link
Contributor Author

Trying to utilize git update-index to force the issue with windows:

$ git update-index --chmod=+x test-env-vars.sh

@zackproser
Copy link
Contributor

Thanks, Andy! LGTM, so approving and merging.

@zackproser zackproser merged commit 6847fd2 into gruntwork-io:master Jun 30, 2023
@zackproser
Copy link
Contributor

@andyfeller Thanks again - https://github.com/gruntwork-io/git-xargs/releases/tag/v0.1.9 is the latest release that will have your changes. v0.1.8 had a build issue related to the Go version, which I bumped in a subsequent release.

@andyfeller
Copy link
Contributor Author

@zackproser : thank you and thank you for OSSing your work for others ✨ I hope to contribute back more, an example of a wrapper script that will demonstrate calling multiple commands and scripts.

In my use case, I have repositories created from a template, which has been updated with new files that the children should get. Additionally, there have been new issue / PR labels I want to push out, which is was somewhat difficult without this PR due to knowing if --dry-run.

@zackproser
Copy link
Contributor

@andyfeller Thanks so much for your kind words. It is my sincere pleasure.

That sounds terrific and I'd bet many others would benefit from that as well. I initially had this scripts folder here thinking it might be a decent place for the community to compile such scripts / examples - but perhaps those belong in a separate repo? Not sure.

@andyfeller andyfeller deleted the issue-115-env-vars branch July 19, 2023 18:27
@andyfeller
Copy link
Contributor Author

@zackproser : finally finished refactoring my initial prototype wrapping around git-xargs and released it as a GitHub CLI extension: https://github.com/andyfeller/gh-publicize

I'd love to chat a bit regarding your thoughts, can open an issue or discussion.

@zackproser
Copy link
Contributor

@andyfeller Wow! This looks super cool - I especially love the fact you made it a gh extension - I've found those to work really well in the past. I love the proposed use cases you have as well - they all make a ton of sense and were part of what originally urged us on to write git-xargs.

Speaking of which - one other idea I always thought would be awesome in conjunction with this stuff is some kind of light engine that could provide the git diff between some desired state and the current state of a given repo - which could output git-xargs or gh-publicize instructions / API calls - to essentially open the PRs which would get your repos all up to date and compliant with what you've set as your template repo - if I'm making sense.

One logistical note - I'm no longer working at Gruntwork, so I'm unlikely to have time to return to this anytime soon, but I'll bet @brikis98 would be keen to know about this as well.

Seriously - very cool work 🎉

@andyfeller
Copy link
Contributor Author

andyfeller commented Aug 1, 2023

Speaking of which - one other idea I always thought would be awesome in conjunction with this stuff is some kind of light engine that could provide the git diff between some desired state and the current state of a given repo - which could output git-xargs or gh-publicize instructions / API calls - to essentially open the PRs which would get your repos all up to date and compliant with what you've set as your template repo - if I'm making sense.

So is this less of a push model and more of a pull? A process that reverse engineers what it is missing to match the source repository in question, yeah?

One logistical note - I'm no longer working at Gruntwork, so I'm unlikely to have time to return to this anytime soon

Congratulations on the new adventure! Happy to talk shop with others as I appreciate the work here ❤️

@zackproser
Copy link
Contributor

@andyfeller 😂 Precisely - your gif game is on point!

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.

Set current repo as Env var
3 participants