create_certs.yml 5.4 KB

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