Skip to content

Commit 2c0f4f0

Browse files
committed
🔧 Simplify dev tags in files
* 💬 Exclude hash (just "{semver}.dev" instead of "{semver}.{hash}-dev") * ⏪ Revert "🚀 Drop older version bump commits before adding new one" * 🚀 Include previous commit message when bumping version tags * 🔧 Add helper scripts for merging with divergent tags This reverts commit 4f635d5.
1 parent 2d282fd commit 2c0f4f0

File tree

5 files changed

+137
-28
lines changed

5 files changed

+137
-28
lines changed

.circleci/config.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,20 @@ jobs:
139139
name: "Checking if version needs updated"
140140
# update version if version needs updated, otherwise just move on
141141
command: |
142-
if [[ ! $(git log -1 --pretty=%B) == *"Update version to"* ]]
142+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
143+
if [[ ! "$COMMIT_MESSAGE" == *"Update version to"* ]]
143144
then
144145
cd $HOME/project/CPAC
145-
VERSION=$(python -c "from info import __version__; print(__version__)")
146+
VERSION=$(python -c "from info import __version__; print('.'.join(('.'.join(__version__[::-1].split('-')[1].split('.')[1:])[::-1], __version__.split('-')[1])) if '-' in __version__ else __version__)")
146147
cd ..
147-
if ! [[ $CIRCLE_BRANCH = 'master' ]]
148-
then
149-
git fetch --all
150-
if [[ -n ${CIRCLE_PR_NUMBER} && -n ${GITHUB_PR_BASE_TOKEN} ]]
151-
then
152-
curl -L "https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64" -o jq
153-
chmod +x jq
154-
REBASE_BASE=origin/$(curl -u shnizzedy:$GITHUB_PR_BASE_TOKEN "https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$CIRCLE_PR_NUMBER" | jq '.base.ref' | tr -d '"')
155-
else
156-
REBASE_BASE=$(git rev-parse --short HEAD~30)
157-
fi
158-
GIT_SEQUENCE_EDITOR=dev/circleci_data/drop_version_bump_commits git rebase -X ours -i $REBASE_BASE --empty drop
159-
fi
160148
echo "v${VERSION}" > version
161149
sed -i -r "s/^(# [Vv]ersion ).*$/# Version ${VERSION}/g" dev/docker_data/default_pipeline.yml
162150
find ./CPAC/resources/configs -name "*.yml" -exec sed -i -r "s/^(# [Vv]ersion ).*$/# Version ${VERSION}/g" {} \;
163151
git add version CPAC/resources/configs dev/docker_data/default_pipeline.yml
164152
if [[ ! -z $(git diff origin/${CIRCLE_BRANCH}) ]]
165153
then
166-
git commit -m ":bookmark: Update version to ${VERSION}"
167-
git push origin HEAD:${CIRCLE_BRANCH} -f || true
154+
git commit -m ":bookmark: Update version to ${VERSION} ($COMMIT_MESSAGE)"
155+
git push origin HEAD:${CIRCLE_BRANCH} || true
168156
circleci step halt
169157
fi
170158
cd ..
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
#!/usr/bin/env python3
2-
2+
"""
3+
Helper to drop auto-tag commits back to a given SHA or branch name ($BASE_BRANCH).
4+
"""
35
import os
46
import re
57

6-
todo_path = os.path.join(
7-
os.getcwd(), '.git', 'rebase-merge', 'git-rebase-todo'
8-
)
9-
with open(todo_path, 'r') as etd:
10-
todo = etd.read()
8+
from sys import argv, stdin
9+
10+
if __name__ == '__main__':
11+
if stdin.isatty and (
12+
len(argv) == 1 or (len(argv) > 1 and argv[1] in {'-h', '--help'})
13+
):
14+
print("""Usage:
15+
Use `drop_version_commits_back_to` to just give a branch or SHA ($BASE_BRANCH) to drop version-tagging commits back to.
16+
17+
Direct usage:
18+
GIT_SEQUENCE_EDITOR=drop_version_bump_commits git rebase -X ours -i $BASE_BRANCH --empty drop""")
19+
else:
20+
todo_path = os.path.join(
21+
os.getcwd(), '.git', 'rebase-merge', 'git-rebase-todo'
22+
)
23+
with open(todo_path, 'r') as etd:
24+
todo = etd.read()
1125

12-
with open(todo_path, 'w') as etd:
13-
etd.write(re.sub(
14-
r"^pick(?=.*\:bookmark\: Update version to.*)",
15-
'drop', todo, flags=re.MULTILINE
16-
))
26+
with open(todo_path, 'w') as etd:
27+
etd.write(re.sub(
28+
r"^pick(?=.*\:bookmark\: Update version to.*)",
29+
'drop', todo, flags=re.MULTILINE
30+
))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Helper script to prepare for merging. Takes the branch name or SHA of the merge base ($BASE_BRANCH)..
3+
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]
4+
then
5+
echo "Usage: drop_version_commits_back_to \$BASE_BRANCH"
6+
else
7+
GIT_SEQUENCE_EDITOR="${BASH_SOURCE%/*}/drop_version_bump_commits" git rebase -X ours -i $1 --empty drop
8+
fi
9+
exit 0
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Helper for handling of auto-tagged version info. Leaves version-tagged files with other changes.
4+
"""
5+
import re
6+
7+
from sys import argv, stdin
8+
9+
10+
def file_diffs(x):
11+
"""
12+
Takes a git diff --stat (plain text) and returns a list of 2-tuples
13+
of (filename, diff_stat)
14+
15+
Parameters
16+
----------
17+
x: str
18+
git diff --stat output
19+
20+
Returns
21+
-------
22+
file_diff_stats: list
23+
of 2-tuples of (filename, diff_stat)
24+
"""
25+
return [
26+
tuple([
27+
z.strip() for z in y.split('|')
28+
]) for y in x.strip().split('\n')[:-1]
29+
]
30+
31+
32+
def overwrite_list(file_diff_stats):
33+
"""
34+
Parameters
35+
----------
36+
file_diff_stats: list
37+
of 2-tuples of (filename, diff_stat)
38+
39+
Returns
40+
-------
41+
set
42+
of strings
43+
"""
44+
config_pattern = 'CPAC/resources/configs/.*\.yml$'
45+
s = set()
46+
return {
47+
fd[0] for fd in file_diff_stats if ((
48+
re.match(config_pattern, fd[0]) or
49+
fd[0] in {
50+
'dev/docker_data/default_pipeline.yml',
51+
'version'
52+
}
53+
) and fd[1] == '2 +-')
54+
}
55+
56+
57+
def print_checkout_file_list(git_diff_stat):
58+
"""
59+
Parameters
60+
----------
61+
git_diff_stat: str
62+
git diff --stat output
63+
64+
Returns
65+
-------
66+
str
67+
space-delimited list of filepaths to checkout from base branch
68+
"""
69+
print(' '.join(overwrite_list(file_diffs(git_diff_stat))))
70+
71+
72+
if __name__ == '__main__':
73+
if (
74+
len(argv) > 1 and argv[1] in {'-h', '--help'}
75+
) or stdin.isatty():
76+
print("""Usage:
77+
Use `prep_merge` to just give a branch or SHA to prep merging onto.
78+
79+
Direct usage:
80+
git diff enh/nested_config --stat=99999 | override_version_tag_list""")
81+
else:
82+
print_checkout_file_list(stdin.read())

dev/circleci_data/prep_merge

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
# Helper script to prepare for merging. Takes the branch name or SHA of the merge base ($BASE_BRANCH)..
3+
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]
4+
then
5+
echo "Usage: prep_merge \$BASE_BRANCH"
6+
else
7+
CIRCLECI_DATA=$(dirname $0)
8+
FILES_TO_REVERT=$(git diff $1 --stat=999999 | $CIRCLECI_DATA/override_version_tag_list)
9+
if [[ -n $FILES_TO_REVERT ]]
10+
then
11+
echo "git checkout $1 -- $FILES_TO_REVERT"
12+
git checkout $1 -- $FILES_TO_REVERT
13+
git commit -m ":twisted_rightwards_arrows: Prep for merging"
14+
fi
15+
fi
16+
exit 0

0 commit comments

Comments
 (0)