validate_secrets.yml 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. name: 1. Validate Secrets
  2. run-name: Validate Secrets
  3. on: [workflow_call, workflow_dispatch]
  4. jobs:
  5. validate:
  6. runs-on: macos-13
  7. steps:
  8. # Checks-out the repo
  9. - name: Checkout Repo
  10. uses: actions/checkout@v3
  11. # Sync the GitHub runner clock with the Windows time server (workaround as suggested in https://github.com/actions/runner/issues/2996)
  12. - name: Sync clock
  13. run: sudo sntp -sS time.windows.com
  14. # Validates the repo secrets
  15. - name: Validate Secrets
  16. run: |
  17. # Validate Secrets
  18. echo Validating Repository Secrets...
  19. # Validate TEAMID
  20. if [ -z "$TEAMID" ]; then
  21. failed=true
  22. echo "::error::TEAMID secret is unset or empty. Set it and try again."
  23. elif [ ${#TEAMID} -ne 10 ]; then
  24. failed=true
  25. echo "::error::TEAMID secret is set but has wrong length. Verify that it is set correctly and try again."
  26. fi
  27. # Validate GH_PAT
  28. if [ -z "$GH_PAT" ]; then
  29. failed=true
  30. echo "::error::GH_PAT secret is unset or empty. Set it and try again."
  31. elif [ "$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Match-Secrets | jq --raw-output '.permissions.push')" != "true" ]; then
  32. failed=true
  33. echo "::error::GH_PAT secret is set but invalid or lacking appropriate privileges on the ${{ github.repository_owner }}/Match-Secrets repository. Verify that it is set correctly and try again."
  34. fi
  35. # Validate FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY
  36. if [ -z "$FASTLANE_ISSUER_ID" ] || [ -z "$FASTLANE_KEY_ID" ] || [ -z "$FASTLANE_KEY" ]; then
  37. failed=true
  38. [ -z "$FASTLANE_ISSUER_ID" ] && echo "::error::The FASTLANE_ISSUER_ID secret is unset or empty. Set it and try again."
  39. [ -z "$FASTLANE_KEY_ID" ] && echo "::error::The FASTLANE_KEY_ID secret is unset or empty. Set it and try again."
  40. [ -z "$FASTLANE_KEY" ] && echo "::error::The FASTLANE_KEY secret is unset or empty. Set it and try again."
  41. elif ! echo "$FASTLANE_KEY" | openssl pkcs8 -nocrypt >/dev/null; then
  42. failed=true
  43. echo "::error::The FASTLANE_KEY secret is set but invalid. Verify that it is set correctly and try again."
  44. elif ! fastlane validate_secrets; then
  45. failed=true
  46. echo "::error::Unable to create a valid authorization token for the App Store Connect API.\
  47. Verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again."
  48. fi
  49. # Validate MATCH_PASSWORD
  50. if [ -z "$MATCH_PASSWORD" ]; then
  51. failed=true
  52. echo "::error::The MATCH_PASSWORD secret is unset or empty. Set it and try again."
  53. fi
  54. # Exit unsuccessfully if secret validation failed.
  55. if [ $failed ]; then
  56. exit 2
  57. fi
  58. shell: bash
  59. env:
  60. TEAMID: ${{ secrets.TEAMID }}
  61. GH_PAT: ${{ secrets.GH_PAT }}
  62. FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
  63. FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
  64. FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
  65. MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
  66. GH_TOKEN: ${{ secrets.GH_PAT }}