Skip to content

Commit e88f516

Browse files
committed
refactor: introduce reuse
1 parent 6902383 commit e88f516

File tree

2 files changed

+31
-62
lines changed

2 files changed

+31
-62
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ workflows:
11271127
- '/release.*/'
11281128

11291129
- trigger-building-distribution-channels:
1130-
name: Trigger building snyk-images (preview)
1130+
name: Trigger building distribution channels (preview)
11311131
context:
11321132
- team-hammerhead-common-deploy-tokens
11331133
- devex_cli_docker_hub
@@ -1140,7 +1140,7 @@ workflows:
11401140
- main
11411141

11421142
- trigger-building-distribution-channels:
1143-
name: Trigger building snyk-images (rc)
1143+
name: Trigger building distribution channels (rc)
11441144
context:
11451145
- team-hammerhead-common-deploy-tokens
11461146
- devex_cli_docker_hub
@@ -1153,7 +1153,7 @@ workflows:
11531153
- '/release.*/'
11541154

11551155
- trigger-building-distribution-channels:
1156-
name: Trigger building snyk-images (stable)
1156+
name: Trigger building distribution channels (stable)
11571157
context:
11581158
- team-hammerhead-common-deploy-tokens
11591159
- devex_cli_docker_hub

release-scripts/upload-artifacts.sh

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -119,81 +119,50 @@ upload_npm() {
119119
fi
120120
}
121121

122-
trigger_build_snyk_images() {
123-
echo "Triggering build-and-publish workflow at snyk-images..."
124-
echo "Version: $VERSION_TAG"
125-
echo "Release Channel: $RELEASE_CHANNEL"
126-
response_file=$TMPDIR/trigger_build_snyk_images_response.txt
127-
RESPONSE=$(curl -L \
128-
-X POST \
129-
-H "Accept: application/vnd.github+json" \
130-
-H "Authorization: Bearer $HAMMERHEAD_GITHUB_PAT" \
131-
-H "X-GitHub-Api-Version: 2022-11-28" \
132-
https://api.github.com/repos/snyk/snyk-images/dispatches \
133-
-d "{\"event_type\":\"build_and_push_images\", \"client_payload\": {\"version\": \"$VERSION_TAG\", \"release_channel\": \"$RELEASE_CHANNEL\"}}" \
134-
-w "%{http_code}" \
135-
-s \
136-
-o "$response_file")
137-
if [ "$RESPONSE" -eq 204 ]; then
138-
echo "Successfully triggered build-and-publish workflow at snyk-images."
139-
else
140-
echo "Failed to trigger build-and-publish workflow at snyk-images."
141-
echo "Response status code: $RESPONSE"
142-
echo "Details:"
143-
cat $response_file
144-
exit 1
122+
# Trigger event for a given repository
123+
# Failure mode is to log and continue as these steps
124+
# are non blocking to a release.
125+
# Recovery is manual trigger on the target repository.
126+
# Arguments:
127+
# repository: The GitHub repository name (e.g., "scoop-snyk
128+
# event_type: The event type to trigger (default: "build_and_release")
129+
trigger_repository_event() {
130+
repository=$1
131+
event_type=$2
132+
133+
if [ -z "$1" ]; then
134+
echo "Error: Missing required argument: repository"
135+
return 0
145136
fi
146-
}
147137

148-
trigger_build_scoop_snyk() {
149-
echo "Triggering build-and-release workflow at snyk-scoop..."
150-
echo "Version: $VERSION_TAG"
151-
echo "Release Channel: $RELEASE_CHANNEL"
152-
response_file=$TMPDIR/trigger_build_snyk_scoop.txt
153-
RESPONSE=$(curl -L \
154-
-X POST \
155-
-H "Accept: application/vnd.github+json" \
156-
-H "Authorization: Bearer $HAMMERHEAD_GITHUB_PAT" \
157-
-H "X-GitHub-Api-Version: 2022-11-28" \
158-
https://api.github.com/repos/snyk/scoop-snyk/dispatches \
159-
-d "{\"event_type\":\"build_and_release\", \"client_payload\": {\"version\": \"$VERSION_TAG\", \"release_channel\": \"$RELEASE_CHANNEL\"}}" \
160-
-w "%{http_code}" \
161-
-s \
162-
-o "$response_file")
163-
if [ "$RESPONSE" -eq 204 ]; then
164-
echo "Successfully triggered build-and-release workflow at snyk-scoop."
165-
else
166-
echo "Failed to trigger build-and-release workflow at snyk-scoop."
167-
echo "Response status code: $RESPONSE"
168-
echo "Details:"
169-
cat $response_file
170-
exit 1
138+
if [ -z "$2" ]; then
139+
echo "Error: Missing required argument: event_type"
140+
return 0
171141
fi
172-
}
173142

174-
trigger_build_homebrew() {
175-
echo "Triggering build-and-release workflow at homebrew-tap..."
143+
144+
echo "Triggering $event_type event on $repository..."
176145
echo "Version: $VERSION_TAG"
177146
echo "Release Channel: $RELEASE_CHANNEL"
178-
response_file=$TMPDIR/trigger_build_homebrew.txt
147+
response_file=$TMPDIR/trigger_build_$repository.txt
179148
RESPONSE=$(curl -L \
180149
-X POST \
181150
-H "Accept: application/vnd.github+json" \
182151
-H "Authorization: Bearer $HAMMERHEAD_GITHUB_PAT" \
183152
-H "X-GitHub-Api-Version: 2022-11-28" \
184-
https://api.github.com/repos/snyk/homebrew-tap/dispatches \
185-
-d "{\"event_type\":\"build_and_release\", \"client_payload\": {\"version\": \"$VERSION_TAG\", \"release_channel\": \"$RELEASE_CHANNEL\"}}" \
153+
https://api.github.com/repos/snyk/$repository/dispatches \
154+
-d "{\"event_type\":\"$event_type\", \"client_payload\": {\"version\": \"$VERSION_TAG\", \"release_channel\": \"$RELEASE_CHANNEL\"}}" \
186155
-w "%{http_code}" \
187156
-s \
188157
-o "$response_file")
189158
if [ "$RESPONSE" -eq 204 ]; then
190-
echo "Successfully triggered build-and-release workflow at homebrew-tap."
159+
echo "Successfully triggered $event_type event on $repository."
191160
else
192-
echo "Failed to trigger build-and-release workflow at homebrew-tap."
161+
echo "Failed to trigger $event_type event on $repository."
193162
echo "Response status code: $RESPONSE"
194163
echo "Details:"
195164
cat $response_file
196-
exit 1
165+
return 0
197166
fi
198167
}
199168

@@ -315,9 +284,9 @@ for arg in "${@}"; do
315284

316285
# Trigger builds across distirbution channel repositories
317286
elif [ "${arg}" == "trigger-distribution-channels" ]; then
318-
trigger_build_snyk_images
319-
trigger_build_scoop_snyk
320-
trigger_build_homebrew
287+
trigger_repository_event "snyk-images" "build_and_push_images"
288+
trigger_repository_event "scoop-snyk" "build_and_release"
289+
trigger_repository_event "homebrew-tap" "build_and_release"
321290

322291

323292
# Trigger building DXT in agentic-integration-wrappers repository

0 commit comments

Comments
 (0)