From d5b3860bbf594a67025e8cb58f68241762358e5f Mon Sep 17 00:00:00 2001 From: keith-ratcliffe Date: Fri, 16 Aug 2024 19:06:23 +0000 Subject: [PATCH] Fix bug in publish-new-releases script / auto-seed first post entry --- _posts/release/2024-08-09-datawave-7.3.0.md | 10 --- scripts/publish-new-releases | 97 ++++++++++++--------- 2 files changed, 54 insertions(+), 53 deletions(-) delete mode 100644 _posts/release/2024-08-09-datawave-7.3.0.md diff --git a/_posts/release/2024-08-09-datawave-7.3.0.md b/_posts/release/2024-08-09-datawave-7.3.0.md deleted file mode 100644 index ce218b41a97..00000000000 --- a/_posts/release/2024-08-09-datawave-7.3.0.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: DataWave 7.3.0 -version: 7.3.0 -tags: [news, releases] -draft: false ---- -A new Accumulo 2.1.x-compatible DataWave release has been tagged - -[View the release on GitHub]({{ site.repository_url }}/releases/tag/{{ page.version }}) - diff --git a/scripts/publish-new-releases b/scripts/publish-new-releases index a637a5b0c9c..755937937b1 100755 --- a/scripts/publish-new-releases +++ b/scripts/publish-new-releases @@ -7,28 +7,20 @@ # # Intended to be non-interactive and suitable for crond or other automation # -# Usage: -# [--push, -p] [--verbose, -v] [--help, -h] -# -# -p option will locally commit the changes and then attempt to push them -# # DW_GITHUB_REMOTE_URL: Github repo to read from and optionally update. -# By default, DW_GITHUB_REMOTE_URL is defined as "https://github.com/NationalSecurityAgency/datawave.git" -# -# However, if --push is used, then it must be overridden as "https://user:token@github.com/NationalSecurityAgency/datawave.git" +# By default, DW_GITHUB_REMOTE_URL is defined as +# https://github.com/NationalSecurityAgency/datawave.git +# However, if --push is used, then it must be overridden as +# https://user:token@github.com/NationalSecurityAgency/datawave.git # where 'user:token' has write permissions on the repo DW_GITHUB_REMOTE_URL="${DW_GITHUB_REMOTE_URL:-https://github.com/NationalSecurityAgency/datawave.git}" # TRACKED_DW_VERSIONS: Major versions of DW that we want to track for publishing purposes. -# For example, any pre-5.x releases that are created at this point are unlikely to be of interest to anyone -# except the development team. Hence, we're not tracking the 3.x line here. -# -# To begin auto-publishing news updates for a new major release, just add the major version to the array and -# then seed the _posts/release/ dir with at least the first entry. For example, assuming hypothetically that -# DataWave 11.0.0 was tagged and released on February 1st 2024, you'd add '11' to the array here and then -# create the file _posts/release/2024-02-01-datawave-11.0.0.md before running the script. All subsequent -# posts for releases on the 11.x line will be created automatically +# For example, any pre-5.x releases that are created at this point are unlikely to be of +# interest to anyone except the development team. Hence, we're not tracking the 3.x line here. +# To start/stop auto-publishing news updates for a release line, just add/remove the major +# version to the array... declare -a -r TRACKED_DW_VERSIONS=( 5 6 7 ) # Fresh git clones are created in /tmp and then deleted each time @@ -41,6 +33,7 @@ declare -i _new_release_count=0 _debug=false _dry_run=true +_force_clean=false log() { echo "[$(date +%Y-%m-%d\ %H:%M:%S)] "${@}"" @@ -82,11 +75,12 @@ clone_repos() { usage() { cat < ${_post_file_name} - ((_new_release_count++)) - done + logi "Generating post for '${1}' @ ${_post_file_name}" + echo "${_post}" > ${_post_file_name} + ((_new_release_count++)) } update_git() { @@ -201,18 +201,28 @@ get_published_tags() { # # Get semver-sorted list of tagged releases for the current _major_version # that've already been published to gh-pages - # + # _ghpages_posts=() _ghpages_posts_count=$(ls -1 ${POSTS_DIR}/*datawave-${_major_version}\.* 2>/dev/null | wc -l) + + if [[ ${_ghpages_posts_count} -eq 0 && ${#_dw_tags[@]} -gt 0 ]] ; then + logi "Latest release is ${_dw_tags[-1]}, but we haven't published any ${_major_version}.x entries yet" + logi "Seeding gh-pages with the ${_dw_tags[0]} entry" + create_post ${_dw_tags[0]} + _ghpages_posts_count=1 + fi + if [[ ${_ghpages_posts_count} -gt 0 ]] ; then _ghpages_posts=( $(cd ${POSTS_DIR} && ls -1 *datawave-${_major_version}\.*\.md | cut -d'-' -f5 | sed 's/.\{3\}$//' | sort -t "." -k1,1n -k2,2n -k3,3n) ) # Get the _DW_TAGS index of the most recent tag published to ghpages _latest_post_index=$(search "${_ghpages_posts[-1]}" "${_dw_tags[@]}") fi + # Sanity check... if [[ ${_ghpages_posts_count} -gt 0 && ${_latest_post_index} -lt 0 ]] ; then logf "Git tag for the ${_ghpages_posts[-1]} gh-pages post wasn't found in Github" fi + logi "Latest ${_major_version}.x post in gh-pages: ${_ghpages_posts[-1]}" logi "Latest DW ${_major_version}.x release: ${_dw_tags[-1]}" logd "${_major_version}.x tag list: $(printf '%s\n' "${_dw_tags[@]}" | paste -sd ',' -)" @@ -228,23 +238,24 @@ for _major_version in "${TRACKED_DW_VERSIONS[@]}" ; do get_published_tags # If latest published tag != latest DW tag, then we need to publish an update if [[ "${_ghpages_posts[-1]}" != "${_dw_tags[-1]}" ]] ; then - _accumulo_version="2.1" - [[ ${_major_version} -lt 5 ]] && _accumulo_version="1.10" - generate_posts "${_accumulo_version}" "$((${_latest_post_index}+1))" "${_dw_tags[@]}" + generate_posts "$((${_latest_post_index}+1))" "${_dw_tags[@]}" else logi "There's nothing new to publish for DW ${_major_version}.x" fi done # Update local gh-pages git repo and do cleanup as needed - -if [[ ${_new_release_count} -eq 0 ]] ; then - cleanup "${TMP_GHPAGES_DIR}" "${TMP_DW_DIR}" -else +cleanup "${TMP_DW_DIR}" +if [[ ${_new_release_count} -gt 0 ]] ; then logi "New releases since the last gh-pages update: ${_new_release_count}" update_git - cleanup "${TMP_DW_DIR}" - logw "Leaving ${TMP_GHPAGES_DIR} intact, because there were changes made" + if [[ "${_force_clean}" == true ]] ; then + cleanup "${TMP_GHPAGES_DIR}" + else + logw "Leaving ${TMP_GHPAGES_DIR} intact, because there were changes made" + fi +else + cleanup "${TMP_GHPAGES_DIR}" fi exit 0