Last active
October 15, 2017 18:44
-
-
Save simon-weber/8211306 to your computer and use it in GitHub Desktop.
Python script to allow use of TravisCI secure arg variables that would normally be defined on each line of a build matrix, but are too large for the key size when combined.See https://github.com/travis-ci/travis-ci/issues/1736 for motivation. If you just need to secure a lot of sample data, do something like https://github.com/travis-ci/travis/i…
This file contains hidden or 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
#!/usr/bin/env python | |
from __future__ import print_function | |
""" | |
./%s 'cmd' <id-argname> <redef-argname> [<redef-argname>...] | |
Given the current environment: | |
IDARG=1 | |
FOO1=foovalue | |
BAR1=barvalue | |
FOO2=foo-unused | |
BAR2=bar-unused | |
The command: | |
./redefine 'ls -l' IDARG FOO BAR GAZ | |
Will run `ls -l` in a subprocess that uses the current environment with: | |
FOO=foovalue | |
BAR=barvalue | |
also included. | |
If cmd was executed, its return code will be used. | |
Code is licensed under the MIT license. | |
""" | |
import os | |
from subprocess import call | |
import sys | |
def redefine(arg_names, id_arg): | |
num = os.environ[id_arg] | |
for arg_name in arg_names: | |
with_num = arg_name + num | |
if with_num in os.environ: | |
os.environ[arg_name] = os.environ[with_num] | |
def show_help_and_exit(): | |
print(sys.modules[__name__].__doc__ % sys.argv[0]) | |
sys.exit(1) | |
if __name__ == '__main__': | |
if len(sys.argv) < 4: | |
show_help_and_exit() | |
redefine(sys.argv[3:], sys.argv[2]) | |
cmd_returncode = call(sys.argv[1].split(' ')) | |
sys.exit(cmd_returncode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would check for TRAVIS_SECURE_ENV_VARS and do something about it.
Probably print an error message and return 0, because having all pull requests succeed seems to be nicer than having them all fail :P