Created
July 30, 2020 13:14
-
-
Save shaypal5/064dd0254a9f32c7549f8d42c26fef90 to your computer and use it in GitHub Desktop.
Bitbucket status badges
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: python:3.8.3 | |
# pipeline stages definitions | |
test: &test | |
step: | |
name: test | |
caches: | |
- pip | |
script: | |
- python --version | |
- pip install -e ".[test]" | |
- PYTEST_STATUS=0 | |
- pytest || PYTEST_STATUS=1 | |
- echo export PYTEST_STATUS=$PYTEST_STATUS > shared_vars.sh | |
- sh ci/status_badge.sh $PYTEST_STATUS | |
artifacts: | |
- status.svg | |
- coverage.svg | |
- shared_vars.sh | |
upload-badge: &upload-status-badge | |
step: | |
name: Upload the build status badge | |
caches: | |
- docker | |
script: | |
- ls /opt/atlassian/pipelines/agent/build | |
- pipe: atlassian/bitbucket-upload-file:0.1.8 | |
variables: | |
BITBUCKET_USERNAME: $BITBUCKET_USERNAME | |
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD | |
FILENAME: 'status.svg' | |
upload-badge: &upload-coverage-badge | |
step: | |
name: Upload the test coverage badge | |
caches: | |
- docker | |
script: | |
- ls /opt/atlassian/pipelines/agent/build | |
- pipe: atlassian/bitbucket-upload-file:0.1.8 | |
variables: | |
BITBUCKET_USERNAME: $BITBUCKET_USERNAME | |
BITBUCKET_APP_PASSWORD: $BITBUCKET_APP_PASSWORD | |
FILENAME: 'coverage.svg' | |
test: &build-status | |
step: | |
name: build-status | |
script: | |
- source shared_vars.sh | |
- exit $PYTEST_STATUS | |
pipelines: | |
default: | |
- <<: *test | |
branches: | |
master: | |
- <<: *test | |
- <<: *upload-status-badge | |
- <<: *upload-coverage-badge | |
- <<: *build-status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# we'll call this if pytest succeeds | |
pytest_success() { | |
echo "pytest succeeded! Generating a build success status badge!" | |
python -m pybadges --left-text=build --right-text=passing --right-color=green > status.svg | |
} | |
# we'll call this if pytest fails | |
pytest_fail() { | |
echo "pytest failed! Generating a build failure status badge!" | |
python -m pybadges --left-text=build --right-text=failure --right-color=red > status.svg | |
} | |
# this is the main logic | |
PYTEST_STATUS=$1 | |
# generate our build status badge based on pytest results | |
[ $PYTEST_STATUS -eq 0 ] && pytest_success || pytest_fail | |
# generate the coverage badge | |
coverage-badge -o coverage.svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment