Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
titlebintray to jcenter/ maven central sync script
#!/bin/bash
set -o errexit
set -o pipefail

# Requirements:
#  - curl
#  - jq
#  - jfrog : configured with credentials https://www.jfrog.com/confluence/display/CLI/JFrog+CLI

# i.e. odpi-lf
BINTRAY_USER=$username
BINTRAY_TOKEN="ABCDEFG12345"
# i.e. odpi
JFROG_ORG=$organization
# i.e. egeria
JFROG_PROJECT=$project
# i.e. 1.3
VERSION=$release_version
# i.e. org.odpi.egeria
MVN_PROJECT=$mvn-id
MVN_QUERY="https://search.maven.org/solrsearch/select?q=g:%22${MVN_PROJECT}%22%20AND%20v:${VERSION}&wt=json&rows=1000000"
# Artifactory release repository
# i.e. https://odpi.jfrog.io/odpi
RT_URL=$url
RT_TOKEN=$bearer-token
RT_REPO=${project}-release

if [[ "${BINTRAY_TOKEN}" == "" || "${RT_TOKEN}" == "" ]]; then
    exit 1
fi
 
function config_rt () {
	    jfrog rt c --interactive=false --url ${RT_URL} --access-tokenapikey ${RT_TOKEN} ${JFROG_ORG}
}
 
function list_rt_packages () {
	    jfrog rt search ${RT_REPO}/*${VERSION}* | jq '.[] | .path' | cut -d/ -f5 | sort | uniq | tee packages_${VERSION}
}
 
function list_mvn_packages () {
	    curl -LsSL ${MVN_QUERY} | jq '.response.docs[] | .a' | sort | uniq | tr -d '"' | tee mvn_packages_${VERSION}
}
 
function diff_packages_to_sync () {
	    set +o errexit
    diff -u0 packages_${VERSION} mvn_packages_${VERSION} | grep '^-' | grep -v '\-\-\-' | cut -c2- | tee packages_to_sync_${VERSION}
    set -o errexit
}
 
function sync_packages () {
    if [ ! -f packages_to_sync_${VERSION} ]; then
        echo "packages_to_sync_${VERSION} file missing"
        exit 1
    fi
    while read -r package_name; do
        sync_package $package_name ${VERSION} ;
    done < packages_to_sync_${VERSION}
}
 
# Needs package name, version
function sync_package () {
    local package_name=$1
    local package_version=$2
    echo "Syncing ${package_name}:${package_version}"
    curl \
    -u ${BINTRAY_USER}:${BINTRAY_TOKEN} \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"close":"1"}' \
    -L "https://api.bintray.com/maven_central_sync/${JFROG_ORG}/${JFROG_PROJECT}/${package_name}/versions/${package_version}"
    echo
}
 
# Configure JFrog CLI
config_rt

echo "> Packages in Artifactory"
list_rt_packages

echo "> Packages in Maven-Central"
list_mvn_packages

echo "> Packaging Not Synced"
diff_packages_to_sync

echo "> Syncing Packages..."
sync_packages


Step-by-step guide

...