|
| 1 | +name: Check task |
| 2 | + |
| 3 | +# Controls when the workflow will run |
| 4 | +on: |
| 5 | + pull_request_target: |
| 6 | + types: |
| 7 | + - opened |
| 8 | + - reopened # good to check canvas again to see if eligibility changed |
| 9 | + - edited # we need to check the new description against the README |
| 10 | + - synchronize |
| 11 | + branches: |
| 12 | + - 2025 |
| 13 | + paths: |
| 14 | + - contributions/** |
| 15 | + |
| 16 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 17 | +jobs: |
| 18 | + check-affected-files: |
| 19 | + name: Check affected files |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + affected_file: ${{ steps.check-affected-files.outputs.affected_file }} |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v2 |
| 25 | + with: |
| 26 | + ref: ${{ github.event.pull_request.head.sha }} |
| 27 | + |
| 28 | + - name: Get changed files |
| 29 | + id: changed-files |
| 30 | + uses: tj-actions/changed-files@v45 |
| 31 | + |
| 32 | + - name: Check affected files |
| 33 | + id: check-affected-files |
| 34 | + env: |
| 35 | + # get all affected files (created, modified, deleted, etc.) |
| 36 | + FILES: ${{ steps.changed-files.outputs.all_changed_and_modified_files }} |
| 37 | + FILES_COUNT: ${{ steps.changed-files.outputs.all_changed_and_modified_files_count }} |
| 38 | + run: | |
| 39 | + for file in "$FILES"; do |
| 40 | + echo "Info: $file was changed" |
| 41 | + done |
| 42 | + if [ "$FILES_COUNT" -ne 1 ]; then |
| 43 | + echo "Error: More than one file affected ($FILES_COUNT)" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + if [[ "$FILES" =~ ^contributions\/(executable-tutorial|feedback|open-source)\/[^\/]+\/README\.md$ ]]; then |
| 47 | + echo "Info: Matches async task" |
| 48 | + elif [[ "$FILES" =~ ^contributions\/(demo|presentation|scientific-paper)\/week[2-7]\/[^\/]+\/README\.md$ ]]; then |
| 49 | + echo "Info: Matches sync task" |
| 50 | + else |
| 51 | + echo "Error: File in wrong directory ($FILES)" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | +
|
| 55 | + echo "affected_file=$FILES" >> "$GITHUB_OUTPUT" |
| 56 | +
|
| 57 | + check-pr-description: |
| 58 | + name: Check whether Pull Request description matches affected file |
| 59 | + needs: check-affected-files |
| 60 | + runs-on: ubuntu-latest |
| 61 | + steps: |
| 62 | + - uses: actions/checkout@v2 |
| 63 | + with: |
| 64 | + ref: ${{ github.event.pull_request.head.sha }} |
| 65 | + |
| 66 | + - name: Install wdiff |
| 67 | + # we use wdiff (word-diff) instead of plain diff (line-based) to ensure |
| 68 | + # that we only enforce *content* to be the same rather than specific |
| 69 | + # file formatting that would otherwise be ignored when the markdown is |
| 70 | + # rendered. e.g., wdiff allows the README to break lines at col 80 for |
| 71 | + # readability while still having the PR description without mid-sentence |
| 72 | + # breaks (since GitHub descriptions don't support them) |
| 73 | + run: | |
| 74 | + sudo apt update |
| 75 | + sudo apt install -y wdiff |
| 76 | +
|
| 77 | + - name: Check PR description |
| 78 | + env: |
| 79 | + AFFECTED_FILE: ${{ needs.check-affected-files.outputs.affected_file }} |
| 80 | + PR_BODY: ${{ github.event.pull_request.body }} |
| 81 | + run: | |
| 82 | + BODY_FILE="$(mktemp)" |
| 83 | + echo "$PR_BODY" > $BODY_FILE |
| 84 | + if wdiff "$AFFECTED_FILE" "$BODY_FILE"; then |
| 85 | + echo "Info: PR description matches affected file" |
| 86 | + else |
| 87 | + echo "Error: PR description does not match affected file!" |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | +
|
| 91 | + check-canvas: |
| 92 | + name: Check proposal is compatible with previous student task registrations |
| 93 | + |
| 94 | + # The type of runner that the job will run on |
| 95 | + runs-on: ubuntu-latest |
| 96 | + |
| 97 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 98 | + steps: |
| 99 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 100 | + - uses: actions/checkout@v2 |
| 101 | + with: |
| 102 | + ref: ${{ github.event.pull_request.head.sha }} |
| 103 | + |
| 104 | + - name: 'Get tools' |
| 105 | + uses: actions/checkout@v2.3.4 |
| 106 | + with: |
| 107 | + repository: KTH/github-canvas-integration-devops |
| 108 | + ref: main |
| 109 | + path: canvas-code |
| 110 | + |
| 111 | + # Setup Python |
| 112 | + - name: Setup Python |
| 113 | + uses: actions/setup-python@v2.2.1 |
| 114 | + with: |
| 115 | + python-version: '3.x' |
| 116 | + |
| 117 | + - name: Install dependencies |
| 118 | + run: | |
| 119 | + python -m pip install --upgrade pip |
| 120 | + if [ -f ./canvas-code/requirements.txt ]; then pip install -r ./canvas-code/requirements.txt; fi |
| 121 | + # Runs a single command using the runners shell |
| 122 | + - name: Update grading in canvas |
| 123 | + env: |
| 124 | + CANVAS_TOKEN: ${{ secrets.CANVAS_TOKEN }} |
| 125 | + CANVAS_COURSE_ID: ${{ secrets.CANVAS_COURSE_ID }} |
| 126 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 127 | + GH_REPO_FULLNAME: ${{ secrets.GH_REPO_FULLNAME }} |
| 128 | + run: | |
| 129 | + export PYTHONPATH="$PWD/canvas-code/utils" |
| 130 | + python ./canvas-code/update_task.py --mode check --pr ${{github.event.number}} |
0 commit comments