patchtest-get-series 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash -e
  2. #
  3. # get-latest-series: Download latest patch series from Patchwork
  4. #
  5. # Copyright (C) 2023 BayLibre Inc.
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. # the interval into the past which we want to check for new series, in minutes
  10. INTERVAL_MINUTES=30
  11. # Maximum number of series to retrieve. the Patchwork API can support up to 250
  12. # at once
  13. SERIES_LIMIT=250
  14. # Location to save patches
  15. DOWNLOAD_PATH="."
  16. # Name of the file to use/check as a log of previously-tested series IDs
  17. SERIES_TEST_LOG=".series_test.log"
  18. # Patchwork project to pull series patches from
  19. PROJECT="oe-core"
  20. # The Patchwork server to pull from
  21. SERVER="https://patchwork.yoctoproject.org/api/1.2/"
  22. help()
  23. {
  24. echo "Usage: get-latest-series [ -i | --interval MINUTES ]
  25. [ -d | --directory DIRECTORY ]
  26. [ -l | --limit COUNT ]
  27. [ -h | --help ]
  28. [ -t | --tested-series LOGFILE]
  29. [ -p | --project PROJECT ]
  30. [ -s | --server SERVER ]"
  31. exit 2
  32. }
  33. while [ "$1" != "" ]; do
  34. case $1 in
  35. -i|--interval)
  36. INTERVAL_MINUTES=$2
  37. shift 2
  38. ;;
  39. -l|--limit)
  40. SERIES_LIMIT=$2
  41. shift 2
  42. ;;
  43. -d|--directory)
  44. DOWNLOAD_PATH=$2
  45. shift 2
  46. ;;
  47. -p|--project)
  48. PROJECT=$2
  49. shift 2
  50. ;;
  51. -s|--server)
  52. SERVER=$2
  53. shift 2
  54. ;;
  55. -t|--tested-series)
  56. SERIES_TEST_LOG=$2
  57. shift 2
  58. ;;
  59. -h|--help)
  60. help
  61. ;;
  62. *)
  63. echo "Unknown option $1"
  64. help
  65. ;;
  66. esac
  67. done
  68. # The time this script is running at
  69. START_TIME=$(date --date "now" +"%Y-%m-%dT%H:%M:%S")
  70. # the corresponding timestamp we want to check against for new patch series
  71. SERIES_CHECK_LIMIT=$(date --date "now - ${INTERVAL_MINUTES} minutes" +"%Y-%m-%dT%H:%M:%S")
  72. echo "Start time is $START_TIME"
  73. echo "Series check limit is $SERIES_CHECK_LIMIT"
  74. # Create DOWNLOAD_PATH if it doesn't exist
  75. if [ ! -d "$DOWNLOAD_PATH" ]; then
  76. mkdir "${DOWNLOAD_PATH}"
  77. fi
  78. # Create SERIES_TEST_LOG if it doesn't exist
  79. if [ ! -f "$SERIES_TEST_LOG" ]; then
  80. touch "${SERIES_TEST_LOG}"
  81. fi
  82. # Retrieve a list of series IDs from the 'git-pw series list' output. The API
  83. # supports a maximum of 250 results, so make sure we allow that when required
  84. SERIES_LIST=$(git-pw --project "${PROJECT}" --server "${SERVER}" series list --since "${SERIES_CHECK_LIMIT}" --limit "${SERIES_LIMIT}" | awk '{print $2}' | xargs | sed -e 's/[^0-9 ]//g')
  85. if [ -z "$SERIES_LIST" ]; then
  86. echo "No new series for project ${PROJECT} since ${SERIES_CHECK_LIMIT}"
  87. exit 0
  88. fi
  89. # Check each series ID
  90. for SERIES in $SERIES_LIST; do
  91. # Download the series only if it's not found in the SERIES_TEST_LOG
  92. if ! grep -w --quiet "${SERIES}" "${SERIES_TEST_LOG}"; then
  93. echo "Downloading $SERIES..."
  94. git-pw series download --separate "${SERIES}" "${DOWNLOAD_PATH}"
  95. echo "${SERIES}" >> "${SERIES_TEST_LOG}"
  96. else
  97. echo "Already tested ${SERIES}. Skipping..."
  98. fi
  99. done