github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/buildah-bud/run-buildah-bud-tests (about)

     1  #!/bin/bash
     2  
     3  ME=$(basename $0)
     4  
     5  ###############################################################################
     6  # BEGIN user-customizable section
     7  
     8  # Buildah main repository; unlikely to change often
     9  BUILDAH_REPO=github.com/containers/buildah
    10  
    11  # Tag name used to identify the base checkout
    12  BASE_TAG=buildah-bud-in-podman
    13  
    14  # END   user-customizable section
    15  ###############################################################################
    16  
    17  usage="Usage: $ME [--help] [--no-checkout] [--no-test] [--filter=TESTNAME]
    18  
    19  Flags, useful for manual debugging:
    20  
    21    --no-checkout   Skip checkout step, go directly to running tests
    22    --no-test       Do checkout only, but do not run tests
    23    --filter=NAME   Passed on to bats; runs only tests that match NAME
    24  "
    25  
    26  # Parse command-line options (used in development only, not in CI)
    27  do_checkout=y
    28  do_test=y
    29  declare -a bats_filter=()
    30  for i; do
    31      value=$(expr "$i" : '[^=]*=\(.*\)')
    32      case "$i" in
    33          --no-checkout)  do_checkout= ; shift;;
    34          --no-test)      do_test=     ; shift;;
    35          --filter=*)     bats_filter=("--filter" "$value"); shift;;
    36          -h|--help)      echo "$usage"; exit 0;;
    37          *)              echo "$ME: Unrecognized option '$i'" >&2; exit 1;;
    38      esac
    39  done
    40  
    41  # Patches helpers.bash and potentially other files (bud.bats? Dockerfiles?)
    42  #
    43  # The patch file is horrible to generate:
    44  #    1) cd to the checked-out buildah/tests directory
    45  #    2) make your edits
    46  #    3) git commit -asm 'blah blah blah'
    47  #       3a) if checked-out directory already includes earlier patches,
    48  #           you may need to 'git commit --amend' instead
    49  #    4) git format-patch HEAD^
    50  #    5) sed -e 's/ \+$//' 0001* >../PATCH-FILE-PATH
    51  #    6) vim that file, remove trailing empty newlines
    52  #    7) cd back out of buildah directory, and git-commit this new patch file
    53  #
    54  # FIXME: this makes me nervous. The diff will probably need tweaking
    55  #        over time. I don't think we need to version it, because we
    56  #        *have* to be in lockstep with a specific buildah version,
    57  #        so problems should only arise when we re-vendor.
    58  #        But I'm still nervous and can't put my finger on the reason.
    59  #
    60  # Complicated invocation needed because we 'cd' down below.
    61  BUD_TEST_DIR=$(realpath $(dirname ${BASH_SOURCE[0]}))
    62  PATCHES=${BUD_TEST_DIR}/buildah-tests.diff
    63  
    64  # Friendlier relative path to our buildah-tests dir
    65  BUD_TEST_DIR_REL=$(dirname $(git ls-files --full-name ${BASH_SOURCE[0]}))
    66  # Path to podman binary; again, do it before we cd
    67  PODMAN_BINARY=$(pwd)/bin/podman
    68  REMOTE=
    69  # If remote, start server & change path
    70  if [[ "${PODBIN_NAME:-}" = "remote" ]]; then
    71      REMOTE=1
    72      PODMAN_BINARY+="-remote"
    73  fi
    74  
    75  function die() {
    76      failhint=
    77      echo "$ME: $*" >&2
    78      exit 1
    79  }
    80  
    81  # From here on out, any unexpected abort will try to offer helpful hints
    82  failhint=
    83  trap 'if [[ $? != 0 ]]; then if [[ -n $failhint ]]; then echo;echo "***************************************";echo "$failhint";echo;echo "Please see $BUD_TEST_DIR_REL/README.md for advice";fi;fi' 0
    84  
    85  # Find the version of buildah we've vendored in, so we can run the right tests
    86  buildah_version=$(awk "\$1 == \"$BUILDAH_REPO\" { print \$2 }" <go.mod)
    87  
    88  if [[ -z "$buildah_version" ]]; then
    89      # This should not happen
    90      die "Did not find '$BUILDAH_REPO' in go.mod"
    91  fi
    92  
    93  # From here on out, any error is fatal
    94  set -e
    95  
    96  # Before pulling buildah (while still cd'ed to podman repo), try to determine
    97  # if this is a PR, and if so if it's a revendoring of buildah. We use this to
    98  # try to offer a helpful hint on failure.
    99  is_revendor=
   100  if [[ -n $CIRRUS_CHANGE_IN_REPO ]]; then
   101      if [[ -n $DEST_BRANCH ]]; then
   102          head=${CIRRUS_CHANGE_IN_REPO}
   103          # Base of this PR.
   104          base=$(set -x;git merge-base ${DEST_BRANCH} $head)
   105          changes=$(set -x;git diff --name-status $base $head)
   106          if [[ -n $changes ]]; then
   107              if [[ $changes =~ vendor/$BUILDAH_REPO ]]; then
   108                  is_revendor=y
   109              fi
   110          fi
   111      fi
   112  fi
   113  
   114  # Pull buildah, including tests
   115  buildah_dir=test-buildah-$buildah_version
   116  if [[ -n $do_checkout ]]; then
   117      if [[ -d $buildah_dir ]]; then
   118          die "Directory already exists: $buildah_dir"
   119      fi
   120  
   121      # buildah_version should usually be vX.Y, but sometimes a PR under test
   122      # will need a special unreleased version (go calls then "pseudoversions").
   123      # In the usual case, we can do a shallow git clone:
   124      shallow_checkout="--branch $buildah_version"
   125      if [[ $buildah_version =~ .*-.*\.[0-9]{14}-.* ]]; then
   126          # ...but with a pseudoversion, we must git-clone the entire repo,
   127          # then do a git checkout within it
   128          shallow_checkout=
   129      fi
   130  
   131      failhint="'git clone' failed - this should never happen!"
   132      (set -x;git clone -q $shallow_checkout https://$BUILDAH_REPO $buildah_dir)
   133  
   134      cd $buildah_dir
   135      if [[ -z $shallow_checkout ]]; then
   136          # extract the SHA (rightmost field) from, e.g., v1.2-YYYMMDD-<sha>
   137          sha=${buildah_version##*-}
   138  
   139          failhint="'git checkout $sha' failed - this should never happen!"
   140          (set -x;git checkout -q $sha)
   141      fi
   142  
   143      # Give it a recognizable tag; this will be useful if we need to update
   144      # the set of patches
   145      (set -x;git tag $BASE_TAG)
   146  
   147      # Build buildah and the copy helper
   148      failhint="error building buildah. This should never happen."
   149      (set -x;make bin/buildah)
   150      failhint="error building buildah's copy helper. This should never happen."
   151      (set -x;make bin/copy)
   152  
   153      # The upcoming patch may fail. Before we try it, create a helper script
   154      # for a developer to push a new set of diffs to podman-land.
   155      failhint=
   156      sed -e "s,\[BASETAG\],${BASE_TAG},g" \
   157          -e "s,\[BUILDAHREPO\],${BUILDAH_REPO},g" \
   158          < ${BUD_TEST_DIR}/make-new-buildah-diffs \
   159          > make-new-buildah-diffs
   160      chmod 755 make-new-buildah-diffs
   161  
   162      # Apply custom patches. We do this _after_ building, although it shouldn't
   163      # matter because these patches should only apply to test scripts and not
   164      # to any buildah sources.
   165      failhint="
   166  Error applying patch file. This can happen when you vendor in a new buildah.
   167  You will want to:
   168  
   169    - look for 'test/*.rej'
   170    - resolve conflicts manually
   171    - git add test/helpers.bash
   172    - git am --continue
   173    - ./make-new-buildah-diffs
   174  "
   175      (set -x;git am --reject <$PATCHES)
   176  
   177      # Now apply our custom skips and error-message changes. This is maintained
   178      # in a custom script, not a .diff file, because diffs are WAY too hard for
   179      # humans to read and update.
   180      APPLY=apply-podman-deltas
   181      failhint="
   182  Error applying podman-specific deltas. This sometimes happens when you
   183  vendor in a new buildah. You will want to:
   184  
   185    - inspect the errors shown above
   186    - find the corresponding lines in $BUD_TEST_DIR_REL/$APPLY
   187    - edit/delete them as necessary
   188  "
   189      (set -x;$BUD_TEST_DIR/$APPLY)
   190  else
   191      # Called with --no-checkout
   192      test -d $buildah_dir || die "Called with --no-checkout, but $buildah_dir does not exist"
   193  
   194      cd $buildah_dir
   195  fi
   196  
   197  if [[ -n $do_test ]]; then
   198      failhint="Error running buildah bud tests under podman."
   199      if [[ -n $is_revendor ]]; then
   200          failhint+="
   201  
   202  It looks like you're vendoring in a new buildah. The likely failure
   203  here is that there's a new test in bud.bats that uses functionality
   204  not (yet) in podman build. You will likely need to 'skip' that test.
   205  "
   206      else
   207          failhint+="
   208  
   209  Is it possible that your PR breaks podman build in some way? Please
   210  review the test failure and double-check your changes.
   211  "
   212      fi
   213  
   214      (set -x;sudo env TMPDIR=/var/tmp \
   215                   PODMAN_BINARY=$PODMAN_BINARY \
   216                   REMOTE=$REMOTE \
   217                   BUILDAH_BINARY=$(pwd)/bin/buildah \
   218                   COPY_BINARY=$(pwd)/bin/copy \
   219                   bats "${bats_filter[@]}" tests/bud.bats)
   220  fi