Try to download and unzip assignment zips. #610
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | ||
- push | ||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@main | ||
- name: Install dependencies | ||
run: | | ||
curl -Ls https://github.com/jgm/pandoc/releases/download/2.11.2/pandoc-2.11.2-1-amd64.deb -o pandoc.deb | ||
sudo dpkg -i pandoc.deb | ||
sudo apt-get install nasm | ||
sudo apt-get install fonts-stix | ||
sudo apt-get install libunistring-dev | ||
- name: Install Racket | ||
uses: Bogdanp/[email protected] | ||
with: | ||
architecture: 'x64' | ||
distribution: 'full' | ||
variant: 'CS' | ||
version: '8.14' | ||
- name: Install a86 and langs | ||
run: | | ||
git clone https://github.com/cmsc430/a86.git | ||
git clone https://github.com/cmsc430/langs.git | ||
raco pkg install --auto a86/ | ||
raco pkg install --auto langs/ | ||
- name: Build and test | ||
run: | | ||
export LINK_DIR=/usr/lib/x86_64-linux-gnu | ||
# raco pkg install --auto www/ | ||
raco make www/main.scrbl | ||
make -C www main | ||
- name: Generate assignment zips | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_ZIPS_WORKFLOW }} | ||
run: | | ||
curl -X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/cmsc430/assignments/actions/workflows/push.yml/dispatches \ | ||
-d '{"ref":"main"}' | ||
- name: Poll for zips | ||
id: poll_workflow | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_ZIPS_WORKFLOW }} | ||
run: | | ||
MAX_ATTEMPTS=5 # Maximum polling attempts (2 minutes each = 10 minutes) | ||
ATTEMPT=0 | ||
STATUS="in_progress" | ||
while [[ "$ATTEMPT" -lt "$MAX_ATTEMPTS" && "$STATUS" != "completed" ]]; do | ||
echo "Polling attempt #$((ATTEMPT + 1))" | ||
ATTEMPT=$((ATTEMPT + 1)) | ||
response=$(curl -s \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
"https://api.github.com/repos/cmsc430/assignments/actions/runs?branch=main&status=success&per_page=1") | ||
if [[ "$(echo "$response" | jq '.total_count')" -gt 0 ]]; then | ||
STATUS="completed" | ||
run_id=$(echo "$response" | jq -r '.workflow_runs[0].id') | ||
echo "RUN_ID=$run_id" >> $GITHUB_ENV | ||
else | ||
echo "Workflow not completed yet. Waiting for 2 minutes before next attempt." | ||
sleep 120 # Wait for 2 minutes before polling again | ||
fi | ||
done | ||
if [[ "$STATUS" != "completed" ]]; then | ||
echo "Workflow did not complete in time. Exiting with failure." | ||
exit 1 | ||
fi | ||
- name: Download assignment zips | ||
if: success() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_ZIPS_WORKFLOW }} | ||
run: | | ||
curl -L \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/cmsc430/assignments/actions/runs/${{ env.RUN_ID }}/artifacts \ | ||
-o artifacts.zip | ||
- name: Extract assignment zips | ||
if: success() | ||
run: | | ||
unzip artifacts.zip | ||
tar -xvf artifact.tar | ||
mv knock-plus.zip www/main/ | ||
- name: Archive www | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
name: github-pages | ||
path: www/main | ||
deploy: | ||
needs: build-and-test | ||
permissions: | ||
pages: write | ||
id-token: write | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
if: github.ref == 'refs/heads/main' | ||
steps: | ||
- name: Deploy to GitHub pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |