-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish the GitHub Actions publish workflow (#714)
Now, GitHub Actions should be able to publish to JFrog. Also, fix the CI test Gradle configuration stuff (e.g. fail fast).
- Loading branch information
Showing
6 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Ensure that this is being run in CI by GitHub Actions | ||
if [ "$CI" != "true" ] || [ "$GITHUB_ACTIONS" != "true" ]; then | ||
echo "This script should only be run in CI by GitHub Actions." | ||
exit 2 | ||
fi | ||
|
||
# Ensure that the tag is named properly as a semver tag | ||
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$ ]]; then | ||
echo "Tag $GITHUB_REF is NOT a valid semver tag (vX.Y.Z), please delete this tag." | ||
exit 1 | ||
fi | ||
|
||
# Ensure that the script is being run from the root project directory | ||
PROPERTIES_FILE='gradle.properties' | ||
if [ ! -f "$PROPERTIES_FILE" ]; then | ||
echo "Could not find $PROPERTIES_FILE, are you sure this is being run from the root project directory?" | ||
echo "PWD: ${PWD}" | ||
exit 1 | ||
fi | ||
|
||
# Determine the version being published | ||
VERSION=$(awk 'BEGIN { FS = "=" }; $1 == "version" { print $2 }' $PROPERTIES_FILE | awk '{ print $1 }') | ||
if [ -z "$VERSION" ]; then | ||
echo "Could not read the version from $PROPERTIES_FILE, please fix it and try again." | ||
exit 1 | ||
fi | ||
|
||
# Determine if the version is a release candidate version | ||
RELEASE_CANDIDATE=false | ||
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$ ]]; then | ||
RELEASE_CANDIDATE=true | ||
fi | ||
|
||
# Ensure the tag corresponds to the current version | ||
EXPECTED_TAG="v$VERSION" | ||
if [ "$GITHUB_REF" != "refs/tags/$EXPECTED_TAG" ]; then | ||
echo "Attempting to publish Rest.li version $VERSION from tag $GITHUB_REF is illegal." | ||
echo "Please delete this tag and publish instead from tag $EXPECTED_TAG" | ||
exit 1 | ||
fi | ||
|
||
# Ensure that the tag commit is an ancestor of master | ||
git fetch origin master:master | ||
git merge-base --is-ancestor $GITHUB_REF master | ||
if [ $? -ne 0 ]; then | ||
echo "Tag $GITHUB_REF is NOT an ancestor of master!" | ||
# Abort the deployment if it's not a release candidate tag | ||
if $RELEASE_CANDIDATE; then | ||
echo "Since this is a release candidate tag, the deployment will continue." | ||
else | ||
echo 'Please delete this tag and instead create a tag off a master commit.' | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# TODO: Is this needed on GitHub Actions? Travis aborts after 10 minutes of no output, not sure about GA | ||
# Output something every 9 minutes, otherwise Travis will abort after 10 minutes of no output | ||
# while sleep 9m; do echo "[Ping] Keeping Travis job alive ($((SECONDS / 60)) minutes)"; done & | ||
# WAITER_PID=$! | ||
|
||
# Publish to JFrog Artifactory | ||
echo "All checks passed, attempting to publish Rest.li $VERSION to JFrog Artifactory..." | ||
./gradlew artifactoryPublish | ||
EXIT_CODE=$? | ||
|
||
# TODO: Figure out if this can be removed as well for GitHub Actions | ||
# Kill the waiter job | ||
# kill $WAITER_PID | ||
|
||
if [ $EXIT_CODE = 0 ]; then | ||
echo "Successfully published Rest.li $VERSION to JFrog Artifactory." | ||
else | ||
# We used to roll back Bintray uploads on failure to publish, but it's not clear if this is needed for JFrog. | ||
# TODO: If "partial uploads" can occur for JFrog, then here we would roll back the upload via the JFrog REST API. | ||
# We did this before using: curl -X DELETE --user ${BINTRAY_USER}:${BINTRAY_KEY} --fail $DELETE_VERSION_URL | ||
|
||
echo 'Failed to publish to JFrog Artifactory.' | ||
echo "You can check https://linkedin.jfrog.io/ui/repos/tree/General/pegasus to ensure that $VERSION is not present." | ||
echo 'Please retry the upload by restarting this GitHub Actions job.' | ||
|
||
exit 1 | ||
fi |
This file contains 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
This file contains 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
This file contains 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
This file contains 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