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