check_secrets.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. # Copyright 2020 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Check if secrets are available for multiple CI's
  16. set -x
  17. echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF:-}"
  18. echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF:-}"
  19. check_secrets()
  20. {
  21. # Travis: Secrets are available if we're not running on a fork.
  22. if [[ -n "${TRAVIS_PULL_REQUEST:-}" ]]; then
  23. if [[ "$TRAVIS_PULL_REQUEST" == "false" ||
  24. "$TRAVIS_PULL_REQUEST_SLUG" == "$TRAVIS_REPO_SLUG" ]]; then
  25. return 0
  26. fi
  27. fi
  28. # GitHub Actions: Secrets are available if we're not running on a fork.
  29. # See https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables
  30. # TODO- Both GITHUB_BASE_REF and GITHUB_HEAD_REF are set in main repo
  31. # PRs even thought the docs say otherwise. They are not set in cron jobs on main.
  32. # Investigate how do to distinguish fork PRs from main repo PRs.
  33. if [[ -n "${GITHUB_WORKFLOW:-}" ]]; then
  34. return 0
  35. fi
  36. return 1
  37. }