Skip to content

Commit

Permalink
Better tag management #64
Browse files Browse the repository at this point in the history
- Automatically create a tag for everything that affects the master
branch.
- When tagging, check that the tag name matches the Cargo version.
  • Loading branch information
frosklis committed Mar 15, 2021
1 parent a895636 commit 54c8a3d
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,31 @@ script:
after_success: |
if [[ "$TRAVIS_RUST_VERSION" == stable ]]; then
# upload to codecov.io coverage results
bash <(curl -s https://codecov.io/bash)
# Get the version from Cargo
export version=$(grep -E "version = \"([0-9]+\.[0-9]+.[0-9]+)\"" Cargo.toml | grep -Eo -m 1 "[0-9]+\.[0-9]+.[0-9]+")
# If this build is not from a tag, create one
if [[ "$TRAVIS_TAG" == "" ]]; then
echo "Do nothing"
# Build a tag
# This prints the version number
# export version=$(grep -E "version = \"([0-9]+\.[0-9]+.[0-9]+)\"" Cargo.toml | grep -Eo -m 1 "[0-9]+\.[0-9]+.[0-9]+")
# export line_number=$(grep -En "version = \"([0-9]+\.[0-9]+.[0-9]+)\"" Cargo.toml | grep -Eo -m 1 "[0-9]+" | head -n 1)
# sed -i "${line_number}s/.*/version = \"${version}-build-${TRAVIS_BUILD_NUMBER}\"/" Cargo.toml
# git tag -a -m "automated tag from Travis [ci skip]" ${version}-build-${TRAVIS_BUILD_NUMBER}
# git push -f --tags https://${GITHUB_TOKEN}@github.com/frosklis/dinero-rs.git
if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_EVENT_TYPE" != "cron" ]]; then
# If the build is from master we actually create a tag
# Build a tag
# This prints the version number
export line_number=$(grep -En "version = \"([0-9]+\.[0-9]+.[0-9]+)\"" Cargo.toml | grep -Eo -m 1 "[0-9]+" | head -n 1)
sed -i "${line_number}s/.*/version = \"${version}-build-${TRAVIS_BUILD_NUMBER}\"/" Cargo.toml
git tag -a -m "automated tag from Travis [ci skip]" ${version}-build-${TRAVIS_BUILD_NUMBER}
git push -f --tags https://${GITHUB_TOKEN}@github.com/frosklis/dinero-rs.git
fi
# If it is from a tag...
elif [[ "$TRAVIS_TAG" != *"build"* ]]; then
if [[ "$TRAVIS_TAG" != "$version" ]]; then
echo "Expected $TRAVIS_TAG from tag name."
echo "Found $version in Cargo.toml"
exit 1
fi
rm cobertura.xml
cargo publish --token ${CARGO_TOKEN}
fi
Expand Down

0 comments on commit 54c8a3d

Please sign in to comment.