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

# 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
BINTRAY_ORG=$organization
# i.e. egeria
BINTRAY_PROJECT=$project
# i.e. 1.3
VERSION=$release_version

if [ "$BINTRAY_TOKEN" == "" ]; then
    exit 1
fi

function list_packages () {
    local URL# i.e. org.odpi.egeria
MVN_PROJECT=$mvn-id
MVN_QUERY="https://apisearch.bintraymaven.comorg/repos/$BINTRAY_ORG/$BINTRAY_PROJECT/packages"
    { curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L $URL | jq '.[] | .name' | tr -d '"';
	# paginated to grab between 300-350 packages
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=50" | jq '.[] | .name' | tr -d '"'; 
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=100"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-token ${RT_TOKEN} odpi
}

function list_rt_packages () {
	jfrog rt search ${RT_REPO}/*${VERSION}* | jq '.[] | .namepath' | trcut -d '"';
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=150"/ -f5 | jqsort '.[] | .name'uniq | tr -d '"';
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=200"tee packages_$VERSION
}

function list_mvn_packages () {
	curl -L ${MVN_QUERY} | jq '.response.docs[] | .namea' | tr -d '"';
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=250" | jq '.[] | .name' sort | uniq | tr -d '"';
 | tee  curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=300" | jq '.[] | .name' | tr -d '"'
    curl -u $BINTRAY_USER:$BINTRAY_TOKEN -L "$URL/?start_pos=350" | jq '.[] | .name' | tr -d '"'
    } >> tmp_packages.txt
    sort tmp_packages.txt | uniq > packages_$VERSION.txt
mvn_packages_$VERSION
}

function diff_packages_to_sync () {
	diff -u0 packages_$VERSION mvn_packages_$VERSION | grep '^-' | grep -v '\-\-\-' | cut -c2- | tee packages_to_sync_$VERSION
}

function sync_packages () {
    if [ ! -f packages.txt_to_sync_$VERSION ]; then
        echo "packages.txt_to_sync_$VERSION file missing"
        exit 1
    fi
    while read -r package_name; do
        sync_package $package_name $VERSION ;
    done < packages.txt_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/$BINTRAY_ORG/$BINTRAY_PROJECT/$package_name/versions/$package_version"
    echo
}

#list_packages
config_rt
list_rt_packages
list_mvn_packages
diff_packages_to_sync
sync_packages
#sync_package $1 $VERSION


Step-by-step guide

The script above needs some environment variables set and then can be run in a screen session (expect 1-2 minutes per package), to sync from Bintray to JCenter and Maven Central.

...