Skip to content

Commit fc11578

Browse files
committed
Validate repository secrets
Adds support for validation of repository secrets.
1 parent a9c4e9b commit fc11578

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

.github/workflows/add_identifiers.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ on:
33
workflow_dispatch:
44

55
jobs:
6+
secrets:
7+
uses: ./.github/workflows/validate_secrets.yml
8+
secrets: inherit
9+
610
identifiers:
11+
needs: secrets
712
runs-on: macos-12
813
steps:
914
# Uncomment to manually select latest Xcode if needed

.github/workflows/build_loop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ on:
33
workflow_dispatch:
44

55
jobs:
6+
secrets:
7+
uses: ./.github/workflows/validate_secrets.yml
8+
secrets: inherit
9+
610
build:
11+
needs: secrets
712
runs-on: macos-12
813
steps:
914
# Uncomment to manually select latest Xcode if needed

.github/workflows/create_certs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ on:
33
workflow_dispatch:
44

55
jobs:
6+
secrets:
7+
uses: ./.github/workflows/validate_secrets.yml
8+
secrets: inherit
9+
610
certificates:
11+
needs: secrets
712
runs-on: macos-12
813
steps:
914
# Uncomment to manually select latest Xcode if needed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Validate Secrets
2+
on: [workflow_call, workflow_dispatch]
3+
4+
jobs:
5+
validate:
6+
runs-on: macos-12
7+
steps:
8+
# Checks-out the repo
9+
- name: Checkout Repo
10+
uses: actions/checkout@v3
11+
12+
# Validates the repo secrets
13+
- name: Validate Secrets
14+
run: |
15+
# Validate Secrets
16+
echo Validating Repository Secrets...
17+
18+
# Validate TEAMID
19+
if [ -z "$TEAMID" ]; then
20+
failed=true
21+
echo "::error::TEAMID secret is unset or empty. Set it and try again."
22+
elif [ ${#TEAMID} -ne 10 ]; then
23+
failed=true
24+
echo "::error::TEAMID secret is set but has wrong length. Verify that it is set correctly and try again."
25+
fi
26+
27+
# Validate GH_PAT
28+
if [ -z "$GH_PAT" ]; then
29+
failed=true
30+
echo "::error::GH_PAT secret is unset or empty. Set it and try again."
31+
elif [ "$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Match-Secrets | jq --raw-output '.permissions.push')" != "true" ]; then
32+
failed=true
33+
echo "::error::GH_PAT secret is set but invalid or lacking appropriate privileges on the ${{ github.repository_owner }}/Match-Secrets repository. Verify that it is set correctly and try again."
34+
fi
35+
36+
# Validate FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY
37+
if [ -z "$FASTLANE_ISSUER_ID" ] || [ -z "$FASTLANE_KEY_ID" ] || [ -z "$FASTLANE_KEY" ]; then
38+
failed=true
39+
[ -z "$FASTLANE_ISSUER_ID" ] && echo "::error::The FASTLANE_ISSUER_ID secret is unset or empty. Set it and try again."
40+
[ -z "$FASTLANE_KEY_ID" ] && echo "::error::The FASTLANE_KEY_ID secret is unset or empty. Set it and try again."
41+
[ -z "$FASTLANE_KEY" ] && echo "::error::The FASTLANE_KEY secret is unset or empty. Set it and try again."
42+
elif ! echo "$FASTLANE_KEY" | openssl ec -noout >/dev/null 2>&1; then
43+
failed=true
44+
echo "::error::The FASTLANE_KEY secret is set but invalid. Verify that it is set correctly and try again."
45+
elif ! fastlane validate_secrets; then
46+
failed=true
47+
echo "::error::Unable to create a valid authorization token for the App Store Connect API.\
48+
Verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again."
49+
fi
50+
51+
# Validate MATCH_PASSWORD
52+
if [ -z "$MATCH_PASSWORD" ]; then
53+
failed=true
54+
echo "::error::The MATCH_PASSWORD secret is unset or empty. Set it and try again."
55+
fi
56+
57+
# Exit unsuccessfully if secret validation failed.
58+
if [ $failed ]; then
59+
exit 2
60+
fi
61+
shell: bash
62+
env:
63+
TEAMID: ${{ secrets.TEAMID }}
64+
GH_PAT: ${{ secrets.GH_PAT }}
65+
FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }}
66+
FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }}
67+
FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }}
68+
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
69+
GH_TOKEN: ${{ secrets.GH_PAT }}
70+
71+
72+
73+

fastlane/Fastfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ platform :ios do
231231
)
232232
end
233233

234+
desc "Validate Secrets"
235+
lane :validate_secrets do
236+
setup_ci if ENV['CI']
237+
ENV["MATCH_READONLY"] = true.to_s
238+
239+
app_store_connect_api_key(
240+
key_id: "#{FASTLANE_KEY_ID}",
241+
issuer_id: "#{FASTLANE_ISSUER_ID}",
242+
key_content: "#{FASTLANE_KEY}"
243+
)
244+
245+
def find_bundle_id(identifier)
246+
bundle_id = Spaceship::ConnectAPI::BundleId.find(identifier)
247+
end
248+
249+
find_bundle_id("com.#{TEAMID}.loopkit.Loop")
250+
end
251+
234252
desc "Nuke Certs"
235253
lane :nuke_certs do
236254
setup_ci if ENV['CI']

0 commit comments

Comments
 (0)