-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check_certs workflow and Fastlane lane for Distribution certificate management #228
Open
bjornoleh
wants to merge
12
commits into
LoopKit:dev
Choose a base branch
from
bjornoleh:check_and_renew_certs
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5dd137d
Add check_certs workflow and Fastlane lane for Distribution certifica…
bjornoleh 0a9d876
check_certs.yml: use checkout@v4
bjornoleh aa0115b
Don't nuke certs in warning period, add optional vars.FORCE_NUKE_CERTS
bjornoleh 4e8ed2e
Require check_certs before building
bjornoleh 063d602
Set error when no valid certs and ENABLE_NUKE_CERTS is not 'true'.
bjornoleh 5432ec6
Annotation for valid certs
bjornoleh 12628fe
Refine error annotations for Validate Fastlane Secrets
bjornoleh 90cc934
Remove unused env
bjornoleh fd9acda
Refactor GitHub Actions Workflows and Fastlane Configuration
bjornoleh 9b8ef46
Rename to "3. Check Certificates", delete old create_certificates.yml
bjornoleh b6bb80a
validate_secrets annotation improvement
bjornoleh 634bbae
Rename to original names create_certs.yml name: 3. Create Certificates
bjornoleh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: Check Certificates | ||
run-name: Check Certificates (${{ github.ref_name }}) | ||
|
||
on: [workflow_call, workflow_dispatch] | ||
|
||
env: | ||
EXPIRATION_WARNING_DAYS: 7 | ||
|
||
jobs: | ||
check_certs: | ||
runs-on: ubuntu-latest | ||
env: | ||
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }} | ||
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }} | ||
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }} | ||
outputs: | ||
new_certificate_needed: ${{ steps.set_output.outputs.new_certificate_needed }} | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.1' | ||
|
||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Check Certificates and create or renew if needed | ||
env: | ||
FASTLANE_USER: ${{ secrets.APPLE_ID }} | ||
FASTLANE_PASSWORD: ${{ secrets.APPLE_PASSWORD }} | ||
run: bundle exec fastlane check_and_renew_certificates | ||
id: check_certs | ||
|
||
- name: Set output based on Fastlane result | ||
id: set_output | ||
run: | | ||
CERT_STATUS_FILE="${{ github.workspace }}/fastlane/new_certificate_needed.txt" | ||
ENABLE_NUKE_CERTS=${{ vars.ENABLE_NUKE_CERTS }} | ||
|
||
if [ -f "$CERT_STATUS_FILE" ]; then | ||
CERT_STATUS=$(cat "$CERT_STATUS_FILE" | tr -d '\n' | tr -d '\r') # Read file content and strip newlines | ||
echo "new_certificate_needed: $CERT_STATUS" | ||
echo "new_certificate_needed=$CERT_STATUS" >> $GITHUB_OUTPUT | ||
else | ||
echo "Certificate status file not found. Defaulting to false." | ||
echo "new_certificate_needed=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
# Check if certs are valid | ||
if [ "$CERT_STATUS" != "true" ]; then | ||
echo "::notice::✅ Distribution certificate is present and valid. No action required." | ||
fi | ||
|
||
# Check if ENABLE_NUKE_CERTS is not set to true when certs are valid | ||
if [ "$CERT_STATUS" != "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then | ||
echo "::notice::🔔 Automated renewal of certificates is disabled because the repository variable ENABLE_NUKE_CERTS is not set to 'true'." | ||
fi | ||
|
||
# Check if ENABLE_NUKE_CERTS is not set to true when certs are not valid | ||
if [ "$CERT_STATUS" = "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then | ||
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'." | ||
exit 1 | ||
fi | ||
|
||
# Check if vars.FORCE_NUKE_CERTS is not set to true | ||
if [ vars.FORCE_NUKE_CERTS = "true" ]; then | ||
echo "::warning::‼️ Nuking of certificates was forced because the repository variable FORCE_NUKE_CERTS is set to 'true'." | ||
fi | ||
|
||
# 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 | ||
nuke_certs: | ||
needs: check_certs | ||
runs-on: macos-14 | ||
if: ${{ (needs.check_certs.outputs.new_certificate_needed == 'true' && vars.ENABLE_NUKE_CERTS == 'true') || vars.FORCE_NUKE_CERTS == 'true' }} | ||
steps: | ||
- name: Debug check_certs output | ||
run: echo "new_certificate_needed=${{ needs.check_certs.outputs.new_certificate_needed }}" | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.1' | ||
|
||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Run Fastlane nuke_certs | ||
run: bundle exec fastlane nuke_certs | ||
env: | ||
TEAMID: ${{ secrets.TEAMID }} | ||
GH_PAT: ${{ secrets.GH_PAT }} | ||
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} | ||
FASTLANE_USER: ${{ secrets.FASTLANE_USER }} | ||
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }} | ||
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }} | ||
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }} | ||
FASTLANE_SKIP_ALL_LANE_SUMMARIES: "true" | ||
|
||
- name: Annotate Summary after Nuke | ||
run: | | ||
echo "::warning::⚠️⚠️⚠️ All Distribution certificates and TestFlight profiles have been revoked." | ||
|
||
|
||
# Trigger create_certs.yml if nuke_certs ran | ||
trigger_create_certs: | ||
needs: [check_certs, nuke_certs] | ||
uses: ./.github/workflows/create_certs.yml | ||
secrets: inherit | ||
|
||
# Annotate Summary after Certificate Creation | ||
annotate_summary: | ||
needs: trigger_create_certs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Annotate Summary | ||
run: | | ||
echo "::warning::⚠️⚠️⚠️ Certificates have been recreated successfully." | ||
echo "::warning::⚠️⚠️⚠️ If you have other apps being distributed by GitHub Actions / Fastlane / TestFlight, please run the '3. Create Certificates' workflow for each of these apps to allow these apps to be built." | ||
echo "::warning::✅✅✅ But don't worry about your existing TestFlight builds, they will keep working!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,10 +184,13 @@ jobs: | |
echo "::error::Unable to decrypt the Match-Secrets repository using the MATCH_PASSWORD secret. Verify that it is set correctly and try again." | ||
elif grep -q -e "required agreement" -e "license agreement" fastlane.log; then | ||
failed=true | ||
echo "::error::Unable to create a valid authorization token for the App Store Connect API. Verify that the latest developer program license agreement has been accepted at https://developer.apple.com/account (review and accept any updated agreement), then wait a few minutes for changes to propagate and try again." | ||
echo "::error::Unable to create a valid authorization token for the App Store Connect API." | ||
echo "::error::❗️ Verify that the latest developer program license agreement has been accepted at https://developer.apple.com/account (review and accept any updated agreement), then wait a few minutes for changes to take effect and try again." | ||
elif ! grep -q -e "No code signing identity found" -e "Could not install WWDR certificate" fastlane.log; then | ||
failed=true | ||
echo "::error::Unable to create a valid authorization token for the App Store Connect API. Verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again." | ||
echo "::error::Unable to create a valid authorization token for the App Store Connect API." | ||
echo "::error::❗️ Verify that the latest developer program license agreement has been accepted at https://developer.apple.com/account (review and accept any updated agreement), then wait a few minutes for changes to take effect and try again." | ||
echo "::error::❗️ Also verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps "If you created a new FASTLANE KEY or have not previously succeeded with validate secrets, then check that FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets were entered correctly. |
||
fi | ||
fi | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change to build is not quite complete. I tested this after revoking certs and then building 2 different apps. I copied over the check_certs.yml file and modified the Fastfile, build_xxx.yml and create_certs.yml to match these changes in LoopFollow. Then added to LF_Second and LF_Third so I have 3 fast building apps to test.
The manual revoke Distribution cert, followed by build app (for the first app works - for any of the apps).
For each successive app, I must manually create certs and then it works.
Perhaps create certs could be modified to encompass some parts of check certs so that build works every time, with no need for a separate create certs step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, yes I know, we need a check for valid distribution profiles during build if we want to avoid the manual create certs here. Or just run create certs on each build. But that doesn’t sound like the right solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be resolved by fd9acda.
The certs lane is now changed to not force renewal of profiles, and is launched before every build to check if certificates and profiles are valid, and creates new one as needed. The nuke_certs lane is used if necessary.
When we get these changes into all of the other DIY repositories, everything around certs and profiles will be very easy for the users and supporting volunteers.
The current changes does not break much for the other apps, but until automation is included elsewhere, users will have to run the Create certificates workflow for each app after cert renewals. This is explained in annotations in the run summary.
I have also replaced the old Create certificates with the new one, currently named
3. Check certificates
, but with the same old create_certs.yml file name. This simplifies things when merging into dev then master (or the other way around?), as we won’t have to explain how new workflow files aren’t visible outside of the default branch.