fix(release): harden macOS publishing

This commit is contained in:
Formsmith746
2026-08-19 18:52:28 +03:00
parent 918a0cc162
commit 76298d590c
5 changed files with 72 additions and 16 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ The macOS job reads these repository secrets:
- `CSC_LINK`: base64-encoded Developer ID Application certificate - `CSC_LINK`: base64-encoded Developer ID Application certificate
- `CSC_KEY_PASSWORD`: certificate password - `CSC_KEY_PASSWORD`: certificate password
- `APPLE_API_KEY`: App Store Connect API private key path - `APPLE_API_KEY`: App Store Connect API private key contents or base64-encoded contents
- `APPLE_API_KEY_ID`: App Store Connect API key ID - `APPLE_API_KEY_ID`: App Store Connect API key ID
- `APPLE_API_ISSUER`: App Store Connect API issuer ID - `APPLE_API_ISSUER`: App Store Connect API issuer ID
+26 -3
View File
@@ -19,7 +19,7 @@ inputs:
description: Developer ID Application certificate password. description: Developer ID Application certificate password.
required: false required: false
apple-api-key: apple-api-key:
description: App Store Connect API private key path. description: App Store Connect API private key contents, base64, or path.
required: false required: false
apple-api-key-id: apple-api-key-id:
description: App Store Connect API key ID. description: App Store Connect API key ID.
@@ -55,13 +55,31 @@ runs:
env: env:
CSC_LINK: ${{ inputs.csc-link }} CSC_LINK: ${{ inputs.csc-link }}
CSC_KEY_PASSWORD: ${{ inputs.csc-key-password }} CSC_KEY_PASSWORD: ${{ inputs.csc-key-password }}
APPLE_API_KEY: ${{ inputs.apple-api-key }} APPLE_API_KEY_INPUT: ${{ inputs.apple-api-key }}
APPLE_API_KEY_ID: ${{ inputs.apple-api-key-id }} APPLE_API_KEY_ID: ${{ inputs.apple-api-key-id }}
APPLE_API_ISSUER: ${{ inputs.apple-api-issuer }} APPLE_API_ISSUER: ${{ inputs.apple-api-issuer }}
CSC_IDENTITY_AUTO_DISCOVERY: ${{ steps.signing.outputs.signing_enabled }} CSC_IDENTITY_AUTO_DISCOVERY: ${{ steps.signing.outputs.signing_enabled }}
run: | run: |
if [[ "${{ steps.signing.outputs.signing_enabled }}" == "false" ]]; then if [[ "${{ steps.signing.outputs.signing_enabled }}" == "false" ]]; then
unset CSC_LINK CSC_KEY_PASSWORD APPLE_API_KEY APPLE_API_KEY_ID APPLE_API_ISSUER unset CSC_LINK CSC_KEY_PASSWORD APPLE_API_KEY APPLE_API_KEY_ID APPLE_API_ISSUER
else
if [[ -f "$APPLE_API_KEY_INPUT" ]]; then
export APPLE_API_KEY="$APPLE_API_KEY_INPUT"
else
export APPLE_API_KEY="$RUNNER_TEMP/sketchforge-notary-${{ inputs.arch }}.p8"
node <<'NODE'
const fs = require("node:fs");
const input = process.env.APPLE_API_KEY_INPUT || "";
const output = process.env.APPLE_API_KEY;
const decoded = input.includes("BEGIN PRIVATE KEY")
? input
: Buffer.from(input, "base64").toString("utf8");
if (!decoded.includes("BEGIN PRIVATE KEY")) {
throw new Error("APPLE_API_KEY must be a .p8 path, key contents, or base64-encoded key contents.");
}
fs.writeFileSync(output, decoded, { mode: 0o600 });
NODE
fi
fi fi
npm run desktop:dist -- --publish never --mac --${{ inputs.arch }} \ npm run desktop:dist -- --publish never --mac --${{ inputs.arch }} \
"-c.mac.artifactName=\${productName}-\${version}-\${arch}${{ steps.signing.outputs.artifact_suffix }}.\${ext}" "-c.mac.artifactName=\${productName}-\${version}-\${arch}${{ steps.signing.outputs.artifact_suffix }}.\${ext}"
@@ -74,9 +92,14 @@ runs:
suffix="${{ steps.signing.outputs.artifact_suffix }}" suffix="${{ steps.signing.outputs.artifact_suffix }}"
test -f "dist/desktop/SketchForge-$VERSION-${{ inputs.arch }}${suffix}.dmg" test -f "dist/desktop/SketchForge-$VERSION-${{ inputs.arch }}${suffix}.dmg"
test -f "dist/desktop/SketchForge-$VERSION-${{ inputs.arch }}${suffix}.zip" test -f "dist/desktop/SketchForge-$VERSION-${{ inputs.arch }}${suffix}.zip"
test -f dist/desktop/latest-mac.yml if [[ "${{ steps.signing.outputs.signing_enabled }}" == "true" ]]; then
test -f dist/desktop/latest-mac.yml
else
rm -f dist/desktop/latest-mac.yml
fi
- name: Rename macOS update manifest - name: Rename macOS update manifest
if: steps.signing.outputs.signing_enabled == 'true'
shell: bash shell: bash
run: mv dist/desktop/latest-mac.yml "dist/desktop/latest-mac-${{ inputs.arch }}.yml" run: mv dist/desktop/latest-mac.yml "dist/desktop/latest-mac-${{ inputs.arch }}.yml"
+43 -12
View File
@@ -172,7 +172,12 @@ jobs:
run: | run: |
git fetch --tags --force git fetch --tags --force
if git rev-parse "$TAG" >/dev/null 2>&1; then if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "$TAG already exists." tag_sha=$(git rev-list -n 1 "$TAG")
source_sha=$(git rev-parse "$SOURCE_SHA^{commit}")
if [[ "$tag_sha" != "$source_sha" ]]; then
echo "$TAG already points to $tag_sha instead of $source_sha." >&2
exit 1
fi
else else
git tag "$TAG" "$SOURCE_SHA" git tag "$TAG" "$SOURCE_SHA"
git push origin "$TAG" git push origin "$TAG"
@@ -213,14 +218,24 @@ jobs:
"dist/release/macos-x64/latest-mac-x64.yml", "dist/release/macos-x64/latest-mac-x64.yml",
"dist/release/macos-arm64/latest-mac-arm64.yml", "dist/release/macos-arm64/latest-mac-arm64.yml",
]; ];
const manifests = paths.map((file) => yaml.load(fs.readFileSync(file, "utf8"))); const existingPaths = paths.filter((file) => fs.existsSync(file));
const merged = { if (existingPaths.length === 1) {
...manifests[0], throw new Error("Only one macOS architecture produced an updater manifest.");
files: manifests.flatMap((manifest) => manifest.files || []), }
}; if (existingPaths.length === 2) {
delete merged.path; const manifests = existingPaths.map((file) => yaml.load(fs.readFileSync(file, "utf8")));
delete merged.sha512; const versions = new Set(manifests.map((manifest) => manifest.version));
fs.writeFileSync("dist/release/latest-mac.yml", yaml.dump(merged, { noRefs: true })); if (versions.size !== 1) {
throw new Error("macOS updater manifests have different versions.");
}
const merged = {
...manifests[0],
files: manifests.flatMap((manifest) => manifest.files || []),
};
delete merged.path;
delete merged.sha512;
fs.writeFileSync("dist/release/latest-mac.yml", yaml.dump(merged, { noRefs: true }));
}
for (const directory of ["macos-x64", "macos-arm64"]) { for (const directory of ["macos-x64", "macos-arm64"]) {
for (const file of fs.readdirSync(`dist/release/${directory}`)) { for (const file of fs.readdirSync(`dist/release/${directory}`)) {
if (file === "latest-mac-x64.yml" || file === "latest-mac-arm64.yml") continue; if (file === "latest-mac-x64.yml" || file === "latest-mac-arm64.yml") continue;
@@ -254,7 +269,15 @@ jobs:
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }} TAG: ${{ steps.version.outputs.tag }}
run: gh release upload "$TAG" dist/release/* --clobber run: |
while IFS= read -r asset; do
case "$asset" in
SketchForge-*|latest.yml|latest-linux.yml|latest-mac.yml)
gh release delete-asset "$TAG" "$asset" --yes
;;
esac
done < <(gh release view "$TAG" --json assets --jq '.assets[].name')
gh release upload "$TAG" dist/release/*
- name: Verify release assets - name: Verify release assets
env: env:
@@ -283,13 +306,21 @@ jobs:
"SketchForge-$VERSION-x64${suffix}.dmg" \ "SketchForge-$VERSION-x64${suffix}.dmg" \
"SketchForge-$VERSION-x64${suffix}.zip" \ "SketchForge-$VERSION-x64${suffix}.zip" \
"SketchForge-$VERSION-arm64${suffix}.dmg" \ "SketchForge-$VERSION-arm64${suffix}.dmg" \
"SketchForge-$VERSION-arm64${suffix}.zip" \ "SketchForge-$VERSION-arm64${suffix}.zip"; do
"latest-mac.yml"; do
grep -Fxq "$expected" <<< "$names" || { grep -Fxq "$expected" <<< "$names" || {
echo "GitHub release is missing $expected" >&2 echo "GitHub release is missing $expected" >&2
exit 1 exit 1
} }
done done
if [[ -z "$suffix" ]]; then
grep -Fxq "latest-mac.yml" <<< "$names" || {
echo "GitHub release is missing latest-mac.yml" >&2
exit 1
}
elif grep -Fxq "latest-mac.yml" <<< "$names"; then
echo "Unsigned macOS builds must not publish latest-mac.yml" >&2
exit 1
fi
- name: Publish release as latest - name: Publish release as latest
env: env:
+1
View File
@@ -34,6 +34,7 @@
"@types/react-dom": "^19.1.5", "@types/react-dom": "^19.1.5",
"electron": "^43.4.0", "electron": "^43.4.0",
"electron-builder": "^26.15.3", "electron-builder": "^26.15.3",
"js-yaml": "^4.3.1",
"typescript": "^5.8.3", "typescript": "^5.8.3",
"vitest": "^4.1.8" "vitest": "^4.1.8"
} }
+1
View File
@@ -61,6 +61,7 @@
"@types/react-dom": "^19.1.5", "@types/react-dom": "^19.1.5",
"electron": "^43.4.0", "electron": "^43.4.0",
"electron-builder": "^26.15.3", "electron-builder": "^26.15.3",
"js-yaml": "^4.3.1",
"typescript": "^5.8.3", "typescript": "^5.8.3",
"vitest": "^4.1.8" "vitest": "^4.1.8"
} }