Skip to content

Instantly share code, notes, and snippets.

@simon-weber
Last active October 15, 2017 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simon-weber/8211306 to your computer and use it in GitHub Desktop.
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…
#!/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)
@reubano
Copy link

reubano commented Apr 29, 2014

How do you use this??

@sauyon
Copy link

sauyon commented Apr 30, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment