Newer
Older
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Hidden template jobs to be used in `.gitlab-ci.yml`
#
# - `.python:black:check`: verify formatting of code with `black`
#
# - `.python:build`: build the `sdist` and `wheel` packages
#
# - `.python:build:sdist`: build the `sdist` package
#
# - `.python:build:wheel`: build the `wheel` package
#
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
#
# .python:black:check
# ===================
#
# The Python code must match `black` standard.
#
# USAGE
# =====
#
# include:
# - project: EOLE/Infra/ci-tools
# ref: stable
# file: /templates/Python.yaml
#
# stages:
# - lint
#
# python:black: {extends: '.python:black:check'}
#
# REQUIREMENTS
# ============
#
# - a `lint` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.not-on-stable` rules templates
#
# OPTIONAL VARIABLES
# ==================
#
# - `PYTHON_BLACK_OPTS`: additional options to pass to `black`
#
# - `PYTHON_SOURCE_DIR`: top level directory where to run `black`,
# defaults to `.`
#
# - `PYTHON_BLACK_IMAGE`: name of the black docker image to use
#
.python:black:check:
stage: lint
extends: .not-on-stable
image: "${PYTHON_BLACK_IMAGE}"
variables:
PYTHON_BLACK_IMAGE: "hub.eole.education/proxyhub/pyfound/black:latest_release"
PYTHON_BLACK_OPTS: ''
PYTHON_SOURCE_DIR: '.'
script:
- echo -e "\e[0Ksection_start:`date +%s`:python-black\r\e[0KExecute 'black --check ${PYTHON_BLACK_OPTS} ${PYTHON_SOURCE_DIR}'"
- black --check ${PYTHON_BLACK_OPTS} ${PYTHON_SOURCE_DIR}
- echo -e "\e[0Ksection_end:`date +%s`:python-black\r\e[0K"
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# .python:build
# =============
#
# Build the python `sdist` and `wheel` packages with the `build` module
#
# USAGE
# =====
#
# include:
# - project: EOLE/Infra/ci-tools
# ref: stable
# file: /templates/Python.yaml
#
# stages:
# - build
#
# python:build {extends: '.python:build'}
#
# REQUIREMENTS
# ============
#
# - a `build` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.rules-map` rules templates
#
# - a `pyproject.toml` or `setup.py` file
#
# OPTIONAL VARIABLES
# ==================
#
# - `PYTHON_DIST_FILES`: files to upload, defaults to `dist/*'
#
# - `PYTHON_SOURCE_DIR`: top level directory of python source where to
# find `pyproject.toml` or `setup.py`, defaults to `.'
#
# - `PYTHON_BUILD_OPTS`: additional options to pass to the
# `pyproject-build` command line
#
# - `PYTHON_IMAGE`: name of the python docker image to use
#
# SEE ALSO
# ========
#
# - https://pypi.org/project/build/
#
.python:build:
stage: build
extends: .python:base
variables:
PYTHON_DIST_FILES: dist/*
artifacts:
paths:
- ${PYTHON_SOURCE_DIR}/${PYTHON_DIST_FILES}
script:
- echo -e "\e[0Ksection_start:`date +%s`:python-build-deps[collapsed=true]\r\e[0KInstall 'build' module"
- pip install build
- echo -e "\e[0Ksection_end:`date +%s`:python-build-deps\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:python-build\r\e[0KBuild distribution `sdist` and `wheel` from '${PYTHON_SOURCE_DIR}'"
- pyproject-build ${PYTHON_BUILD_OPTS} "${PYTHON_SOURCE_DIR}"
- echo -e "\e[0Ksection_end:`date +%s`:python-build\r\e[0K"
#
# .python:build:sdist
# ===================
#
# Build the python source `.tar.gz` with the `build` module
#
# USAGE
# =====
#
# include:
# - project: EOLE/Infra/ci-tools
# ref: stable
# file: /templates/Python.yaml
#
# stages:
# - build
#
# python:build:source {extends: '.python:build:sdist'}
#
# REQUIREMENTS
# ============
#
# - a `build` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.rules-map` rules templates
# - a `pyproject.toml` or `setup.py` file
#
# OPTIONAL VARIABLES
# ==================
#
# - `PYTHON_DIST_FILES`: files to upload, defaults to `dist/*.tar.gz'
#
# - `PYTHON_SOURCE_DIR`: top level directory of python source where to
# find `pyproject.toml` or `setup.py`, defaults to `.'
# - `PYTHON_BUILD_OPTS`: additional options to pass to the
# `pyproject-build` command line
#
# - `PYTHON_IMAGE`: name of the python docker image to use
#
# SEE ALSO
# ========
#
# - https://pypi.org/project/build/
#
extends: .python:build
variables:
PYTHON_DIST_FILES: dist/*.tar.gz
script:
- echo -e "\e[0Ksection_start:`date +%s`:python-build-sdist-deps[collapsed=true]\r\e[0KInstall 'build' module"
- pip install build
- echo -e "\e[0Ksection_end:`date +%s`:python-build-sdist-deps\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:python-build-sdist\r\e[0KBuild distribution 'sdist` from '${PYTHON_SOURCE_DIR}'"
- pyproject-build --sdist ${PYTHON_BUILD_OPTS} "${PYTHON_SOURCE_DIR}"
- echo -e "\e[0Ksection_end:`date +%s`:python-build-sdist\r\e[0K"
#
# .python:build:wheel
# ===================
#
# Build the python source `.tar.gz` with the `build` module
#
# USAGE
# =====
#
# include:
# - project: EOLE/Infra/ci-tools
# ref: stable
# file: /templates/Python.yaml
#
# stages:
# - build
#
# python:build:source {extends: '.python:build:wheel'}
#
# REQUIREMENTS
# ============
#
# - a `build` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.rules-map` rules templates
# - a `pyproject.toml` or `setup.py` file
#
# OPTIONAL VARIABLES
# ==================
#
# - `PYTHON_DIST_FILES`: files to upload, defaults to `dist/*.whl'
#
# - `PYTHON_SOURCE_DIR`: top level directory of python source where to
# find `pyproject.toml` or `setup.py`, defaults to `.'
# - `PYTHON_BUILD_OPTS`: additional options to pass to the
# `pyproject-build` command line
#
# - `PYTHON_IMAGE`: name of the python docker image to use
#
# SEE ALSO
# ========
#
# - https://pypi.org/project/build/
#
extends: .python:build
variables:
PYTHON_DIST_FILES: dist/*.whl
script:
- echo -e "\e[0Ksection_start:`date +%s`:python-build-wheel-deps[collapsed=true]\r\e[0KInstall 'build' module"
- pip install build
- echo -e "\e[0Ksection_end:`date +%s`:python-build-wheel-deps\r\e[0K"
- echo -e "\e[0Ksection_start:`date +%s`:python-build-wheel\r\e[0KBuild distribution 'wheel` from '${PYTHON_SOURCE_DIR}'"
- pyproject-build --wheel ${PYTHON_BUILD_OPTS} "${PYTHON_SOURCE_DIR}"
- echo -e "\e[0Ksection_end:`date +%s`:python-build-wheel\r\e[0K"
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#
# .python:upload
# ==============
#
# Upload python package files to the registry
#
# USAGE
# =====
#
# include:
# - project: EOLE/Infra/ci-tools
# ref: stable
# file: /templates/Python.yaml
#
# stages:
# - build
#
# python:upload {extends: '.python:upload'}
#
# REQUIREMENTS
# ============
#
# - a `build` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need
#
# - the `.on-release-tag` rules templates
#
# OPTIONAL VARIABLES
# ==================
#
# - `PYTHON_DIST_FILES`: files to upload, defaults to `dist/*'
#
# - `PYTHON_SOURCE_DIR`: top level directory of python source where to
# find `setup.py`, defaults to `.`
#
# - `PYTHON_REPOSITORY_URL`: pypi repository URL, defaults to
# `${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi`
#
# - `PYTHON_IMAGE`: name of the python docker image to use
#
.python:upload:
stage: release
extends:
- .python:base
- .on-release-tag
variables:
PYTHON_REPOSITORY_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi
script:
- echo -e "\e[0Ksection_start:`date +%s`:python-twine-upload\r\e[0KUpload '${PYTHON_SOURCE_DIR}/${PYTHON_DIST_FILES}' to repository '${PYTHON_REPOSITORY_URL}'"
- cd ${PYTHON_SOURCE_DIR}
- pip install twine
- 'TWINE_PASSWORD=${CI_JOB_TOKEN}
TWINE_USERNAME=gitlab-ci-token
python -m twine upload
--repository-url ${PYTHON_REPOSITORY_URL}
${PYTHON_DIST_FILES}'
- echo -e "\e[0Ksection_end:`date +%s`:python-twine-upload\r\e[0K"
#
# .python:base
# ============
#
# Base template for build and upload
# Run on all branches, release and prerelease tags
rules:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, on-release-tag]
- !reference [.rules-map, on-testing-tag]
- !reference [.rules-map, on-dev-tag]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-branch]
image: "${PYTHON_IMAGE}"
variables:
PYTHON_IMAGE: "hub.eole.education/proxyhub/library/python:latest"
PYTHON_SOURCE_DIR: '.'
PYTHON_DIST_FILES: 'dist/*'