1#!/bin/bash 2# 3# A script to generate the GATK tool WDLs for a specified GATK release, and publish them 4# to the GATK tool WDL github repository broadinstitute/gatk-tool-wdls. 5# 6# Must be run from the root of a GATK clone. 7# 8# Usage: bash scripts/publish_gatk_tool_wdls.sh <gatk_version_tag> 9# 10# Eg., bash scripts/publish_gatk_tool_wdls.sh 4.1.9.0 11# 12# The specified GATK version will also be used to tag the WDLs themselves in 13# broadinstitute/gatk-tool-wdls 14# 15 16if [ $# -ne 1 ]; then 17 echo "Usage: $0 <gatk_version_tag>" 18 exit 1 19fi 20 21GATK_VERSION="$1" 22GATK_CLONE_ROOT=$( pwd ) 23GATK_WDL_REPO="git@github.com:broadinstitute/gatk-tool-wdls.git" 24WDL_STAGING_AREA="wdl_staging_area" 25WDL_GEN_DIR="build/docs/wdlGen" 26DOCKSTORE_YML=".dockstore.yml" 27 28function cleanup() { 29 cd "${GATK_CLONE_ROOT}" 30 rm -rf "${WDL_STAGING_AREA}" 31} 32 33function fatal_error() { 34 echo "$1" 1>&2 35 cleanup 36 exit 1 37} 38 39function generate_dockstore_yml() { 40 local WDL_DIR="$1" 41 local YML_FILE="$2" 42 43 printf "version: 1.2\n" > "${YML_FILE}" 44 printf "workflows:\n" >> "${YML_FILE}" 45 46 for wdl in ${WDL_DIR}/*.wdl; do 47 local WDL_NAME=$( basename "${wdl}" .wdl ) 48 local WDL_JSON="${WDL_NAME}Inputs.json" 49 50 printf " - name: %s\n" "${WDL_NAME}" >> "${YML_FILE}" 51 printf " subclass: WDL\n" >> "${YML_FILE}" 52 printf " primaryDescriptorPath: %s\n" "/${WDL_DIR}/${WDL_NAME}.wdl" >> "${YML_FILE}" 53 printf " testParameterFiles:\n" >> "${YML_FILE}" 54 printf " - %s\n" "/${WDL_DIR}/${WDL_JSON}" >> "${YML_FILE}" 55 done 56} 57 58# Checkout the GATK version for which we are publishing WDLs 59echo "$0: Checking out GATK version ${GATK_VERSION}" 60git checkout -f "${GATK_VERSION}" 61if [ $? -ne 0 ]; then 62 fatal_error "Failed to checkout GATK version ${GATK_VERSION}" 63fi 64 65# Get a fresh clone of the GATK WDL repo, and delete all existing WDLs 66echo "$0: Cloning ${GATK_WDL_REPO} into ${WDL_STAGING_AREA}" 67cleanup 68git clone "${GATK_WDL_REPO}" "${WDL_STAGING_AREA}" 69if [ $? -ne 0 ]; then 70 fatal_error "Failed to clone GATK WDL repo ${GATK_WDL_REPO}" 71fi 72 73rm -rf "${WDL_STAGING_AREA}/wdls" 74mkdir "${WDL_STAGING_AREA}/wdls" 75 76# Generate the GATK WDLs, copy into our clone of the WDL repo, and delete the test WDLs 77echo "$0: Running GATK WDL generation" 78./gradlew clean gatkWDLGen 79if [ $? -ne 0 ]; then 80 fatal_error "Unable to generate the GATK tool WDLs" 81fi 82 83echo "$0: Copying WDLs to staging area" 84cp ${WDL_GEN_DIR}/* "${WDL_STAGING_AREA}/wdls" 85rm -f ${WDL_STAGING_AREA}/wdls/*Test.wdl 86rm -f ${WDL_STAGING_AREA}/wdls/*TestInputs.json 87rm -f ${WDL_STAGING_AREA}/wdls/*.html 88 89# Switch to the root of our WDL staging clone, and add the WDLs we just generated to git 90cd "${WDL_STAGING_AREA}" 91git add wdls/* 92 93# Regenerate the .dockstore.yml file 94echo "$0: Generating .dockstore.yml" 95rm -f "${DOCKSTORE_YML}" 96generate_dockstore_yml wdls "${DOCKSTORE_YML}" 97git add "${DOCKSTORE_YML}" 98 99# Commit, tag, and push the WDLs 100echo "$0: Pushing to github" 101git commit -a -m "Version ${GATK_VERSION} of the GATK tool WDLs" 102git tag -a -f -m "Version ${GATK_VERSION} of the GATK tool WDLs" "${GATK_VERSION}" 103git push -f --tags origin HEAD:master 104if [ $? -ne 0 ]; then 105 fatal_error "Unable to push WDLs to github repo ${GATK_WDL_REPO}" 106fi 107 108# Cleanup and exit 109echo "Done! Successfully published GATK tool wdls for version ${GATK_VERSION}" 110cd "${GATK_CLONE_ROOT}" 111cleanup 112git checkout -f master 113exit 0 114