Skip to content

Commit

Permalink
Merge pull request Yelp#395 from Yelp/pre-v1-bump2version
Browse files Browse the repository at this point in the history
Integrating with bump2version
  • Loading branch information
domanchi authored Feb 25, 2021
2 parents 33fd15e + 14b709d commit 4e71e00
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 142 deletions.
8 changes: 6 additions & 2 deletions detect_secrets/core/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Callable
from typing import cast
from typing import Dict
from typing import List
from typing import Union

from . import upgrades
Expand Down Expand Up @@ -67,8 +68,11 @@ def format_for_output(secrets: SecretsCollection, is_slim_mode: bool = False) ->
else:
# NOTE: This has a nice little side effect of keeping it ordered by line number,
# even though we don't output it.
for filename, secrets in output['results'].items():
for secret_dict in secrets:
for filename, secret_list in cast(
Dict[str, List[Dict[str, Any]]],
output['results'],
).items():
for secret_dict in secret_list:
secret_dict.pop('line_number')

return output
Expand Down
22 changes: 17 additions & 5 deletions docs/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ assumption of the upgrade script will break.

### Changing the Version

The version file is specified in `detect_secrets.__version__`. Just modify this value to the
desired version, based on your change that is made.
`detect-secrets` integrates with `bump2version` to make this process easier. Here's a handy
pre-bump checklist to make sure you haven't forgotten anything:

This version bump should be a separate PR (often by a `detect-secrets` maintainer), and should
be accompanied by a corresponding CHANGELOG modification.
- [ ] Have you modified the CHANGELOG with the latest changes?
- [ ] Have you written an upgrade file to ensure backwards compatibility?

Then, you (as a `detect-secrets` maintainer) can run:

```bash
scripts/bump-version
```

### Pushing to PyPi

TODO
```bash
# First, test with test.pypi.com
scripts/upload-to-pypi

# If all looks good, we can head to prod!
scripts/upload-to-pypi --prod
```
106 changes: 106 additions & 0 deletions scripts/bump-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
# This is just a thin wrapper around bump2version, to support cases where there's no
# current version in git.
PACKAGE_NAME='detect_secrets'
DRY_RUN=0

function usage() {
echo "Usage: bump-version [major|minor|patch]"
}

function main() {
verifyArguments "$@"
if [[ $? == 1 ]]; then
return 1
fi

installDependency

getLatestTagName
if [[ $? == 0 ]]; then
bumpVersion "$@"
else
setVersion
fi

if [[ $? == 1 ]]; then
return 1
fi

# Since setVersion has already set the tags, at this point, the tag should already exist.
local tagName=`getLatestTagName`
if [[ $DRY_RUN == 0 ]]; then
git push origin HEAD
git push origin "$tagName"
else
echo "git push origin HEAD"
echo "git push origin '$tagName'"
fi
}

function verifyArguments() {
local part="$1"
if [[ -z "$part" ]]; then
# We only allow bump-version to be used with no arguments if there's
# no current version.
getLatestTagName
if [[ $? == 0 ]]; then
usage
return 1
fi

elif [[ "$part" != "major" ]] && [[ "$part" != "minor" ]] && [[ "$part" != "patch" ]]; then
usage
return 1
fi

# Check if virtualenv is built.
test -f venv/bin/pip
if [[ $? != 0 ]]; then
echo 'error: Run `make development` first.'
return 1
fi

return 0
}

function getLatestTagName() {
local output
output=$(git describe --tags --abbrev=0 2>/dev/null)
if [[ $? != 0 ]]; then
return 1
fi

echo "$output"
return 0
}

function installDependency() {
# NOTE: We don't specify this in requirements-dev-minimal, since not all developers need
# to bump the version.
venv/bin/pip install bump2version
}

function setVersion() {
local version=$(grep -Eo '\d+\.\d+\.\d+' $PACKAGE_NAME/__version__.py)

if [[ $DRY_RUN == 0 ]]; then
git commit -m "Initializing v$version"
git tag "v$version"
else
echo "setting version to $version"
fi
}

function bumpVersion() {
local part="$1"
if [[ $DRY_RUN == 0 ]]; then
venv/bin/bump2version "$part"
else
venv/bin/bump2version "$part" --dry-run --verbose
fi

return $?
}

main "$@"
132 changes: 0 additions & 132 deletions scripts/bumpity.py

This file was deleted.

Loading

0 comments on commit 4e71e00

Please sign in to comment.