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
BINTRAYJFROG_ORG=$organization
# i.e. egeria
BINTRAYJFROG_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${BINTRAY_TOKEN"} == "" || "$RT${RT_TOKEN"} == "" ]; then
    exit 1
fi

function config_rt () {
	jfrog rt c --interactive=false --url ${RT_URL} --access-token ${RT_TOKEN} odpi${JFROG_ORG}
}

function list_rt_packages () {
	jfrog rt search ${RT_REPO}/*${VERSION}* | jq '.[] | .path' | cut -d/ -f5 | sort | uniq | tee packages_$VERSION${VERSION}
}

function list_mvn_packages () {
	curl -L ${MVN_QUERY} | jq '.response.docs[] | .a' | sort | uniq | tr -d '"' | tee mvn_packages_$VERSION${VERSION}
}

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

function sync_packages () {
    if [ ! -f packages_to_sync_$VERSION${VERSION} ]; then
        echo "packages_to_sync_$VERSION${VERSION} file missing"
        exit 1
    fi
    while read -r package_name; do
        sync_package $package_name $VERSION${VERSION} ;
    done < packages_to_sync_$VERSION${VERSION}
}

# Needs package name, version
function sync_package () {
    local package_name=$1
    local package_version=$2
    echo "Syncing $package${package_name}:$package${package_version}"
    curl \
    -u $BINTRAY${BINTRAY_USER}:$BINTRAY${BINTRAY_TOKEN} \
    -H "Content-Type: application/json" \
    -X POST \
    -d '{"close":"1"}' \
    -L "https://api.bintray.com/maven_central_sync/$BINTRAY${JFROG_ORG}/$BINTRAY${JFROG_PROJECT}/$package${package_name}/versions/$package${package_version}"
    echo
}

config_rt
list_rt_packages
list_mvn_packages
diff_packages_to_sync
sync_packages

...