Skip to content

Instantly share code, notes, and snippets.

@breinbaas
Last active June 29, 2022 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breinbaas/85ce38d6c9e3402ead2309f22f83c14a to your computer and use it in GitHub Desktop.
Save breinbaas/85ce38d6c9e3402ead2309f22f83c14a to your computer and use it in GitHub Desktop.

Example script of testing, linting and deploying a python package to a private gitlab repo

Note the following info

  • PROJECT_ID, can be found on the main repo page under the title
  • GITLAB_TOKEN, can be created under PREFERENCES | ACCESS TOKENS, create one with the api scope

In this CICD script we only run the tests etc on commits to the main branch.


before_script:
  - pip install poetry
  - poetry config virtualenvs.create false
  - poetry install

testing:
  stage: test  
  script:
    - poetry run pytest
  only:
    refs:
      - main

linting:
  stage: deploy
  script:
    - poetry run black .
  only:
    refs:
      - main

deploying:
  stage: deploy
  script:
    - poetry config repositories.gitlab https://gitlab.com/api/v4/projects/<PROJECT_ID>/packages/pypi
    - poetry build
    - poetry publish --repository gitlab -u breinbaas -p <GITLAB_TOKEN>
  only:
    refs:
      - main```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment