create_certs.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. name: 3. Create Certificates
  2. run-name: Create Certificates (${{ github.ref_name }})
  3. on: [workflow_call, workflow_dispatch]
  4. env:
  5. TEAMID: ${{ secrets.TEAMID }}
  6. GH_PAT: ${{ secrets.GH_PAT }}
  7. MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
  8. FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
  9. FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
  10. FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
  11. jobs:
  12. validate:
  13. name: Validate
  14. uses: ./.github/workflows/validate_secrets.yml
  15. secrets: inherit
  16. create_certs:
  17. name: Certificates
  18. needs: validate
  19. runs-on: macos-15
  20. outputs:
  21. new_certificate_needed: ${{ steps.set_output.outputs.new_certificate_needed }}
  22. steps:
  23. # Checks-out the repo
  24. - name: Checkout Repo
  25. uses: actions/checkout@v5
  26. # Patch Fastlane Match not print tables
  27. - name: Patch Match Tables
  28. run: |
  29. TABLE_PRINTER_PATH=$(ruby -e 'puts Gem::Specification.find_by_name("fastlane").gem_dir')/match/lib/match/table_printer.rb
  30. if [ -f "$TABLE_PRINTER_PATH" ]; then
  31. sed -i "" "/puts(Terminal::Table.new(params))/d" "$TABLE_PRINTER_PATH"
  32. else
  33. echo "table_printer.rb not found"
  34. exit 1
  35. fi
  36. # Install project dependencies
  37. - name: Install Project Dependencies
  38. run: bundle install
  39. # Create or update Distribution certificate and provisioning profiles
  40. - name: Check and create or update Distribution certificate and profiles if needed
  41. run: |
  42. echo "Running Fastlane certs lane..."
  43. bundle exec fastlane certs || true # ignore and continue on errors without annotating an exit code
  44. - name: Check Distribution certificate and launch Nuke certificates if needed
  45. run: bundle exec fastlane check_and_renew_certificates
  46. id: check_certs
  47. - name: Set output and annotations based on Fastlane result
  48. id: set_output
  49. run: |
  50. CERT_STATUS_FILE="${{ github.workspace }}/fastlane/new_certificate_needed.txt"
  51. # Convert to lowercase for case-insensitive comparison
  52. ENABLE_NUKE_CERTS=$(echo "${{ vars.ENABLE_NUKE_CERTS }}" | tr '[:upper:]' '[:lower:]')
  53. FORCE_NUKE_CERTS=$(echo "${{ vars.FORCE_NUKE_CERTS }}" | tr '[:upper:]' '[:lower:]')
  54. if [ -f "$CERT_STATUS_FILE" ]; then
  55. CERT_STATUS=$(cat "$CERT_STATUS_FILE" | tr -d '\n' | tr -d '\r') # Read file content and strip newlines
  56. echo "new_certificate_needed: $CERT_STATUS"
  57. echo "new_certificate_needed=$CERT_STATUS" >> $GITHUB_OUTPUT
  58. else
  59. echo "Certificate status file not found. Defaulting to false."
  60. echo "new_certificate_needed=false" >> $GITHUB_OUTPUT
  61. fi
  62. # Check if ENABLE_NUKE_CERTS is not set to true when certs are valid
  63. if [ "$CERT_STATUS" != "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
  64. echo "::notice::🔔 Automated renewal of certificates is disabled because the repository variable ENABLE_NUKE_CERTS is not set to 'true'."
  65. fi
  66. # Check if ENABLE_NUKE_CERTS is not set to true when certs are not valid
  67. if [ "$CERT_STATUS" = "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
  68. echo "::error::❌ No valid distribution certificate found. Automated renewal of certificates was skipped because the repository variable ENABLE_NUKE_CERTS is not set to 'true'."
  69. exit 1
  70. fi
  71. # Check if FORCE_NUKE_CERTS is set to true
  72. if [ "$FORCE_NUKE_CERTS" = "true" ]; then
  73. echo "::warning::‼️ Nuking of certificates was forced because the repository variable FORCE_NUKE_CERTS is set to 'true'."
  74. fi
  75. # Nuke Certs if needed, and if the repository variable ENABLE_NUKE_CERTS is set to 'true', or if FORCE_NUKE_CERTS is set to 'true', which will always force certs to be nuked
  76. nuke_certs:
  77. name: Nuke certificates
  78. needs: [validate, create_certs]
  79. runs-on: macos-15
  80. if: ${{ (needs.create_certs.outputs.new_certificate_needed == 'true' && vars.ENABLE_NUKE_CERTS == 'true') || vars.FORCE_NUKE_CERTS == 'true' }}
  81. steps:
  82. - name: Output from step id 'check_certs'
  83. run: echo "new_certificate_needed=${{ needs.create_certs.outputs.new_certificate_needed }}"
  84. - name: Checkout repository
  85. uses: actions/checkout@v5
  86. - name: Install dependencies
  87. run: bundle install
  88. - name: Run Fastlane nuke_certs
  89. run: |
  90. set -e # Set error immediately after this step if error occurs
  91. bundle exec fastlane nuke_certs
  92. - name: Recreate Distribution certificate after nuking
  93. run: |
  94. set -e # Set error immediately after this step if error occurs
  95. bundle exec fastlane certs
  96. - name: Add success annotations for nuke and certificate recreation
  97. if: ${{ success() }}
  98. run: |
  99. echo "::warning::⚠️ All Distribution certificates and TestFlight profiles have been revoked and recreated."
  100. echo "::warning::❗️ If you have other apps being distributed by GitHub Actions / Fastlane / TestFlight that does not renew certificates automatically, please run the '3. Create Certificates' workflow for each of these apps to allow these apps to be built."
  101. echo "::warning::✅ But don't worry about your existing TestFlight builds, they will keep working!"