|
1 | | -# create numerical tag number for the latest git check in and record that in |
2 | | -# the git_version.py file. This also advances the minor version number |
3 | | -# for the GSAS-II version number (from 5.X.Y to 5.X+1.0) |
| 1 | +# create a new numerical tag number for the most recent git checkin |
| 2 | +# and advance the minor GSAS-II version number (from 5.X.Y to 5.X+1.0) |
| 3 | +# Record the hash and version numbers in the git_version.py file. |
4 | 4 |
|
5 | | -# perhaps someday this should be made automatic in some fashion (perhaps |
6 | | -# not used on every check-in but don't go too many days/mods without a new |
7 | | -# version # |
8 | | - |
9 | | -# perhaps someday include as a clean (run on git add) or smudge |
10 | | -# step (run on git pull). |
11 | | -# Alternately, on commit/pull might get a count of how many untagged |
12 | | -# check-ins there have been. |
13 | | -# |
14 | | -# [filter "createVersionFile"] |
15 | | -# clean = python git_filters.py --tag-version |
16 | | -# smudge = python git_filters.py --record-version |
17 | | -# for debug of auto-run scripts, include a redirect in the script to |
18 | | -# send output to a log file: |
19 | | -# sys.stderr = sys.stdout = open('/tmp/gitfilter.log','a') |
20 | | -# |
21 | 5 | import os |
22 | 6 | import sys |
23 | 7 | import datetime as dt |
|
32 | 16 |
|
33 | 17 | if __name__ == '__main__': |
34 | 18 |
|
35 | | - g2repo = git.Repo(path2repo) |
36 | | -# if g2repo.active_branch.name != 'master': |
37 | | -# print('Not on master branch') |
38 | | -# sys.exit() |
| 19 | + try: |
| 20 | + g2repo = git.Repo(path2repo) |
| 21 | + except: |
| 22 | + print('Launch of gitpython for version file failed'+ |
| 23 | + f' with path {path2repo}') |
| 24 | + sys.exit() |
| 25 | + if g2repo.active_branch.name != 'main': |
| 26 | + print('Not on main branch') |
| 27 | + sys.exit() |
39 | 28 | if g2repo.head.is_detached: |
40 | 29 | print(f'Detached head {commit0[:7]!r}') |
41 | 30 | sys.exit() |
42 | 31 | # make a list of tags without a dash; get the largest numeric tag |
43 | 32 | # someday use the packaging module (but no more dependencies for now) |
44 | 33 | numtag = [i for i in g2repo.tags if '-' not in i.name] |
45 | 34 | max_numeric = max([int(i.name) for i in numtag if i.name.isdecimal()]) |
| 35 | + commit = g2repo.head.commit |
| 36 | + now = dt.datetime.now().replace( |
| 37 | + tzinfo=commit.committed_datetime.tzinfo) |
| 38 | + commit0 = commit.hexsha |
| 39 | + # is the newest commit tagged? |
| 40 | + tags0 = g2repo.git.tag('--points-at',commit) |
| 41 | + if tags0: tags0 = tags0.split('\n') |
| 42 | + if tags0: |
| 43 | + print(f'Latest commit ({commit.hexsha[:7]}) is already tagged ({tags0}).') |
| 44 | + sys.exit() |
| 45 | + |
46 | 46 | # get the latest version number |
47 | 47 | releases = [i for i in g2repo.tags if '.' in i.name and i.name.startswith('v')] |
48 | 48 | majors = [i.name.split('.')[0][1:] for i in releases] |
|
60 | 60 | if versiontag in releases: |
61 | 61 | print(f'Versioning problem, generated next version {versiontag} already defined!') |
62 | 62 | versiontag = '?' |
63 | | - |
64 | | - # is the newest commit tagged? |
65 | | - c = g2repo.head.commit |
66 | | - tags = g2repo.git.tag('--points-at',c).split('\n') |
67 | | - if tags != ['']: |
68 | | - print(f'Latest commit ({c.hexsha[:7]}) is already tagged ({tags}).') |
69 | 63 | sys.exit() |
70 | | - # add a tag to the newest commit |
| 64 | + if versiontag != '?': |
| 65 | + g2repo.create_tag(str(versiontag),ref=commit) |
| 66 | + print(f'created version # {versiontag} for {commit.hexsha[:7]}') |
| 67 | + |
| 68 | + # add a numeric tag to the newest commit as well |
71 | 69 | tagnum = max_numeric + 1 |
72 | 70 | while str(tagnum) in g2repo.tags: |
73 | 71 | print(f'Error: {tagnum} would be repeated') |
74 | 72 | tagnum += 1 |
75 | | - g2repo.create_tag(str(tagnum),ref=c) |
76 | | - print(f'created tag {tagnum} for {c.hexsha[:7]}') |
77 | | - if versiontag != '?': |
78 | | - g2repo.create_tag(str(versiontag),ref=c) |
79 | | - print(f'created version # {versiontag} for {c.hexsha[:7]}') |
| 73 | + g2repo.create_tag(str(tagnum),ref=commit) |
| 74 | + print(f'created tag {tagnum} for {commit.hexsha[:7]}') |
80 | 75 |
|
81 | | - # create a file with GSAS-II version information |
82 | | - try: |
83 | | - g2repo = git.Repo(path2repo) |
84 | | - except: |
85 | | - print('Launch of gitpython for version file failed'+ |
86 | | - f' with path {path2repo}') |
87 | | - sys.exit() |
88 | | - commit = g2repo.head.commit |
89 | | - #ctim = commit.committed_datetime.strftime('%d-%b-%Y %H:%M') |
90 | | - now = dt.datetime.now().replace( |
91 | | - tzinfo=commit.committed_datetime.tzinfo) |
92 | | - commit0 = commit.hexsha |
93 | 76 | tags0 = [i for i in g2repo.git.tag('--points-at',commit).split('\n') if i.isdecimal()] |
94 | 77 | history = list(g2repo.iter_commits('HEAD')) |
95 | 78 | for i in history[1:]: |
|
99 | 82 | tagsm1 = [i for i in tags.split('\n') if i.isdecimal()] |
100 | 83 | if not tagsm1: continue |
101 | 84 | break |
| 85 | + # create a file with GSAS-II version information |
102 | 86 | pyfile = os.path.join(path2GSAS2,'git_verinfo.py') |
103 | 87 | try: |
104 | 88 | fp = open(pyfile,'w') |
|
120 | 104 | fp.close() |
121 | 105 | print(f'Created git version file {pyfile} at {now} for {commit0[:7]!r}') |
122 | 106 |
|
123 | | - print('Now do:\n\t git add \n\t git commit \n\t git push \n\t git push --tags\n (try "git push origin HEAD --tags")') |
| 107 | + g2repo.index.add([pyfile]) |
| 108 | + g2repo.index.commit('increment minor version') |
| 109 | + g2repo.remote(name='origin').push() |
| 110 | + g2repo.remote(name='origin').push('--tags') |
124 | 111 |
|
125 | | -# Git 2.4 has added the push.followTags option to turn that flag on by default which you can set with: |
126 | | -# |
127 | | -# git config --global push.followTags true |
128 | | -# or by adding followTags = true to the [push] section of your ~/.gitconfig file. |
| 112 | +# print('Now do:\n\t git add \n\t git commit \n\t git push \n\t git push --tags\n (try "git push origin HEAD --tags")') |
0 commit comments