Reset Course Data #1
This file contains hidden or 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
| name: Reset Course Data | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| course_id: | |
| description: "Course ID(s) to reset, comma-separated (e.g. 30004,30005)" | |
| required: true | |
| type: string | |
| sub_title: | |
| description: "Lecture title(s) to delete, comma-separated (leave empty + check 'all' to delete all)" | |
| required: false | |
| type: string | |
| all: | |
| description: "Delete ALL lectures for the specified courses" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| reset: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Fetch database from data branch | |
| run: | | |
| mkdir -p data | |
| curl -fL -o data/icourse.db.enc.tmp \ | |
| "https://raw.githubusercontent.com/${{ github.repository }}/data/data/icourse.db.enc" \ | |
| || echo "Fetch from data branch failed." | |
| if [ -f data/icourse.db.enc.tmp ]; then | |
| mv data/icourse.db.enc.tmp data/icourse.db.enc | |
| echo "Database loaded from data branch." | |
| else | |
| echo "::error::No database found on data branch." | |
| exit 1 | |
| fi | |
| - name: Decrypt database | |
| env: | |
| DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }} | |
| run: | | |
| openssl enc -aes-256-cbc -d -pbkdf2 \ | |
| -in data/icourse.db.enc -out data/icourse.db \ | |
| -pass env:DB_KEY | |
| echo "Database decrypted." | |
| - name: Reset course data | |
| run: | | |
| ARGS="--course-id '${{ inputs.course_id }}'" | |
| if [ "${{ inputs.all }}" = "true" ]; then | |
| ARGS="$ARGS --all" | |
| elif [ -n "${{ inputs.sub_title }}" ]; then | |
| ARGS="$ARGS --sub-title '${{ inputs.sub_title }}'" | |
| fi | |
| eval python scripts/reset_course_data.py $ARGS | |
| - name: Deploy updated database to data branch | |
| env: | |
| DB_KEY: ${{ secrets.STUID }}${{ secrets.UISPSW }}${{ secrets.DASHSCOPE_API_KEY }}${{ secrets.SMTP_PASSWORD }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| openssl enc -aes-256-cbc -salt -pbkdf2 \ | |
| -in data/icourse.db -out data/icourse.db.enc \ | |
| -pass env:DB_KEY | |
| mkdir -p /tmp/db_deploy/data | |
| cp data/icourse.db.enc /tmp/db_deploy/data/ | |
| cd /tmp/db_deploy | |
| git init | |
| git checkout -b data | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add data/icourse.db.enc | |
| git commit -m "chore: reset course data (course_id=${{ inputs.course_id }})" | |
| git push --force "https://${{ github.actor }}:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" data |