Skip to content

Commit fe62062

Browse files
committed
fix: improve changelog workflow monitoring and dispatch feedback
1 parent 1444054 commit fe62062

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

.github/workflows/prepare-tag.yml

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ jobs:
152152
fi
153153
154154
echo "✅ Successfully dispatched changelog generation for ${{ matrix.name }}"
155+
156+
# Wait a moment for the run to be created and get its URL
157+
echo "⏳ Getting workflow run URL..."
158+
sleep 5
159+
160+
# Get the most recent run URL for this workflow
161+
if run_url=$(gh run list --repo "$target_repo" --workflow "$workflow_id" --limit 1 --json url -q '.[0].url' 2>/dev/null); then
162+
if [ -n "$run_url" ] && [ "$run_url" != "null" ]; then
163+
echo "🔗 View dispatched workflow run: $run_url"
164+
fi
165+
fi
166+
155167
echo "skip_monitoring=false" >> $GITHUB_OUTPUT
156168
echo "workflow_id=$workflow_id" >> $GITHUB_OUTPUT
157169
echo "workflow_name=$workflow_name" >> $GITHUB_OUTPUT
@@ -161,13 +173,13 @@ jobs:
161173
env:
162174
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
163175
run: |
164-
workflow_name="${{ steps.dispatch.outputs.workflow_name }}"
176+
workflow_name="${{ matrix.name }}"
165177
workflow_id="${{ steps.dispatch.outputs.workflow_id }}"
166178
target_repo="codesnippetspro/.github-private"
167179
max_attempts=10
168180
attempt=0
169181
170-
echo "Monitoring workflow: $workflow_name (ID: $workflow_id) in repository: $target_repo"
182+
echo "Monitoring workflow: $workflow_name in repository: $target_repo"
171183
172184
# Check if the repository exists and is accessible
173185
if ! gh repo view "$target_repo" >/dev/null 2>&1; then
@@ -176,54 +188,51 @@ jobs:
176188
exit 0
177189
fi
178190
179-
# Wait a bit for the workflow to start
180-
echo "⏳ Waiting 10 seconds for workflow to start..."
181-
sleep 10
182-
183191
while : ; do
184192
attempt=$((attempt + 1))
185193
186194
# Check if we've exceeded max attempts
187195
if [ $attempt -gt $max_attempts ]; then
188196
echo "::warning::Timeout reached after $max_attempts attempts. Workflow '$workflow_name' monitoring stopped."
189-
echo "::warning::This might be expected if testing locally or if the workflow takes longer than expected."
197+
echo "::warning::This might be expected if testing locally or if the workflow doesn't exist yet."
190198
exit 0
191199
fi
192200
193-
# Get the latest run for this workflow using the workflow ID
194-
echo "🔍 Attempt $attempt/$max_attempts: Checking workflow status..."
201+
# Try to get workflow status by changelog.yml first, then fallback to workflow ID
202+
status=""
203+
conclusion=""
195204
196-
# First check if we can list any runs at all
197-
if ! gh run list --repo "$target_repo" --limit 1 --json status,conclusion,workflowDatabaseId >/dev/null 2>&1; then
198-
echo "::warning::Attempt $attempt/$max_attempts: Cannot access workflow runs in $target_repo. Checking again..."
199-
sleep 10
200-
continue
205+
# First attempt: Try using changelog.yml filename
206+
if status=$(gh run list --workflow changelog.yml --limit 1 --json status -q '.[0].status' --repo "$target_repo" --ref main 2>/dev/null) && [ -n "$status" ]; then
207+
conclusion=$(gh run list --workflow changelog.yml --limit 1 --json conclusion -q '.[0].conclusion' --repo "$target_repo" --ref main 2>/dev/null)
208+
else
209+
# Fallback: Try using workflow ID from previous step
210+
if [ -n "$workflow_id" ]; then
211+
echo "::info::Attempt $attempt/$max_attempts: changelog.yml not found, trying workflow ID $workflow_id"
212+
run_data=$(gh run list --repo "$target_repo" --limit 10 --json status,conclusion,workflowDatabaseId 2>/dev/null | jq -r ".[] | select(.workflowDatabaseId == $workflow_id) | [.status, .conclusion] | @tsv" | head -1)
213+
if [ -n "$run_data" ]; then
214+
status=$(echo "$run_data" | cut -f1)
215+
conclusion=$(echo "$run_data" | cut -f2)
216+
fi
217+
fi
201218
fi
202219
203-
# Try to get the status of the most recent run for our workflow
204-
run_data=$(gh run list --repo "$target_repo" --limit 10 --json status,conclusion,workflowDatabaseId 2>/dev/null | jq -r ".[] | select(.workflowDatabaseId == $workflow_id) | [.status, .conclusion] | @tsv" | head -1)
205-
206-
if [ -z "$run_data" ]; then
207-
echo "⏳ Attempt $attempt/$max_attempts: No runs found for workflow ID $workflow_id yet. Checking again..."
220+
# If we still couldn't get status, continue waiting
221+
if [ -z "$status" ]; then
222+
echo "::warning::Attempt $attempt/$max_attempts: Could not find workflow '$workflow_name' or no runs exist yet. Checking again..."
208223
sleep 10
209224
continue
210225
fi
211226
212-
status=$(echo "$run_data" | cut -f1)
213-
conclusion=$(echo "$run_data" | cut -f2)
214-
215-
echo "📊 Workflow status: $status, conclusion: $conclusion"
216-
217227
if [ "$status" = "completed" ]; then
218-
if [ "$conclusion" != "success" ] && [ "$conclusion" != "null" ]; then
219-
echo "::error::Workflow $workflow_name (ID: $workflow_id) failed with conclusion: $conclusion"
228+
if [ "$conclusion" != "success" ]; then
229+
echo "::error::Workflow $workflow_name failed with conclusion: $conclusion"
220230
exit 1
221231
fi
222-
echo "✅ Workflow $workflow_name (ID: $workflow_id) completed successfully"
232+
echo "✅ Workflow $workflow_name completed successfully"
223233
break
224234
fi
225235
226-
echo "⏳ Attempt $attempt/$max_attempts: Workflow $workflow_name (ID: $workflow_id) is still running (status: $status). Waiting..."
236+
echo "⏳ Attempt $attempt/$max_attempts: Workflow $workflow_name is still running (status: $status). Waiting..."
227237
sleep 10
228238
done
229-

0 commit comments

Comments
 (0)