check_secrets.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF:-}"
  17. echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF:-}"
  18. check_secrets()
  19. {
  20. # Travis: Secrets are available if we're not running on a fork.
  21. if [[ -n "${TRAVIS_PULL_REQUEST:-}" ]]; then
  22. if [[ "$TRAVIS_PULL_REQUEST" == "false" ||
  23. "$TRAVIS_PULL_REQUEST_SLUG" == "$TRAVIS_REPO_SLUG" ]]; then
  24. return 0
  25. fi
  26. fi
  27. # GitHub Actions: Secrets are available if we're not running on a fork.
  28. # See https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables
  29. # TODO- Both GITHUB_BASE_REF and GITHUB_HEAD_REF are set in main repo
  30. # PRs even thought the docs say otherwise. They are not set in cron jobs on main.
  31. # Investigate how do to distinguish fork PRs from main repo PRs.
  32. if [[ -n "${GITHUB_WORKFLOW:-}" ]]; then
  33. return 0
  34. fi
  35. return 1
  36. }