Skip to content

Commit c7b1604

Browse files
committed
Try to download and unzip assignment zips.
1 parent 0bcffa5 commit c7b1604

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/push.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,54 @@ jobs:
4242
-H "Authorization: Bearer $GITHUB_TOKEN" \
4343
https://api.github.com/repos/cmsc430/assignments/actions/workflows/push.yml/dispatches \
4444
-d '{"ref":"main"}'
45+
- name: Poll for zips
46+
id: poll_workflow
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.PAT_ZIPS_WORKFLOW }}
49+
run: |
50+
MAX_ATTEMPTS=5 # Maximum polling attempts (2 minutes each = 10 minutes)
51+
ATTEMPT=0
52+
STATUS="in_progress"
53+
54+
while [[ "$ATTEMPT" -lt "$MAX_ATTEMPTS" && "$STATUS" != "completed" ]]; do
55+
echo "Polling attempt #$((ATTEMPT + 1))"
56+
ATTEMPT=$((ATTEMPT + 1))
57+
58+
response=$(curl -s \
59+
-H "Accept: application/vnd.github+json" \
60+
-H "Authorization: Bearer $GITHUB_TOKEN" \
61+
"https://api.github.com/repos/cmsc430/assignments/actions/runs?branch=main&status=success&per_page=1")
62+
63+
if [[ "$(echo "$response" | jq '.total_count')" -gt 0 ]]; then
64+
STATUS="completed"
65+
run_id=$(echo "$response" | jq -r '.workflow_runs[0].id')
66+
echo "RUN_ID=$run_id" >> $GITHUB_ENV
67+
else
68+
echo "Workflow not completed yet. Waiting for 2 minutes before next attempt."
69+
sleep 120 # Wait for 2 minutes before polling again
70+
fi
71+
done
72+
73+
if [[ "$STATUS" != "completed" ]]; then
74+
echo "Workflow did not complete in time. Exiting with failure."
75+
exit 1
76+
fi
77+
- name: Download assignment zips
78+
if: success()
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.PAT_ZIPS_WORKFLOW }}
81+
run: |
82+
curl -L \
83+
-H "Accept: application/vnd.github+json" \
84+
-H "Authorization: Bearer $GITHUB_TOKEN" \
85+
https://api.github.com/repos/cmsc430/assignments/actions/runs/${{ env.RUN_ID }}/artifacts \
86+
-o artifacts.zip
87+
- name: Extract assignment zips
88+
if: success()
89+
run: |
90+
unzip artifacts.zip
91+
tar -xvf artifact.tar
92+
mv knock-plus.zip www/main/
4593
- name: Archive www
4694
uses: actions/upload-pages-artifact@v3
4795
with:

0 commit comments

Comments
 (0)