checkout_complement.sh 955 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. #
  3. # Fetches a version of complement which best matches the current build.
  4. #
  5. # The tarball is unpacked into `./complement`.
  6. set -e
  7. mkdir -p complement
  8. # Pick an appropriate version of complement. Depending on whether this is a PR or release,
  9. # etc. we need to use different fallbacks:
  10. #
  11. # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF
  12. # for pull requests, otherwise GITHUB_REF).
  13. # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y
  14. # (GITHUB_BASE_REF for pull requests).
  15. # 3. Use the default complement branch ("HEAD").
  16. for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "HEAD"; do
  17. # Skip empty branch names and merge commits.
  18. if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then
  19. continue
  20. fi
  21. (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break
  22. done