validate_secrets.yml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # Validates the repo secrets
  12. - name: Validate Secrets
  13. run: |
  14. # Validate Secrets
  15. echo Validating Repository Secrets...
  16. # Validate TEAMID
  17. if [ -z "$TEAMID" ]; then
  18. failed=true
  19. echo "::error::TEAMID secret is unset or empty. Set it and try again."
  20. elif [ ${#TEAMID} -ne 10 ]; then
  21. failed=true
  22. echo "::error::TEAMID secret is set but has wrong length. Verify that it is set correctly and try again."
  23. fi
  24. # Validate GH_PAT
  25. if [ -z "$GH_PAT" ]; then
  26. failed=true
  27. echo "::error::GH_PAT secret is unset or empty. Set it and try again."
  28. elif [ "$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Match-Secrets | jq --raw-output '.permissions.push')" != "true" ]; then
  29. failed=true
  30. 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."
  31. fi
  32. # Validate FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY
  33. if [ -z "$FASTLANE_ISSUER_ID" ] || [ -z "$FASTLANE_KEY_ID" ] || [ -z "$FASTLANE_KEY" ]; then
  34. failed=true
  35. [ -z "$FASTLANE_ISSUER_ID" ] && echo "::error::The FASTLANE_ISSUER_ID secret is unset or empty. Set it and try again."
  36. [ -z "$FASTLANE_KEY_ID" ] && echo "::error::The FASTLANE_KEY_ID secret is unset or empty. Set it and try again."
  37. [ -z "$FASTLANE_KEY" ] && echo "::error::The FASTLANE_KEY secret is unset or empty. Set it and try again."
  38. elif ! echo "$FASTLANE_KEY" | openssl pkcs8 -nocrypt >/dev/null; then
  39. failed=true
  40. echo "::error::The FASTLANE_KEY secret is set but invalid. Verify that it is set correctly and try again."
  41. elif ! fastlane validate_secrets; then
  42. failed=true
  43. echo "::error::Unable to create a valid authorization token for the App Store Connect API.\
  44. Verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again."
  45. fi
  46. # Validate MATCH_PASSWORD
  47. if [ -z "$MATCH_PASSWORD" ]; then
  48. failed=true
  49. echo "::error::The MATCH_PASSWORD secret is unset or empty. Set it and try again."
  50. fi
  51. # Exit unsuccessfully if secret validation failed.
  52. if [ $failed ]; then
  53. exit 2
  54. fi
  55. shell: bash
  56. env:
  57. TEAMID: ${{ secrets.TEAMID }}
  58. GH_PAT: ${{ secrets.GH_PAT }}
  59. FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
  60. FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
  61. FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
  62. MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
  63. GH_TOKEN: ${{ secrets.GH_PAT }}