2
2
from __future__ import print_function
3
3
import subprocess , sys , os
4
4
5
+ pypirc_contents = \
6
+ """[distutils]
7
+ index-servers =
8
+ pypi
9
+ pypitest
10
+
11
+ [pypi]
12
+ repository=https://pypi.python.org/pypi
13
+ username=%s
14
+ password=%s
15
+
16
+ [pypitest]
17
+ repository=https://testpypi.python.org/pypi
18
+ username=%s
19
+ password=%s
20
+ """ % (os .environ ['PYPI_USER' ], os .environ ['PYPI_PASS' ],
21
+ os .environ ['PYPI_USER' ], os .environ ['PYPI_PASS' ])
22
+
5
23
print ('Travis CI Passed' )
6
24
7
25
# Prevents merging certain files, i.e. .travis.yml
@@ -23,82 +41,107 @@ for branch in branches:
23
41
print ('Branches existing on Travis Server: %s' % output )
24
42
print ('Branchname (or SHA) is %s' % branchname )
25
43
26
- # Relevant:
27
- # (Explains the usage of merge-base and merge-tree commands to view if merge is valid
28
- # http://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option
29
-
30
- # Attempt to auto-merge develop into pre-beta if travis tests pass
31
-
32
-
33
- print ('Resetting remote/origin' )
34
- subprocess .call (['git' , 'remote' , 'remove' , 'origin' ])
35
- print ('Done.' )
36
- print ('Re-adding origin..' )
37
- subprocess .call (['git' , 'remote' , 'add' , 'origin' , 'https://github.com/pyGSTio/pyGSTi.git' ])
38
- print ('Done.' )
39
- print ('Updating remote' )
40
- subprocess .call (['git' , 'remote' , 'update' ])
41
- subprocess .call (['git' , 'fetch' ])
42
-
43
- print ('Setting up user credentials' )
44
-
45
- EMAIL = os .environ ['EMAIL' ]
46
- USER = os .environ ['USER' ]
47
- subprocess .call (['git' , 'config' , '--global' , 'user.email' , EMAIL ])
48
- subprocess .call (['git' , 'config' , '--global' , 'user.name' , USER ])
49
- print ('Done' )
50
-
51
- print ('Getting the latest version of beta' )
52
- print ('Deleting local version, if it exists' )
53
- subprocess .call (['git' , 'branch' , '-D' , 'beta' ]) # So that we can verify beta doesn't exist locally
54
- print ('Fetching from origin' )
55
- subprocess .call (['git' , 'fetch' , 'origin' ]) # Then grab it..
56
- print ('Recreating local branch' )
57
- subprocess .call (['git' , 'checkout' , '-b' , 'beta' , 'origin/beta' ]) # And switch to it
58
- print ('Done.' )
59
- print ('Getting SHA of merge-base (To view merge tree between %s and beta' % branchname )
60
- SHAOut = subprocess .check_output (['git' ,
61
- 'merge-base' ,
62
- branchname , # OUR version of develop
63
- 'beta' ] )
64
- SHA = SHAOut .decode ('utf-8' ).replace ('\n ' , '' )
65
- print ('Done. SHA was %s' % SHA )
66
- print ('Creating merge-tree' )
67
- output = subprocess .check_output (['git' ,
68
- 'merge-tree' ,
69
- SHA ,
70
- 'beta' ,
71
- branchname ]) # View merge tree between beta and (our) develop
72
- output = output .decode ('utf-8' , 'ignore' )
73
- print ('Done:' )
74
- # print(output)
44
+ HOME = os .environ ['HOME' ]
45
+ TRAVIS_BRANCH = os .environ ['TRAVIS_BRANCH' ]
46
+ TRAVIS_PULL_REQUEST = os .environ ['TRAVIS_PULL_REQUEST' ]
47
+ print ("TRAVIS_BRANCH = " ,TRAVIS_BRANCH )
48
+ print ("TRAVIS_PULL_REQUEST = " ,TRAVIS_PULL_REQUEST )
75
49
76
- canMerge = ('<' * 5 ) not in output # '<' * 5 avoids git finding the expanded string in this file and thinking it is a merge conflict
77
50
78
- if canMerge :
79
- print ('Merge of develop into beta is possible' )
80
- # The below code is active, but only for testing
81
- subprocess .call (['git' , 'merge' , '--no-ff' , '--no-commit' , 'develop' ]) #into beta
82
- print ('Merge command finished.' )
83
- print ('Staging files..' )
84
- subprocess .call (['git' , 'add' , '-u' ])
85
- print ('Committing..' )
86
- subprocess .call (['git' , 'commit' , '--no-verify' , '-m' ,
87
- 'Auto-merged develop -> beta (No conflicts, CI passed)' ])
88
- print ('Commit finished' )
51
+ if TRAVIS_BRANCH == "develop" and TRAVIS_PULL_REQUEST == "false" :
52
+
53
+ # Relevant:
54
+ # (Explains the usage of merge-base and merge-tree commands to view if merge is valid
55
+ # http://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option
56
+
57
+ # Attempt to auto-merge develop into pre-beta if travis tests pass
58
+
59
+
60
+ print ('Resetting remote/origin' )
61
+ subprocess .call (['git' , 'remote' , 'remove' , 'origin' ])
62
+ print ('Done.' )
63
+ print ('Re-adding origin..' )
64
+ subprocess .call (['git' , 'remote' , 'add' , 'origin' , 'https://github.com/pyGSTio/pyGSTi.git' ])
65
+ print ('Done.' )
66
+ print ('Updating remote' )
67
+ subprocess .call (['git' , 'remote' , 'update' ])
68
+ subprocess .call (['git' , 'fetch' ])
69
+
70
+ print ('Setting up user credentials' )
71
+
72
+ EMAIL = os .environ ['EMAIL' ]
73
+ USER = os .environ ['USER' ]
74
+ subprocess .call (['git' , 'config' , '--global' , 'user.email' , EMAIL ])
75
+ subprocess .call (['git' , 'config' , '--global' , 'user.name' , USER ])
76
+ print ('Done' )
77
+
78
+ print ('Getting the latest version of beta' )
79
+ print ('Deleting local version, if it exists' )
80
+ subprocess .call (['git' , 'branch' , '-D' , 'beta' ]) # So that we can verify beta doesn't exist locally
81
+ print ('Fetching from origin' )
82
+ subprocess .call (['git' , 'fetch' , 'origin' ]) # Then grab it..
83
+ print ('Recreating local branch' )
84
+ subprocess .call (['git' , 'checkout' , '-b' , 'beta' , 'origin/beta' ]) # And switch to it
85
+ print ('Done.' )
86
+ print ('Getting SHA of merge-base (To view merge tree between %s and beta' % branchname )
87
+ SHAOut = subprocess .check_output (['git' ,
88
+ 'merge-base' ,
89
+ branchname , # OUR version of develop
90
+ 'beta' ] )
91
+ SHA = SHAOut .decode ('utf-8' ).replace ('\n ' , '' )
92
+ print ('Done. SHA was %s' % SHA )
93
+ print ('Creating merge-tree' )
94
+ output = subprocess .check_output (['git' ,
95
+ 'merge-tree' ,
96
+ SHA ,
97
+ 'beta' ,
98
+ branchname ]) # View merge tree between beta and (our) develop
99
+ output = output .decode ('utf-8' , 'ignore' )
100
+ print ('Done:' )
101
+ # print(output)
102
+
103
+ canMerge = ('<' * 5 ) not in output # '<' * 5 avoids git finding the expanded string in this file and thinking it is a merge conflict
104
+
105
+ if canMerge :
106
+ print ('Merge of develop into beta is possible' )
107
+ # The below code is active, but only for testing
108
+ subprocess .call (['git' , 'merge' , '--no-ff' , '--no-commit' , 'develop' ]) #into beta
109
+ print ('Merge command finished.' )
110
+ print ('Staging files..' )
111
+ subprocess .call (['git' , 'add' , '-u' ])
112
+ print ('Committing..' )
113
+ subprocess .call (['git' , 'commit' , '--no-verify' , '-m' ,
114
+ 'Auto-merged develop -> beta (No conflicts, CI passed)' ])
115
+ print ('Commit finished' )
116
+
117
+ PUSHKEY = os .environ ['PUSHKEY' ]
118
+ push_uri = 'https://%s:%[email protected] /pyGSTio/pyGSTi.git' % (
USER ,
PUSHKEY )
# yikes
119
+ try :
120
+ print ('Pushing to origin/beta. If this fails, there shouldn\' t be any useful output, since it would contain my access token' )
121
+ with open (os .devnull , 'w' ) as FNULL :
122
+ result = subprocess .call (['git' , 'push' , '--no-verify' , push_uri , 'beta' ], stdout = FNULL , stderr = FNULL )
123
+ if result != 0 :
124
+ print ('Secure push failed' )
125
+ else :
126
+ print ('Secure push worked' )
127
+ except :
128
+ print ('Secure push failed' )
129
+
130
+ else :
131
+ print ('Potential merge conflicts found! Cannot merge beta into develop' )
89
132
90
- PUSHKEY = os .environ ['PUSHKEY' ]
91
- push_uri = 'https://%s:%[email protected] /pyGSTio/pyGSTi.git' % (
USER ,
PUSHKEY )
# yikes
92
- try :
93
- print ('Pushing to origin/beta. If this fails, there shouldn\' t be any useful output, since it would contain my access token' )
94
- with open (os .devnull , 'w' ) as FNULL :
95
- result = subprocess .call (['git' , 'push' , '--no-verify' , push_uri , 'beta' ], stdout = FNULL , stderr = FNULL )
96
- if result != 0 :
97
- print ('Secure push failed' )
98
- else :
99
- print ('Secure push worked' )
100
- except :
101
- print ('Secure push failed' )
133
+ #if TRAVIS_BRANCH == "develop" and TRAVIS_PULL_REQUEST == "false":
134
+ # print("Attempting to deploy on pypitest")
135
+ # f = open(os.path.join(HOME,".pypirc"),"w")
136
+ # f.write(pypirc_contents)
137
+ # f.close()
138
+ # print("Running setup.py...")
139
+ # os.system("python setup.py sdist upload -r pypitest")
102
140
103
- else :
104
- print ('Potential merge conflicts found! Cannot merge beta into develop' )
141
+ if TRAVIS_BRANCH == "master" and TRAVIS_PULL_REQUEST == "false" :
142
+ print ("Attempting to deploy on pypi" )
143
+ f = open (os .path .join (HOME ,".pypirc" ),"w" )
144
+ f .write (pypirc_contents )
145
+ f .close ()
146
+ print ("Running setup.py..." )
147
+ os .system ("python setup.py sdist upload -r pypi" )
0 commit comments