cli-artifact.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env bash
  2. #
  3. # SPDX-License-Identifier: GPL-2.0
  4. #
  5. # Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
  6. #
  7. # This file is a part of the Armbian Build Framework
  8. # https://github.com/armbian/build/
  9. function cli_artifact_pre_run() {
  10. case "${ARMBIAN_COMMAND}" in
  11. download-artifact)
  12. display_alert "download-only mode:" "won't build '${WHAT}'" "info"
  13. DONT_BUILD_ARTIFACTS="${WHAT}"
  14. ;;
  15. esac
  16. initialize_artifact "${WHAT}"
  17. # Run the pre run adapter
  18. artifact_cli_adapter_pre_run
  19. }
  20. function cli_artifact_run() {
  21. : "${chosen_artifact:?chosen_artifact is not set}"
  22. : "${chosen_artifact_impl:?chosen_artifact_impl is not set}"
  23. if [[ "${CONFIG_DEFS_ONLY}" != "yes" ]]; then
  24. # Make sure ORAS tooling is installed before starting.
  25. run_tool_oras
  26. fi
  27. display_alert "artifact" "${chosen_artifact}" "debug"
  28. display_alert "artifact" "${chosen_artifact} :: ${chosen_artifact_impl}()" "debug"
  29. declare -g artifact_version_requires_aggregation="no" # marker
  30. artifact_cli_adapter_config_prep # only if in cli.
  31. # if asked by _config_prep to aggregate, and HOSTRELEASE is not set, obtain it.
  32. if [[ "${artifact_version_requires_aggregation}" == "yes" ]] && [[ -z "${HOSTRELEASE}" ]]; then
  33. obtain_hostrelease_only # Sets HOSTRELEASE
  34. fi
  35. # When run in GHA, assume we're checking/updating the remote cache only.
  36. # Local cache is ignored, and if found, it's not unpacked, either from local or remote.
  37. # If remote cache is found, does nothing.
  38. declare default_update_remote_only="no"
  39. if [[ "${CI}" == "true" ]] && [[ "${GITHUB_ACTIONS}" == "true" ]]; then
  40. display_alert "Running in GitHub Actions, assuming we're updating remote cache only" "GHA remote-only" "info"
  41. default_update_remote_only="yes"
  42. fi
  43. declare skip_unpack_if_found_in_caches="${skip_unpack_if_found_in_caches:-"${default_update_remote_only}"}"
  44. declare ignore_local_cache="${ignore_local_cache:-"${default_update_remote_only}"}"
  45. declare deploy_to_remote="${deploy_to_remote:-"${default_update_remote_only}"}"
  46. case "${ARMBIAN_COMMAND}" in
  47. download-artifact)
  48. display_alert "Running in download-artifact mode" "download-artifact" "ext"
  49. skip_unpack_if_found_in_caches="no"
  50. ignore_local_cache="no"
  51. deploy_to_remote="no"
  52. ;;
  53. *)
  54. # @TODO: rpardini: i'm braindead. I really can't make sense of my own code!
  55. # If OCI_TARGET_BASE is explicitly set, ignore local, skip if found in remote, and deploy to remote after build.
  56. if [[ -n "${OCI_TARGET_BASE}" ]]; then
  57. skip_unpack_if_found_in_caches="yes"
  58. ignore_local_cache="yes"
  59. deploy_to_remote="yes"
  60. # Pass ARTIFACT_USE_CACHE=yes to actually use the cache versions, but don't deploy to remote.
  61. # @TODO this is confusing. each op should be individually controlled...
  62. # what we want is:
  63. # 1: - check remote, if not found, check local, if not found, build, then deploy to remote
  64. # - if remote found, do nothing.
  65. # - if local found, deploy it to remote (for switching targets)
  66. # 2: - get from remote -> get local -> build, then DON'T deploy to remote
  67. if [[ "${ARTIFACT_USE_CACHE}" == "yes" ]]; then
  68. skip_unpack_if_found_in_caches="no"
  69. ignore_local_cache="no"
  70. deploy_to_remote="no"
  71. fi
  72. fi
  73. ;;
  74. esac
  75. # Force artifacts download we need to populate repository
  76. if [[ "${FORCE_ARTIFACTS_DOWNLOAD}" == "yes" ]]; then
  77. skip_unpack_if_found_in_caches="no"
  78. fi
  79. # display a summary of the 3 vars above: skip_unpack_if_found_in_caches, ignore_local_cache, deploy_to_remote
  80. display_alert "CLI Artifact summary" "skip_unpack_if_found_in_caches=${skip_unpack_if_found_in_caches}, ignore_local_cache=${ignore_local_cache}, deploy_to_remote=${deploy_to_remote}" "info"
  81. if [[ "${ARTIFACT_BUILD_INTERACTIVE}" == "yes" ]]; then # Set by `kernel-config`, `kernel-patch`, `uboot-config`, `uboot-patch`, etc.
  82. display_alert "Running artifact build in interactive mode" "log file will be incomplete" "info"
  83. do_with_default_build obtain_complete_artifact
  84. else
  85. do_with_default_build obtain_complete_artifact < /dev/null
  86. fi
  87. }