Skip to content

Commit dbb44c2

Browse files
authored
Merge pull request #462 from nightscout/release/0.2.3
Release v0.2.3
2 parents d97ee5e + 9035ee4 commit dbb44c2

File tree

11 files changed

+193
-51
lines changed

11 files changed

+193
-51
lines changed

.github/ISSUE_TEMPLATE/bug-report.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name: "\U0001F41B Bug report"
33
about: Create a report to help us fix things
44
title: ''
5-
labels: ['bug', 'needs-triage']
5+
labels: ['needs-triage']
6+
type: "bug"
67
assignees: ''
78
projects: ['nightscout/2']
89

.github/ISSUE_TEMPLATE/feature-request.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
name: "\U0001F4A1 Feature request \U0001F4A1"
33
about: Suggest an idea for this project
44
title: ''
5-
labels: ['enhancement', 'needs-triage']
5+
labels: ['needs-triage']
6+
types: "feature"
67
assignees: ''
78
projects: ['nightscout/2']
89

.github/workflows/build_trio.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ env:
1818
ALIVE_BRANCH_DEV: alive-dev
1919

2020
jobs:
21-
validate:
22-
name: Validate
23-
uses: ./.github/workflows/validate_secrets.yml
24-
secrets: inherit
21+
# Checks if Distribution certificate is present and valid, optionally nukes and
22+
# creates new certs if the repository variable ENABLE_NUKE_CERTS == 'true'
23+
check_certs:
24+
name: Check certificates
25+
uses: ./.github/workflows/create_certs.yml
26+
secrets: inherit
2527

2628
# Checks if GH_PAT holds workflow permissions
2729
# Checks for existence of alive branch; if non-existent creates it
2830
check_alive_and_permissions:
29-
needs: validate
31+
needs: check_certs
3032
runs-on: ubuntu-latest
3133
name: Check alive branch and permissions
3234
permissions:
@@ -96,7 +98,7 @@ jobs:
9698
# Checks for changes in upstream repository; if changes exist prompts sync for build
9799
# Performs keepalive to avoid stale fork
98100
check_latest_from_upstream:
99-
needs: [validate, check_alive_and_permissions]
101+
needs: [check_certs, check_alive_and_permissions]
100102
runs-on: ubuntu-latest
101103
name: Check upstream and keep alive
102104
outputs:
@@ -185,7 +187,7 @@ jobs:
185187
# Builds Trio
186188
build:
187189
name: Build
188-
needs: [validate, check_alive_and_permissions, check_latest_from_upstream]
190+
needs: [check_certs, check_alive_and_permissions, check_latest_from_upstream]
189191
runs-on: macos-14
190192
permissions:
191193
contents: write

.github/workflows/create_certs.yml

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
name: 3. Create Certificates
22
run-name: Create Certificates (${{ github.ref_name }})
3-
on:
4-
workflow_dispatch:
3+
4+
on: [workflow_call, workflow_dispatch]
5+
6+
env:
7+
TEAMID: ${{ secrets.TEAMID }}
8+
GH_PAT: ${{ secrets.GH_PAT }}
9+
GH_TOKEN: ${{ secrets.GH_PAT }}
10+
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
11+
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
12+
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
13+
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
514

615
jobs:
716
validate:
817
name: Validate
918
uses: ./.github/workflows/validate_secrets.yml
1019
secrets: inherit
11-
12-
certificates:
13-
name: Create Certificates
20+
21+
create_certs:
22+
name: Certificates
1423
needs: validate
1524
runs-on: macos-14
25+
outputs:
26+
new_certificate_needed: ${{ steps.set_output.outputs.new_certificate_needed }}
27+
1628
steps:
1729
# Uncomment to manually select latest Xcode if needed
1830
#- name: Select Latest Xcode
@@ -37,17 +49,76 @@ jobs:
3749
- name: Install Project Dependencies
3850
run: bundle install
3951

40-
# Sync the GitHub runner clock with the Windows time server (workaround as suggested in https://github.com/actions/runner/issues/2996)
41-
- name: Sync clock
42-
run: sudo sntp -sS time.windows.com
43-
44-
# Create or update certificates for app
45-
- name: Create Certificates
46-
run: bundle exec fastlane certs
47-
env:
48-
TEAMID: ${{ secrets.TEAMID }}
49-
GH_PAT: ${{ secrets.GH_PAT }}
50-
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
51-
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
52-
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
53-
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
52+
# Create or update Distribution certificate and provisioning profiles
53+
- name: Check and create or update Distribution certificate and profiles if needed
54+
run: |
55+
echo "Running Fastlane certs lane..."
56+
bundle exec fastlane certs || true # ignore and continue on errors without annotating an exit code
57+
58+
- name: Check Distribution certificate and launch Nuke certificates if needed
59+
run: bundle exec fastlane check_and_renew_certificates
60+
id: check_certs
61+
62+
- name: Set output and annotations based on Fastlane result
63+
id: set_output
64+
run: |
65+
CERT_STATUS_FILE="${{ github.workspace }}/fastlane/new_certificate_needed.txt"
66+
ENABLE_NUKE_CERTS=${{ vars.ENABLE_NUKE_CERTS }}
67+
68+
if [ -f "$CERT_STATUS_FILE" ]; then
69+
CERT_STATUS=$(cat "$CERT_STATUS_FILE" | tr -d '\n' | tr -d '\r') # Read file content and strip newlines
70+
echo "new_certificate_needed: $CERT_STATUS"
71+
echo "new_certificate_needed=$CERT_STATUS" >> $GITHUB_OUTPUT
72+
else
73+
echo "Certificate status file not found. Defaulting to false."
74+
echo "new_certificate_needed=false" >> $GITHUB_OUTPUT
75+
fi
76+
77+
# Check if ENABLE_NUKE_CERTS is not set to true when certs are valid
78+
if [ "$CERT_STATUS" != "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
79+
echo "::notice::🔔 Automated renewal of certificates is disabled because the repository variable ENABLE_NUKE_CERTS is not set to 'true'."
80+
fi
81+
82+
# Check if ENABLE_NUKE_CERTS is not set to true when certs are not valid
83+
if [ "$CERT_STATUS" = "true" ] && [ "$ENABLE_NUKE_CERTS" != "true" ]; then
84+
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'."
85+
exit 1
86+
fi
87+
88+
# Check if vars.FORCE_NUKE_CERTS is not set to true
89+
if [ vars.FORCE_NUKE_CERTS = "true" ]; then
90+
echo "::warning::‼️ Nuking of certificates was forced because the repository variable FORCE_NUKE_CERTS is set to 'true'."
91+
fi
92+
93+
# 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
94+
nuke_certs:
95+
name: Nuke certificates
96+
needs: [validate, create_certs]
97+
runs-on: macos-14
98+
if: ${{ (needs.create_certs.outputs.new_certificate_needed == 'true' && vars.ENABLE_NUKE_CERTS == 'true') || vars.FORCE_NUKE_CERTS == 'true' }}
99+
steps:
100+
- name: Output from step id 'check_certs'
101+
run: echo "new_certificate_needed=${{ needs.create_certs.outputs.new_certificate_needed }}"
102+
103+
- name: Checkout repository
104+
uses: actions/checkout@v4
105+
106+
- name: Install dependencies
107+
run: bundle install
108+
109+
- name: Run Fastlane nuke_certs
110+
run: |
111+
set -e # Set error immediately after this step if error occurs
112+
bundle exec fastlane nuke_certs
113+
114+
- name: Recreate Distribution certificate after nuking
115+
run: |
116+
set -e # Set error immediately after this step if error occurs
117+
bundle exec fastlane certs
118+
119+
- name: Add success annotations for nuke and certificate recreation
120+
if: ${{ success() }}
121+
run: |
122+
echo "::warning::⚠️ All Distribution certificates and TestFlight profiles have been revoked and recreated."
123+
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."
124+
echo "::warning::✅ But don't worry about your existing TestFlight builds, they will keep working!"

.github/workflows/validate_secrets.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,15 @@ jobs:
178178
elif ! echo "$FASTLANE_KEY" | openssl pkcs8 -nocrypt >/dev/null; then
179179
failed=true
180180
echo "::error::The FASTLANE_KEY secret is set but invalid. Verify that you copied it correctly from the API Key file (*.p8) you downloaded and try again."
181-
elif ! bundle exec fastlane validate_secrets 2>&1 | tee fastlane.log; then
181+
elif ! (bundle exec fastlane validate_secrets 2>&1 || true) | tee fastlane.log; then # ignore "fastlane validate_secrets" errors and continue on errors without annotating an exit code
182182
if grep -q "bad decrypt" fastlane.log; then
183183
failed=true
184184
echo "::error::Unable to decrypt the Match-Secrets repository using the MATCH_PASSWORD secret. Verify that it is set correctly and try again."
185185
elif grep -q -e "required agreement" -e "license agreement" fastlane.log; then
186186
failed=true
187-
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."
188-
elif ! grep -q -e "No code signing identity found" -e "Could not install WWDR certificate" fastlane.log; then
189-
failed=true
190-
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."
187+
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."
188+
elif grep -q "Your certificate .* is not valid" fastlane.log; then
189+
echo "::notice::Your Distribution certificate is invalid or expired. Automated renewal of the certificate will be attempted."
191190
fi
192191
fi
193192

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APP_DISPLAY_NAME = Trio
2-
APP_VERSION = 0.2.2
2+
APP_VERSION = 0.2.3
33
APP_BUILD_NUMBER = 1
44
COPYRIGHT_NOTICE =
55
DEVELOPER_TEAM = ##TEAM_ID##

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can either use the Build Script or you can run each command manually.
1616

1717
### Build Script:
1818

19-
If you copy, paste, and run the following script in Terminal, it will guide you through downloading and installing Trio. More information about the script can be found [here](https://docs.diy-trio.org/en/latest/operate/build.html#build-trio-with-script).
19+
If you copy, paste, and run the following script in Terminal, it will guide you through downloading and installing Trio. More information about the script can be found [here](https://docs.diy-trio.org/operate/build/#build-trio-with-script).
2020

2121
```
2222
/bin/bash -c "$(curl -fsSL \
@@ -65,7 +65,7 @@ Instructions in greater detail, but not Trio-specific:
6565

6666
[Discord Trio - Server ](http://discord.diy-trio.org)
6767

68-
[Trio documentation](https://docs.diy-trio.org/en/latest/)
68+
[Trio documentation](https://docs.diy-trio.org/)
6969

7070
TODO: Add link: Trio Website (under development, not existing yet)
7171

fastlane/Fastfile

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ platform :ios do
217217

218218
match(
219219
type: "appstore",
220-
force: true,
220+
force: false,
221+
verbose: true,
221222
git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}"),
222223
app_identifier: [
223224
"#{BUNDLE_ID}",
@@ -271,4 +272,56 @@ platform :ios do
271272
git_basic_authorization: Base64.strict_encode64("#{GITHUB_REPOSITORY_OWNER}:#{GH_PAT}")
272273
)
273274
end
274-
end
275+
276+
desc "Check Certificates and Trigger Workflow for Expired or Missing Certificates"
277+
lane :check_and_renew_certificates do
278+
setup_ci if ENV['CI']
279+
ENV["MATCH_READONLY"] = false.to_s
280+
281+
# Authenticate using App Store Connect API Key
282+
api_key = app_store_connect_api_key(
283+
key_id: ENV["FASTLANE_KEY_ID"],
284+
issuer_id: ENV["FASTLANE_ISSUER_ID"],
285+
key_content: ENV["FASTLANE_KEY"] # Ensure valid key content
286+
)
287+
288+
# Initialize flag to track if renewal of certificates is needed
289+
new_certificate_needed = false
290+
291+
# Fetch all certificates
292+
certificates = Spaceship::ConnectAPI::Certificate.all
293+
294+
# Filter for Distribution Certificates
295+
distribution_certs = certificates.select { |cert| cert.certificate_type == "DISTRIBUTION" }
296+
297+
# Handle case where no distribution certificates are found
298+
if distribution_certs.empty?
299+
puts "No Distribution certificates found! Triggering action to create certificate."
300+
new_certificate_needed = true
301+
else
302+
# Check for expiration
303+
distribution_certs.each do |cert|
304+
expiration_date = Time.parse(cert.expiration_date)
305+
306+
puts "Current Distribution Certificate: #{cert.id}, Expiration date: #{expiration_date}"
307+
308+
if expiration_date < Time.now
309+
puts "Distribution Certificate #{cert.id} is expired! Triggering action to renew certificate."
310+
new_certificate_needed = true
311+
else
312+
puts "Distribution certificate #{cert.id} is valid. No action required."
313+
end
314+
end
315+
end
316+
317+
# Write result to new_certificate_needed.txt
318+
file_path = File.expand_path('new_certificate_needed.txt')
319+
File.write(file_path, new_certificate_needed ? 'true' : 'false')
320+
321+
# Log the absolute path and contents of the new_certificate_needed.txt file
322+
puts ""
323+
puts "Absolute path of new_certificate_needed.txt: #{file_path}"
324+
new_certificate_needed_content = File.read(file_path)
325+
puts "Certificate creation or renewal needed: #{new_certificate_needed_content}"
326+
end
327+
end

0 commit comments

Comments
 (0)