-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (171 loc) · 7.17 KB
/
Copy pathfinalize-notarization.yml
File metadata and controls
196 lines (171 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: Finalize Notarization
on:
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:
permissions:
actions: write
contents: write
concurrency:
group: finalize-notarization
cancel-in-progress: false
jobs:
poll:
runs-on: macos-15
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
COMUX_NOTARY_APPLE_ID: ${{ secrets.APPLE_NOTARY_APPLE_ID }}
COMUX_NOTARY_TEAM_ID: ${{ secrets.APPLE_NOTARY_TEAM_ID }}
COMUX_NOTARY_PASSWORD: ${{ secrets.APPLE_NOTARY_PASSWORD }}
steps:
- name: Poll pending notarizations
shell: bash
run: |
set -euo pipefail
artifacts_path="$RUNNER_TEMP/comux-notarization-artifacts.tsv"
artifacts_loaded=0
for attempt in 1 2 3; do
if gh api --paginate \
"/repos/${GITHUB_REPOSITORY}/actions/artifacts?per_page=100" \
--jq '.artifacts[] | select(.expired == false and (.name | startswith("comux-notarization-"))) | [.id, .name, .workflow_run.id] | @tsv' \
> "$artifacts_path"; then
artifacts_loaded=1
break
fi
echo "::warning::Could not list notarization artifacts (attempt $attempt of 3)."
if [[ "$attempt" -lt 3 ]]; then
sleep "$((attempt * 4))"
fi
done
if [[ "$artifacts_loaded" -ne 1 ]]; then
echo "::warning::GitHub is unavailable; skipping this notarization poll."
exit 0
fi
if [[ ! -s "$artifacts_path" ]]; then
echo "No pending Comux notarization artifacts found."
exit 0
fi
failures=0
dispatched=0
has_asset() {
local asset_name="$1"
local assets_path="$2"
grep -Fx "$asset_name" "$assets_path" >/dev/null
}
while IFS=$'\t' read -r artifact_id artifact_name artifact_run_id; do
if [[ -z "$artifact_id" || -z "$artifact_name" || -z "$artifact_run_id" ]]; then
continue
fi
artifact_dir="$RUNNER_TEMP/${artifact_name}-${artifact_run_id}"
rm -rf "$artifact_dir"
mkdir -p "$artifact_dir"
echo "Inspecting $artifact_name from run $artifact_run_id."
if ! gh run download "$artifact_run_id" \
--repo "$GITHUB_REPOSITORY" \
--name "$artifact_name" \
--dir "$artifact_dir"; then
echo "::warning::Could not download $artifact_name from run $artifact_run_id."
failures=1
continue
fi
state_path="$artifact_dir/comux-notarization.txt"
if [[ ! -f "$state_path" ]]; then
echo "::warning::Missing notarization state file in $artifact_name."
failures=1
continue
fi
version=""
release_repository="$GITHUB_REPOSITORY"
submission_id=""
source_run_id="$artifact_run_id"
while IFS='=' read -r key value; do
case "$key" in
VERSION)
version="$value"
;;
REPOSITORY)
release_repository="$value"
;;
SUBMISSION_ID)
submission_id="$value"
;;
RUN_ID)
source_run_id="$value"
;;
esac
done < "$state_path"
if [[ -z "$version" || -z "$submission_id" || -z "$source_run_id" ]]; then
echo "::warning::Incomplete notarization state in $artifact_name."
failures=1
continue
fi
normalized_version="${version#v}"
tag="v${normalized_version}"
archive_name="comux-${normalized_version}.zip"
cask_name="comux.rb"
release_assets_path="$RUNNER_TEMP/${artifact_name}-${artifact_run_id}-release-assets.txt"
if ! gh release view "$tag" \
--repo "$release_repository" \
--json assets \
--jq '.assets[].name' > "$release_assets_path"; then
echo "::warning::Release $tag does not exist in $release_repository. Create the draft release before finalization."
failures=1
continue
fi
if has_asset "$archive_name" "$release_assets_path" && has_asset "$cask_name" "$release_assets_path"; then
echo "Release $tag is complete; retiring $artifact_name."
if ! gh api \
--method DELETE \
"/repos/${GITHUB_REPOSITORY}/actions/artifacts/${artifact_id}"; then
echo "::warning::Could not retire completed notarization artifact $artifact_name."
fi
continue
fi
if [[ -z "${COMUX_NOTARY_APPLE_ID:-}" || -z "${COMUX_NOTARY_TEAM_ID:-}" || -z "${COMUX_NOTARY_PASSWORD:-}" ]]; then
echo "::error::Apple notarization credentials are required to poll pending submission $submission_id for $tag."
failures=1
continue
fi
info_path="$RUNNER_TEMP/${artifact_name}-${artifact_run_id}-notary-info.json"
if ! xcrun notarytool info "$submission_id" \
--apple-id "$COMUX_NOTARY_APPLE_ID" \
--team-id "$COMUX_NOTARY_TEAM_ID" \
--password "$COMUX_NOTARY_PASSWORD" \
--no-progress \
--output-format json > "$info_path"; then
echo "::warning::Could not fetch Apple notarization status for $submission_id."
failures=1
continue
fi
status="$(plutil -extract status raw -o - "$info_path")"
case "$status" in
Accepted)
echo "Notarization accepted for $tag; dispatching release finalization."
gh workflow run release.yml \
--repo "$GITHUB_REPOSITORY" \
--ref "$DEFAULT_BRANCH" \
-f "version=$normalized_version" \
-f "repository=$release_repository" \
-f "notarization_submission_id=$submission_id" \
-f "notarization_run_id=$source_run_id"
dispatched=$((dispatched + 1))
;;
Invalid|Rejected)
log_path="$RUNNER_TEMP/${artifact_name}-${artifact_run_id}-notary-log.json"
xcrun notarytool log "$submission_id" "$log_path" \
--apple-id "$COMUX_NOTARY_APPLE_ID" \
--team-id "$COMUX_NOTARY_TEAM_ID" \
--password "$COMUX_NOTARY_PASSWORD" || true
echo "::error::Notarization $submission_id for $tag finished with status $status. Log: $log_path"
failures=1
;;
*)
echo "Notarization $submission_id for $tag is $status; will check again later."
;;
esac
done < "$artifacts_path"
echo "Dispatched $dispatched release finalization run(s)."
if [[ "$failures" -ne 0 ]]; then
exit 1
fi