#acl Known:write,read,delete,admin,revert All:read ### acl Known:read,write,admin,delete,revert = Gitlab to Canvas syncing = For a working example check out the [[https://gitlab.control.lth.se/regler/FRTF10|FRTF10-repo]] where as soon as any changes in pdfs are pushed to the `to_canvas` folder on the master branch they are uploaded to the `from_gitlab` folder on the [[https://canvas.education.lu.se/courses/1342/files/folder/from_gitlab|canvas page]]. == Gitlab CI == Gitlab CI is run through a file called `.gitlab-ci.yml` in the root folder of the repository. This file can setup the environment we need to run certain scripts, define how and what scripts should be run and define in what cases it should be run. For our example we use [[https://gitlab.control.lth.se/regler/FRTF10/blob/master/.gitlab-ci.yml|this]] file {{{#!highlight yaml image: "python:3.7" before_script: - python3 -m pip install canvasapi canvas_push: script: - python3 to_canvas.py stage: deploy only: refs: - master changes: - to_canvas/**/*.{pdf} }}} where `image` tells the runner to use a python3 docker image, `before_script` runs a command in the container created from the image that installs the package canvasapi and the python script runs if any pdf-files in the folder to_canvas has been modified. == Runners == See https://gitlab.control.lth.se/regler//-/settings/ci_cd, where should be replaced with the repository name, for instructions about runners. Hopefully we will soon have some shared runners for the department, but for the moment they have to be set up for each project specifically. == Python script == The [[https://gitlab.control.lth.se/regler/FRTF10/blob/master/to_canvas.py|current script]] just takes all pdf files in one folder and pushed them to a folder on canvas. The script needs the names of the folders and the course code in canvas. To change how the upload is done you simply need to change this script to find and upload things in another fashion. == Canvas API Token == The script assumes there exists a variable for the Canvas API token in the repository. This variable is added to the gitlab runner as an environment variable and can then be used without us having it hardcoded anywhere. A token can be added by navigating to https://gitlab.control.lth.se/regler//-/settings/ci_cd, where you replace with the repository name, and looking under Variables. There you add a token with name `CANVAS_TOKEN` and value `13596~t2TYuTRlaJnfvyTznfvhDOqq7B85o2wD2jU8NBCsixzLirB8nceTFIvUzbldIa1K`. The API token can also be generated in a canvas profile but this is a token generated from a department account.