Skip to content

Commit

Permalink
Safe-guard publishing of artifacts on master to development versions
Browse files Browse the repository at this point in the history
Since an actual release changes the version property but still results
in a push to the `master` branch, we safe-guard publishing CI artifacts.
  • Loading branch information
punycode committed Apr 14, 2020
1 parent f04efe5 commit cf33a7b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Publish SNAPSHOT artifacts to Sonatype OSSRH
- name: Publish development artifacts to Sonatype OSSRH
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
# Run only if current version is actually a development version
run: |
./gradlew -Psonatype build publishToSonatype
if ./scripts/is_development; then
./gradlew -Psonatype build publishToSonatype
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
Expand Down
28 changes: 28 additions & 0 deletions scripts/_functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

# Helper variables
_REPO_ROOT=$(git rev-parse --show-toplevel)

# Get current version as specified in the project configuration
current_version() {
grep -e '^version=.*$' "${_REPO_ROOT}/gradle.properties" | cut -d '=' -f 2
}

## Different checks (versions and git)
# Check if the supplied version is a development version
is_development_version() {
_version=$1
echo "${_version}" | grep -q -e '-SNAPSHOT$'
}

# Check if the supplied version is a (pre-)release version
is_release_version() {
_version=$1
echo "${_version}" | grep -v -q -e '-SNAPSHOT$'
}

# Check if the supplied version is a REAL pre-release version
is_prerelease_version() {
_version=$1
echo "${_version}" | grep -E -q -e '\.(RC|M)[[:digit:]]+$'
}
19 changes: 19 additions & 0 deletions scripts/is_development
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -o errexit
set -o nounset
set -o pipefail

# Global variables
REPO_ROOT=$(git rev-parse --show-toplevel)

# shellcheck source=_functions.sh
. "${REPO_ROOT}/scripts/_functions.sh"

CURRENT_VERSION=$(current_version)
if is_development_version "$CURRENT_VERSION"; then
info "Current version '${CURRENT_VERSION}' is a development version."
else
info "Current version '${CURRENT_VERSION}' is a release version."
exit 1
fi

0 comments on commit cf33a7b

Please sign in to comment.