create_certs.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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@v4
  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. ENABLE_NUKE_CERTS=${{ vars.ENABLE_NUKE_CERTS }}
  52. if [ -f "$CERT_STATUS_FILE" ]; then
  53. CERT_STATUS=$(cat "$CERT_STATUS_FILE" | tr -d '\n' | tr -d '\r') # Read file content and strip newlines
  54. echo "new_certificate_needed: $CERT_STATUS"
  55. echo "new_certificate_needed=$CERT_STATUS" >> $GITHUB_OUTPUT
  56. else
  57. echo "Certificate status file not found. Defaulting to false."
  58. echo "new_certificate_needed=false" >> $GITHUB_OUTPUT
  59. fi
  60. # Check if ENABLE_NUKE_CERTS is not set to true when certs are valid
  61. if [ "$CERT_STATUS" != "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
  62. echo "::notice::🔔 Automated renewal of certificates is disabled because the repository variable ENABLE_NUKE_CERTS is not set to 'true'."
  63. fi
  64. # Check if ENABLE_NUKE_CERTS is not set to true when certs are not valid
  65. if [ "$CERT_STATUS" = "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
  66. 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'."
  67. exit 1
  68. fi
  69. # Check if vars.FORCE_NUKE_CERTS is not set to true
  70. if [ vars.FORCE_NUKE_CERTS = "true" ]; then
  71. echo "::warning::‼️ Nuking of certificates was forced because the repository variable FORCE_NUKE_CERTS is set to 'true'."
  72. fi
  73. # 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
  74. nuke_certs:
  75. name: Nuke certificates
  76. needs: [validate, create_certs]
  77. runs-on: macos-15
  78. if: ${{ (needs.create_certs.outputs.new_certificate_needed == 'true' && vars.ENABLE_NUKE_CERTS == 'true') || vars.FORCE_NUKE_CERTS == 'true' }}
  79. steps:
  80. - name: Output from step id 'check_certs'
  81. run: echo "new_certificate_needed=${{ needs.create_certs.outputs.new_certificate_needed }}"
  82. - name: Checkout repository
  83. uses: actions/checkout@v4
  84. - name: Install dependencies
  85. run: bundle install
  86. - name: Run Fastlane nuke_certs
  87. run: |
  88. set -e # Set error immediately after this step if error occurs
  89. bundle exec fastlane nuke_certs
  90. - name: Recreate Distribution certificate after nuking
  91. run: |
  92. set -e # Set error immediately after this step if error occurs
  93. bundle exec fastlane certs
  94. - name: Add success annotations for nuke and certificate recreation
  95. if: ${{ success() }}
  96. run: |
  97. echo "::warning::⚠️ All Distribution certificates and TestFlight profiles have been revoked and recreated."
  98. 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."
  99. echo "::warning::✅ But don't worry about your existing TestFlight builds, they will keep working!"