Size: 2670
Comment:
|
Size: 1995
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 5: | Line 5: |
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/to_canvas|canvas page]]. | 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 they are uploaded to the `from_git` folder on the [[https://canvas.education.lu.se/courses/1342/files/folder/from_git|canvas page]]. |
Line 8: | Line 8: |
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. |
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. An example file can be found [[https://gitlab.control.lth.se/regler/canvassync/-/blob/master/gitlab-ci.yml|here]]. It contains the CANVAS_COURSE_CODE variable which defines where the script should upload to. |
Line 31: | Line 14: |
The [[https://gitlab.control.lth.se/regler/FRTF10/blob/master/to_canvas.py|current script]] uploads all pdf files from a folder (with subfolders) and creates the corresponding folder structure on canvas. The script assumes there exists environment variables for a canvas API token and canvas course code. A token can be added by navigating to https://gitlab.control.lth.se/regler/<REPO>/-/settings/ci_cd, where you replace <REPO> with the repository name, and looking under Variables. There you add a token with name `CANVAS_TOKEN` and one with name `CANVAS_COURSE_CODE`. |
The [[https://gitlab.control.lth.se/regler/canvassync/-/blob/master/canvas_sync.py|current script]] uploads all files from the to_canvas folder (with subfolders) and creates the corresponding folder structure on canvas in the from_git folder. |
Line 38: | Line 19: |
The API token can be generated in a canvas profile, and this one is generated from an account that should have access to all courses run by Automatic Control `13596~t2TYuTRlaJnfvyTznfvhDOqq7B85o2wD2jU8NBCsixzLirB8nceTFIvUzbldIa1K`. | The API token can be generated in a canvas profile, and this one is generated from an account that should have access to all courses run by Automatic Control `13596~t2TYuTRlaJnfvyTznfvhDOqq7B85o2wD2jU8NBCsixzLirB8nceTFIvUzbldIa1K`. It is available to all repositories in the regler group on gitlab under the name CANVAS_TOKEN. |
Gitlab to Canvas syncing
For a working example check out the FRTF10-repo where as soon as any changes in pdfs are pushed to the to_canvas folder they are uploaded to the from_git folder on the 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. An example file can be found here. It contains the CANVAS_COURSE_CODE variable which defines where the script should upload to.
Runners
See https://gitlab.control.lth.se/regler/<REPO>/-/settings/ci_cd, where <REPO> 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 current script uploads all files from the to_canvas folder (with subfolders) and creates the corresponding folder structure on canvas in the from_git folder.
Currently the script will upload and replace files if they already exists, but it wont otherwise delete files if they are removed from the repo.
Canvas API Token
The API token can be generated in a canvas profile, and this one is generated from an account that should have access to all courses run by Automatic Control 13596~t2TYuTRlaJnfvyTznfvhDOqq7B85o2wD2jU8NBCsixzLirB8nceTFIvUzbldIa1K. It is available to all repositories in the regler group on gitlab under the name CANVAS_TOKEN.