deploy_files.py 952 Bytes
Newer Older
Paul McCarthy's avatar
Paul McCarthy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python


import os
import sys
import shutil


def main():

    dest                  = sys.argv[1]
    files                 = sys.argv[2:]
    publish_from_branches = os.environ.get('PUBLISH_FROM_BRANCHES', '')
    branch                = os.environ.get('CI_COMMIT_BRANCH', None)
    tag                   = os.environ.get('CI_COMMIT_TAG',    None)

    allow_publish = ((tag is not None) or
                     ((branch is not None) and
                      (branch in publish_from_branches)))

    if not allow_publish:
        print('Publishing is only allowed from tags or '
              f'these branches: {publish_from_branches}')
        sys.exit(1)

    if tag is not None:
        print(f'Publishing files from tag {tag}')
    else:
        print(f'Publishing files from branch {branch}')

    for src in files:
        print(f'Copying {src} to {dest}')
        shutil.copy(src, dest)


if __name__ == '__main__':
    main()