Skip to content

Commit bf90287

Browse files
authored
feat: [OSM-612] Fix broken tests, restructure internal logic (#219)
* chore: adding stale PR checker * fix: pinning urllib3 to workspace fixtures to avoid platform flakes * fix: removing not needed tap setup, updating test utils * feat: removed all tap tests, ported to jest * feat: removing tap from packages.json * feat: master -> main * feat: replaced circleci system tests with a Dockerfile for easier local replication * feat: removing support for EOLed libraries, re-wrote the test framework substantially BREAKING CHANGE: We now will not support EOL'ed versions of Python, NodeJs nor Pip. * chore: updating circleci config * chore: fixing typos * fix: partial depgraph comparisons * chore: python->python3 for local test setup' * fix: dropping setup.py test that was already done someplace else * chore: lint * chore: Node 14, 18
1 parent 08ffde3 commit bf90287

File tree

25 files changed

+441
-1742
lines changed

25 files changed

+441
-1742
lines changed

.circleci/config.yml

Lines changed: 52 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,67 @@
11
version: 2.1
22

33
orbs:
4+
node: circleci/[email protected]
45
prodsec: snyk/[email protected]
56

67
defaults: &defaults
8+
resource_class: medium
79
docker:
8-
- image: node:16
9-
working_directory: ~/snyk-python-plugin
10-
11-
commands:
12-
checkout_and_merge:
13-
steps:
14-
- checkout
15-
- run:
16-
name: Checkout master
17-
command: git checkout origin/master
18-
- run:
19-
name: Merge test branch
20-
command: |
21-
git config user.name "CircleCI"
22-
git config user.email "noop"
23-
git merge --no-edit "$CIRCLE_BRANCH"
24-
- attach_workspace:
25-
at: ~/snyk-python-plugin
26-
test_python:
27-
parameters:
28-
pip_version:
29-
type: string
30-
python_version:
31-
type: string
32-
steps:
33-
- checkout_and_merge
34-
- attach_workspace:
35-
at: ~/snyk-python-plugin
36-
- run:
37-
name: Run tests
38-
command: |
39-
apt -qq update
40-
apt -qq install python3-pip python-pip -y &> /dev/null
41-
curl https://pyenv.run | $SHELL
42-
export PATH=$HOME/.pyenv/bin:$PATH
43-
eval "$(pyenv init -)"
44-
eval "$(pyenv virtualenv-init -)"
45-
export PYTHON_VER_FULL=`pyenv install --list | grep -v 'Available versions' | awk '{$1=$1};1' | grep "^$PYTHON_VER\.[0-9]\+$" | tail -1`
46-
echo $PYTHON_VER_FULL
47-
# Install the specific release of Python if it isn't already installed
48-
pyenv install -s $PYTHON_VER_FULL
49-
export PATH=$HOME/.pyenv/versions/$PYTHON_VER_FULL/bin:$PATH
50-
pyenv shell $PYTHON_VER_FULL
51-
python --version
52-
export PATH=$HOME/.local/bin:$PATH
53-
export LC_ALL=C.UTF-8
54-
export LANG=C.UTF-8
55-
python -m pip install --user --quiet -r dev-requirements.txt --disable-pip-version-check
56-
# pipenv installation always bumps pip version to >18.0.0, we manually install the desired pip version again
57-
python -m pip install --user --quiet pip==$PIP_VER
58-
pyenv rehash
59-
npm run test
60-
environment:
61-
PIP_VER: << parameters.pip_version >>
62-
PYTHON_VER: << parameters.python_version >>
10+
- image: cimg/node:19.6.1
6311

6412
jobs:
65-
install:
66-
<<: *defaults
67-
environment:
68-
NODE_ENV: develop # Required because base image sets it to 'production'
69-
steps:
70-
- checkout_and_merge
71-
- run:
72-
name: Use snyk-main npmjs user
73-
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
74-
- run:
75-
name: Install Node dependencies
76-
command: npm install
77-
- persist_to_workspace:
78-
root: .
79-
paths:
80-
- node_modules/
8113
lint:
8214
<<: *defaults
8315
steps:
84-
- checkout_and_merge
16+
- checkout
17+
- node/install-packages:
18+
with-cache: false
19+
override-ci-command: npm install
8520
- run:
86-
name: Run linting tasks
8721
command: npm run lint
22+
8823
test:
8924
<<: *defaults
9025
parameters:
9126
node_version:
9227
type: string
93-
pip_version:
94-
type: string
9528
python_version:
9629
type: string
97-
docker:
98-
- image: node:<< parameters.node_version >>
9930
steps:
100-
- test_python:
101-
pip_version: << parameters.pip_version >>
102-
python_version: << parameters.python_version >>
31+
- checkout
32+
- setup_remote_docker
33+
- run:
34+
name: Run tests
35+
command: |
36+
BUILDKIT_PROGRESS=plain \
37+
DOCKER_BUILDKIT=1 \
38+
docker build \
39+
--build-arg NODE_VERSION=<< parameters.node_version >> \
40+
--build-arg PYTHON_VERSION=<< parameters.python_version >> \
41+
-t snyk-python-plugin:integration-tests-<< parameters.python_version >> \
42+
-f test/Dockerfile .
43+
docker run --rm snyk-python-plugin:integration-tests-<< parameters.python_version >>
44+
10345
build:
10446
<<: *defaults
10547
steps:
106-
- checkout_and_merge
107-
- run:
108-
name: Use snyk-main npmjs user
109-
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
110-
- run:
111-
name: Install dependencies
112-
command: npm install
48+
- checkout
49+
- node/install-packages:
50+
with-cache: false
51+
override-ci-command: npm install
11352
- run:
114-
name: Run tests
11553
command: npm run build
54+
11655
release:
11756
<<: *defaults
11857
docker:
11958
- image: node:16
12059
steps:
121-
- checkout_and_merge
122-
- run:
123-
name: Install deps
124-
command: npm install
60+
- checkout
61+
- node/install-packages:
62+
with-cache: false
63+
override-ci-command: npm install
12564
- run:
126-
name: Build
12765
command: npm run build
12866
- run:
12967
name: Release
@@ -139,46 +77,49 @@ workflows:
13977
- snyk-bot-slack
14078
channel: os-team-managed-alerts
14179

142-
- install:
143-
name: Install
144-
filters:
145-
branches:
146-
ignore:
147-
- master
14880
- lint:
14981
name: Lint
150-
requires:
151-
- Install
15282
filters:
15383
branches:
15484
ignore:
155-
- master
85+
- main
86+
15687
- build:
15788
name: Build
158-
requires:
159-
- Install
16089
filters:
16190
branches:
16291
ignore:
163-
- master
92+
- main
93+
16494
- test:
165-
name: Node << matrix.node_version >>, Python << matrix.python_version >>, Pip << matrix.pip_version >>
95+
name: Node << matrix.node_version >>, Python << matrix.python_version >>
16696
requires:
16797
- Lint
16898
- Build
16999
matrix:
170100
parameters:
171-
node_version: ['14', '16']
172-
pip_version: ['10.0.0','18.1.0']
173-
python_version: ['2.7','3.6', '3.7', '3.8', '3.9']
101+
node_version: [
102+
'14',
103+
'16',
104+
'18',
105+
]
106+
python_version: [
107+
'3.8',
108+
'3.9',
109+
'3.10',
110+
'3.11',
111+
]
174112
filters:
175113
branches:
176114
ignore:
177-
- master
115+
- main
116+
178117
- release:
179118
name: Release
180119
context: nodejs-lib-release
120+
requires:
121+
- Scan repository for secrets
181122
filters:
182123
branches:
183124
only:
184-
- master
125+
- main

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ Remember that you're developing for multiple platforms and versions of node, so
4545

4646
## Contributor Agreement
4747

48-
A pull-request will only be considered for merging into the upstream codebase after you have signed our [contributor agreement](https://github.com/snyk/snyk-python-plugin/blob/master/Contributor-Agreement.md), assigning us the rights to the contributed code and granting you a license to use it in return. If you submit a pull request, you will be prompted to review and sign the agreement with one click (we use [CLA assistant](https://cla-assistant.io/)).
48+
A pull-request will only be considered for merging into the upstream codebase after you have signed our [contributor agreement](https://github.com/snyk/snyk-python-plugin/blob/main/Contributor-Agreement.md), assigning us the rights to the contributed code and granting you a license to use it in return. If you submit a pull request, you will be prompted to review and sign the agreement with one click (we use [CLA assistant](https://cla-assistant.io/)).

.github/workflows/pr-housekeeping.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
on:
2+
schedule:
3+
- cron: '0 0 * * *' # Every day at midnight
4+
workflow_dispatch:
5+
6+
jobs:
7+
stale:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/stale@v7
11+
with:
12+
stale-pr-message: "Your PR has not had any activity for 60 days. In 7 days I'll close it. Make some activity to remove this."
13+
close-pr-message: "Your PR has now been stale for 7 days. I'm closing it."

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ their corresponding positions in the original manifest file.
5252

5353
## Contributing
5454

55-
[Guide](https://github.com/snyk/snyk-python-plugin/blob/master/.github/CONTRIBUTING.md)
55+
[Guide](https://github.com/snyk/snyk-python-plugin/blob/main/.github/CONTRIBUTING.md)
5656

5757
### Developing and Testing
5858

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
build: off
55
branches:
66
only:
7-
- master
7+
- main
88

99
init:
1010
- git config --global core.autocrlf true

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"format:check": "prettier --check '{lib,test}/**/*.{js,ts}'",
1515
"format": "prettier --write '{lib,test}/**/*.{js,ts}'",
1616
"prepare": "npm run build",
17-
"test": "npm run test:pysrc && npm run test:tap && npm run test:jest",
18-
"test:tap": "cross-env TS_NODE_PROJECT=tsconfig-test.json tap --node-arg=-r --node-arg=ts-node/register ./test/**/*.test.{js,ts} -R spec --timeout=900",
17+
"test": "npm run test:pysrc && npm run test:jest",
1918
"test:jest": "jest",
2019
"test:pysrc": "python -m unittest discover pysrc",
2120
"lint": "npm run build-tests && npm run format:check && eslint --cache '{lib,test}/**/*.{js,ts}'"
@@ -30,7 +29,6 @@
3029
"tmp": "0.2.1"
3130
},
3231
"devDependencies": {
33-
"@snyk/types-tap": "^1.1.0",
3432
"@types/jest": "^28.1.3",
3533
"@types/node": "^16.11.66",
3634
"@types/tmp": "^0.1.0",
@@ -44,7 +42,6 @@
4442
"jest-junit": "^10.0.0",
4543
"prettier": "^2.7.1",
4644
"sinon": "^2.3.2",
47-
"tap": "^12.6.1",
4845
"ts-jest": "^28.0.8",
4946
"ts-node": "^8.10.2",
5047
"typescript": "^4.8.4"

test/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ARG NODE_VERSION
2+
FROM node:${NODE_VERSION}
3+
4+
ARG DEVUSER=node
5+
USER ${DEVUSER}
6+
7+
SHELL ["/bin/bash", "-c"]
8+
9+
WORKDIR /home/${DEVUSER}
10+
11+
ARG PYTHON_VERSION
12+
ENV PYTHON_VERSION $PYTHON_VERSION
13+
14+
RUN set -ex \
15+
&& curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash \
16+
&& export PATH="$HOME/.pyenv/bin:$PATH" \
17+
&& pyenv update \
18+
&& pyenv install $PYTHON_VERSION \
19+
&& pyenv global $PYTHON_VERSION \
20+
&& pyenv rehash
21+
22+
ENV PATH="/home/${DEVUSER}/.pyenv/shims:${PATH}"
23+
RUN python --version
24+
25+
COPY --chown=${DEVUSER}:${DEVUSER} . ./
26+
27+
RUN npm install
28+
29+
ENV PATH="/home/${DEVUSER}/.local/bin:${PATH}"
30+
RUN python -m pip install --user --quiet -r dev-requirements.txt --disable-pip-version-check
31+
32+
CMD ["npm", "run", "test", "--", "--runInBand"]

test/_setup.test.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/fixtures/updated-manifest/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Jinja2==2.7.2
22
Django==2.0.1
33
python-etcd==0.4.5
44
Django-Select2==6.0.1 # this version installs with lowercase so it catches a previous bug in pip_resolve.py
5-
irc==16.2 # this has a cyclic dependecy (interanl jaraco.text <==> jaraco.collections)
5+
irc==16.2 # this has a cyclic dependecy (internal jaraco.text <==> jaraco.collections)
66
testtools==\
77
2.3.0 # this has a cycle (fixtures ==> testtols);
88
./packages/prometheus_client-0.6.0
9-
transitive>=1.1.1 # not directly required, pinned by Snyk to avoid a vulnerability
9+
transitive>=1.1.1 # not directly required, pinned by Snyk to avoid a vulnerability

0 commit comments

Comments
 (0)