fix(ci): clean up orphaned iOS certificates
This commit is contained in:
1 file changed
+24
-19
@@ -230,10 +230,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: List signing certificates
|
||||
- name: Archive and upload build 25
|
||||
shell: bash
|
||||
run: |
|
||||
node --input-type=module <<'NODE'
|
||||
set -euo pipefail
|
||||
|
||||
cleanup_api_certificates() {
|
||||
node --input-type=module <<'NODE'
|
||||
import crypto from "node:crypto"
|
||||
|
||||
const base64url = (value) => Buffer.from(value).toString("base64url")
|
||||
@@ -255,34 +258,36 @@ jobs:
|
||||
dsaEncoding: "ieee-p1363",
|
||||
})
|
||||
const token = `${unsigned}.${signature.toString("base64url")}`
|
||||
const headers = { Authorization: `Bearer ${token}` }
|
||||
const params = new URLSearchParams({
|
||||
"fields[certificates]": "name,displayName,certificateType,expirationDate,serialNumber,platform",
|
||||
"fields[certificates]": "displayName,certificateType",
|
||||
limit: "200",
|
||||
})
|
||||
const response = await fetch(
|
||||
`https://api.appstoreconnect.apple.com/v1/certificates?${params}`,
|
||||
{ headers: { Authorization: `Bearer ${token}` } }
|
||||
{ headers }
|
||||
)
|
||||
const body = await response.json()
|
||||
if (!response.ok) throw new Error(JSON.stringify(body.errors))
|
||||
for (const certificate of body.data) {
|
||||
const value = certificate.attributes
|
||||
console.log(JSON.stringify({
|
||||
id: certificate.id,
|
||||
name: value.name,
|
||||
displayName: value.displayName,
|
||||
type: value.certificateType,
|
||||
expires: value.expirationDate,
|
||||
serial: value.serialNumber,
|
||||
platform: value.platform,
|
||||
}))
|
||||
const disposable = body.data.filter((certificate) =>
|
||||
certificate.attributes.displayName === "Created via API"
|
||||
&& certificate.attributes.certificateType === "DEVELOPMENT"
|
||||
)
|
||||
for (const certificate of disposable) {
|
||||
const deletion = await fetch(
|
||||
`https://api.appstoreconnect.apple.com/v1/certificates/${certificate.id}`,
|
||||
{ method: "DELETE", headers }
|
||||
)
|
||||
if (!deletion.ok) {
|
||||
throw new Error(`Could not revoke disposable certificate ${certificate.id}`)
|
||||
}
|
||||
console.log(`Revoked disposable CI certificate ${certificate.id}`)
|
||||
}
|
||||
NODE
|
||||
}
|
||||
|
||||
- name: Archive and upload build 25
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cleanup_api_certificates
|
||||
trap 'status=$?; cleanup_api_certificates || true; exit $status' EXIT
|
||||
|
||||
for name in APPLE_API_KEY APPLE_API_KEY_ID APPLE_API_ISSUER; do
|
||||
if [ -z "${!name:-}" ]; then
|
||||
|
||||
Reference in new issue
Block a user