-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
166 lines (150 loc) · 4.29 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
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
64
65
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
stages:
- lint
- test
- build
- publish
workflow:
# Only run for merge requests, tags, and the default branch
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH == 'main'
- if: $CI_COMMIT_BRANCH =~ '/^release\/v[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?$/'
.default_rules: &default_rules
- when: always
.publish_to_github_rules: &publish_to_github_rules
- if: $CI_COMMIT_BRANCH == 'main'
.publish_to_pypi_rules: &publish_to_pypi_rules
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9]+)?$/
.base:
image: python:3.10
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
before_script:
- mkdir -p ${PIP_CACHE_DIR}
- python -m venv .venv
- source .venv/bin/activate
- pip install -r requirements.txt
- python -m setup develop
cache: &default_cache
- paths:
- .cache/pip
- key:
files:
- requirements.txt
- setup.cfg
paths:
- ".venv"
.base_gh_ssh_agent:
before_script:
## _Inspired by https://docs.gitlab.com/ee/ci/ssh_keys/_
##
## Install ssh-agent if not already installed.
- "command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )"
## Run ssh-agent
- eval $(ssh-agent -s)
## Add the private key file to ssh-agent
- echo "$GH_REPO_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
## Create the SSH directory and give it the right permissions
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
## Using the set $SSH_KNOWN_HOSTS to be able to verify remote servers public keys
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
pycodestyle:
extends: .base
stage: lint
script:
- pycodestyle
rules:
- *default_rules
mypy:
extends: .base
stage: lint
script:
- mypy .
rules:
- *default_rules
licenses_checker:
stage: lint
image: registry.gitlab.com/ai-r/cogment/license-checker:latest
script:
- license-checker
rules:
- *default_rules
shellcheck:
image: koalaman/shellcheck-alpine:stable
stage: lint
before_script:
- shellcheck --version
script:
- shellcheck $(find . -name '*.sh' | xargs)
rules:
- *default_rules
shfmt:
image: mvdan/shfmt:v3.1.0-alpine
stage: lint
before_script:
- shfmt -version
script:
- shfmt -i 2 -ci -d .
rules:
- *default_rules
check_dependencies_conflicts:
image: python:$PYTHON_VERSION
stage: test
parallel:
matrix:
- PYTHON_VERSION: ["3.7", "3.8", "3.9", "3.10"]
script:
- ./scripts/check_dependencies_conflicts.sh
timeout: 2h
# We only want to run this job if there's been a change in dependencies.
rules:
- changes:
- scripts/check_dependencies_conflicts.sh
- requirements.txt
- pyproject.toml
integration_test:
extends: .base
stage: test
script:
- pytest --launch-orchestrator
artifacts:
when: always
reports:
junit: integration_test_report.xml
rules:
- *default_rules
build_sdist:
extends: .base
stage: build
script:
- python -m build
- twine check dist/*
artifacts:
expire_in: 1 week
paths:
- dist/*.tar.gz
- dist/*.whl
rules:
- *default_rules
publish_to_pypi:
extends: .base
stage: publish
script:
- python -m build
- python -m twine upload dist/* --non-interactive -u $PYPI_USERNAME -p $PYPI_PASSWORD
rules:
- *publish_to_pypi_rules
publish_branch_to_github:
extends: .base_gh_ssh_agent
stage: publish
script:
- git checkout ${CI_COMMIT_BRANCH} # Checkout the branch not the sha1
- git remote add downstream git@github.com:cogment/cogment-py-sdk.git
- git fetch downstream ${CI_COMMIT_BRANCH}
- git push --tags downstream ${CI_COMMIT_BRANCH}:${CI_COMMIT_BRANCH}
rules:
- *publish_to_github_rules