├── .github └── workflows │ ├── Dockerfile │ ├── cache_docker.yml │ └── postaction.yml └── README.md /.github/workflows/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ocaml/opam:ubuntu-lts-ocaml-4.14 2 | 3 | USER root 4 | RUN dpkg --add-architecture i386 && \ 5 | apt-get update --fix-missing -y && \ 6 | apt-get install -y software-properties-common gcc-multilib make m4 pkg-config libpcre2-dev && \ 7 | rm -rf /var/lib/apt/lists/* 8 | 9 | USER opam 10 | RUN opam init --disable-sandboxing -y && \ 11 | eval $(opam env) && \ 12 | opam pin add Lama https://github.com/PLTools/Lama.git\#1.30 --no-action && \ 13 | opam install -y Lama 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # compilers-supplementary 2 | 3 | A supplementary repository for the course on compilers. 4 | 5 | **How to submit tasks**: 6 | 7 | * fork the repo 8 | * implement the corresponding task (branches `T01`, `T02`, ...) 9 | * open pull-request with title `[] ` to this repo to the branch with the corresponding task where 10 | * ` ::= SPBGU | NUP | CUB | HSE | |ITMO` 11 | * `` --- assignment number (the first three symbols of the corresponding branch name) 12 | * NB: your pr has to contain changes to files `*.lama` files from folder `src` 13 | * NB: be sure that all checks have passed 14 | 15 | All lecture notes are located in branch [lecture-notes](https://github.com/danyaberezun/compilers-supplementary/tree/lecture-notes/). 16 | 17 | [This table](https://docs.google.com/spreadsheets/d/1Cs9XFVvEuXq3CaIk3YT9YF5EXpbkU0MjO4g-ajPKps8/edit?usp=sharing) contains results and deadlines in the corresponding sheets. 18 | -------------------------------------------------------------------------------- /.github/workflows/cache_docker.yml: -------------------------------------------------------------------------------- 1 | name: Cache Lama Docker Image 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "0 0 * * *" 7 | push: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | check-cache: 13 | runs-on: ubuntu-latest 14 | outputs: 15 | cache_found: ${{ steps.step1.outputs.noCache }} 16 | steps: 17 | - name: Retrieve Docker image 18 | uses: actions/cache/restore@v3 19 | with: 20 | path: lama-1-30.tar 21 | key: lama-1-30-${{ runner.os }}- 22 | 23 | - name: Check if Lama-docker was restored from cache 24 | id: step1 25 | run: | 26 | if [ -f lama-1-30.tar ]; then 27 | echo "Lama's docker image is restored successfully. Exiting..." 28 | echo "noCache=true" >> $GITHUB_OUTPUT 29 | else 30 | echo "Cache not found. Building.." 31 | echo "noCache=false" >> $GITHUB_OUTPUT 32 | fi 33 | 34 | build-image: 35 | needs: [check-cache] 36 | if: needs.check-cache.outputs.cache_found != 'true' 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout repository 40 | uses: actions/checkout@v3 41 | - name: Set up Docker Buildx 42 | uses: docker/setup-buildx-action@v3 43 | 44 | - name: Build Docker image 45 | uses: docker/build-push-action@v5 46 | with: 47 | context: . 48 | file: ./.github/workflows/Dockerfile 49 | tags: berezun/lama-image:latest 50 | outputs: type=docker,dest=lama-1-30.tar 51 | 52 | - name: Cache Docker Lama file 53 | id: cache-file 54 | uses: actions/cache/save@v3 55 | with: 56 | path: lama-1-30.tar 57 | key: lama-1-30-${{ runner.os }}- 58 | restore-keys: | 59 | lama-1-30-${{ runner.os }}- 60 | -------------------------------------------------------------------------------- /.github/workflows/postaction.yml: -------------------------------------------------------------------------------- 1 | name: PostAction 2 | 3 | on: 4 | workflow_run: 5 | workflows: ["CheckPullRequest"] 6 | types: 7 | - completed 8 | 9 | jobs: 10 | job2: 11 | if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} 12 | runs-on: ubuntu-latest 13 | outputs: 14 | output_id_number: ${{ steps.step1.outputs.id }} 15 | update_is_needed: ${{ steps.step1.outputs.update_is_needed }} 16 | steps: 17 | - name: 'Download artifact' 18 | uses: actions/github-script@v6 19 | with: 20 | script: | 21 | console.log(${{ github.event.workflow_run.id }}); 22 | var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ 23 | owner: context.repo.owner, 24 | repo: context.repo.repo, 25 | run_id: ${{ github.event.workflow_run.id }}, 26 | }); 27 | var matchArtifact = artifacts.data.artifacts.filter((artifact) => { 28 | return artifact.name == "share_info"; 29 | })[0]; 30 | var download = await github.rest.actions.downloadArtifact({ 31 | owner: context.repo.owner, 32 | repo: context.repo.repo, 33 | artifact_id: matchArtifact.id, 34 | archive_format: 'zip', 35 | }); 36 | var fs = require('fs'); 37 | fs.writeFileSync('${{ github.workspace }}/share_info.zip', Buffer.from(download.data)); 38 | 39 | - run: unzip share_info.zip 40 | - run: | 41 | echo "university=$(cat university.txt)" >> $GITHUB_ENV 42 | echo "assignment=$(cat assignment_number.txt)" >> $GITHUB_ENV 43 | echo "login=$(cat gitid.txt)" >> $GITHUB_ENV 44 | echo "base=$(cat base.txt)" >> $GITHUB_ENV 45 | - id: 'get_deadlines_worksheet' 46 | uses: jroehl/gsheet.action@v2.1.1 47 | with: 48 | spreadsheetId: ${{secrets.SPREADSHEET_ID}} 49 | commands: | # list of commands, specified as a valid JSON string 50 | [ 51 | { "command": "getData", "args": { "worksheetTitle": "Deadlines", "minCol": 1, "maxCol": 20 } } 52 | ] 53 | env: 54 | GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }} 55 | GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }} 56 | - id: check-deadline 57 | name: check-deadline 58 | env: 59 | RESULTS: ${{ steps.get_deadlines_worksheet.outputs.results }} 60 | run: | 61 | cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData") 62 | assignment=${{ env.assignment }} 63 | university="\"${{ env.university }}\"" 64 | # Find Deadline in the Google Sheet 65 | row=0 66 | for j in {1..10} 67 | do 68 | t=$(echo "${cmd}" | jq ".[$j][0]") 69 | if [ $t = $university ]; then 70 | echo "university FOUND: $j" 71 | row=$j 72 | echo $row 73 | break 74 | fi 75 | done 76 | if [ $row -eq 0 ]; then 77 | echo "ERROR: Deadline for $university not found!" 78 | exit 1 79 | fi 80 | deadline=$(echo "${cmd}" | jq ".[$row][${assignment}]") 81 | echo "Deadline for $university for assignment number $assignment is $deadline" 82 | # Get submission time 83 | submission_time="\"${{ github.event.workflow_run.head_commit.timestamp }}\"" 84 | # Check Deadline 85 | echo $submission_time 86 | echo $deadline 87 | if [[ $submission_time > $deadline ]]; then 88 | echo "result=0.01" >> $GITHUB_ENV 89 | echo "FIASCO: The deadline has expired" 90 | else 91 | echo "result=1" >> $GITHUB_ENV 92 | echo "OK: you are on time!" 93 | fi 94 | 95 | # - name: Check out code 96 | # uses: actions/checkout@v2 97 | # - name: Comment PR 98 | # uses: thollander/actions-comment-pull-request@v2 99 | # with: 100 | # message: | 101 | # All checks have successfully passed! 102 | # The assignment is submitted on time. 103 | # reactions: rocket 104 | 105 | - id: 'get_worksheet' 106 | uses: jroehl/gsheet.action@v2.1.1 107 | with: 108 | spreadsheetId: ${{secrets.SPREADSHEET_ID}} 109 | commands: | # list of commands, specified as a valid JSON string 110 | [ 111 | { "command": "getData", "args": { "worksheetTitle": "Sheet1", "minCol": 1, "maxCol": 30 } } 112 | ] 113 | env: 114 | GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }} 115 | GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }} 116 | - id: step1 117 | name: dump results 118 | env: 119 | # the output of the action can be found in ${{ steps.update_worksheet.outputs.results }} 120 | RESULTS: ${{ steps.get_worksheet.outputs.results }} 121 | run: | 122 | # the result command will be stored in environment variable $id 123 | cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData") 124 | # echo "cmd = $cmd \n" 125 | # echo "RESULTS = ${RESULTS} \n" 126 | branch=${{ env.base }} 127 | assignment=${{ env.assignment }} 128 | gitid="\"${{ env.login }}\"" 129 | lastrow=0 130 | for i in {1..100} 131 | do 132 | t=$(echo "${cmd}" | jq ".[$i][0]") 133 | # echo "$t" 134 | # echo "$gitid" 135 | if [ "$t" = "$gitid" ]; then 136 | echo "FOUND: t=$t gitid=$gitid i=$i" 137 | current_result=$(echo "${cmd}" | jq ".[$i][$((assignment*2))]") 138 | echo "current_result=$current_result" 139 | if [ -n "$current_result" ] && [ "$current_result" != "\"\"" ] && [ "$current_result" != "\"0.01\"" ]; then 140 | echo "Current result in the GSHEET current_result=$current_result" 141 | echo "There is not need for update; aborting" 142 | echo "update_is_needed=false" >> $GITHUB_OUTPUT 143 | exit 0 144 | fi 145 | j="[{ \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [["\"$result\"", "\"$result\""]], \"minCol\": $((assignment*2)), \"minRow\": $((i+1)) }} ]" 146 | echo "update command: $j \n" 147 | echo "id=$j" >> $GITHUB_OUTPUT 148 | break 149 | else 150 | echo "Strings are not equal: t=$t gitid=$gitid" 151 | if [ -z $t ] || [ -z "$t" ] || [ $t = null ] || [ $t = "" ] || [ $t = "\"\"" ] || [ "$t" = "\"\"" ] || [ "$t" = "" ]; then 152 | echo "t=$t is null; I.e. $gitid is not found in the sheet" 153 | break 154 | fi 155 | lastrow=$i 156 | echo "lastrow -> $lastrow" 157 | fi 158 | done 159 | # if the gitid is not found in the sheet 160 | # then write in var j command that adds the gitid to the sheet 161 | if [[ ! -n "$j" ]] 162 | then 163 | j="[{ \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [[ "$gitid" ]], \"minCol\": 1, \"minRow\": $((lastrow+2)) }}, { \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [["\"$result\"", "\"$result\""]], \"minCol\": $((assignment*2)), \"minRow\": $((lastrow+2)) }} ]" 164 | echo "update command: $j \n" 165 | echo "id=$j" >> $GITHUB_OUTPUT 166 | fi 167 | echo "update_is_needed=true" >> $GITHUB_OUTPUT 168 | 169 | job3: 170 | runs-on: ubuntu-latest 171 | needs: [job2] 172 | if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && needs.job2.outputs.update_is_needed == 'true' }} 173 | steps: 174 | - id: 'update_worksheet' 175 | uses: jroehl/gsheet.action@v2.1.1 176 | with: 177 | spreadsheetId: ${{secrets.SPREADSHEET_ID}} 178 | commands: ${{needs.job2.outputs.output_id_number}} 179 | env: 180 | GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }} 181 | GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }} 182 | --------------------------------------------------------------------------------