Skip to content

Commit

Permalink
feat: [OSM-612] Fix broken tests, restructure internal logic (#219)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dotkas committed Sep 11, 2023
1 parent 08ffde3 commit bf90287
Show file tree
Hide file tree
Showing 25 changed files with 441 additions and 1,742 deletions.
163 changes: 52 additions & 111 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,129 +1,67 @@
version: 2.1

orbs:
node: circleci/node@5.1.0
prodsec: snyk/prodsec-orb@1.0

defaults: &defaults
resource_class: medium
docker:
- image: node:16
working_directory: ~/snyk-python-plugin

commands:
checkout_and_merge:
steps:
- checkout
- run:
name: Checkout master
command: git checkout origin/master
- run:
name: Merge test branch
command: |
git config user.name "CircleCI"
git config user.email "noop"
git merge --no-edit "$CIRCLE_BRANCH"
- attach_workspace:
at: ~/snyk-python-plugin
test_python:
parameters:
pip_version:
type: string
python_version:
type: string
steps:
- checkout_and_merge
- attach_workspace:
at: ~/snyk-python-plugin
- run:
name: Run tests
command: |
apt -qq update
apt -qq install python3-pip python-pip -y &> /dev/null
curl https://pyenv.run | $SHELL
export PATH=$HOME/.pyenv/bin:$PATH
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export PYTHON_VER_FULL=`pyenv install --list | grep -v 'Available versions' | awk '{$1=$1};1' | grep "^$PYTHON_VER\.[0-9]\+$" | tail -1`
echo $PYTHON_VER_FULL
# Install the specific release of Python if it isn't already installed
pyenv install -s $PYTHON_VER_FULL
export PATH=$HOME/.pyenv/versions/$PYTHON_VER_FULL/bin:$PATH
pyenv shell $PYTHON_VER_FULL
python --version
export PATH=$HOME/.local/bin:$PATH
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
python -m pip install --user --quiet -r dev-requirements.txt --disable-pip-version-check
# pipenv installation always bumps pip version to >18.0.0, we manually install the desired pip version again
python -m pip install --user --quiet pip==$PIP_VER
pyenv rehash
npm run test
environment:
PIP_VER: << parameters.pip_version >>
PYTHON_VER: << parameters.python_version >>
- image: cimg/node:19.6.1

jobs:
install:
<<: *defaults
environment:
NODE_ENV: develop # Required because base image sets it to 'production'
steps:
- checkout_and_merge
- run:
name: Use snyk-main npmjs user
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
- run:
name: Install Node dependencies
command: npm install
- persist_to_workspace:
root: .
paths:
- node_modules/
lint:
<<: *defaults
steps:
- checkout_and_merge
- checkout
- node/install-packages:
with-cache: false
override-ci-command: npm install
- run:
name: Run linting tasks
command: npm run lint

test:
<<: *defaults
parameters:
node_version:
type: string
pip_version:
type: string
python_version:
type: string
docker:
- image: node:<< parameters.node_version >>
steps:
- test_python:
pip_version: << parameters.pip_version >>
python_version: << parameters.python_version >>
- checkout
- setup_remote_docker
- run:
name: Run tests
command: |
BUILDKIT_PROGRESS=plain \
DOCKER_BUILDKIT=1 \
docker build \
--build-arg NODE_VERSION=<< parameters.node_version >> \
--build-arg PYTHON_VERSION=<< parameters.python_version >> \
-t snyk-python-plugin:integration-tests-<< parameters.python_version >> \
-f test/Dockerfile .
docker run --rm snyk-python-plugin:integration-tests-<< parameters.python_version >>
build:
<<: *defaults
steps:
- checkout_and_merge
- run:
name: Use snyk-main npmjs user
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
- run:
name: Install dependencies
command: npm install
- checkout
- node/install-packages:
with-cache: false
override-ci-command: npm install
- run:
name: Run tests
command: npm run build

release:
<<: *defaults
docker:
- image: node:16
steps:
- checkout_and_merge
- run:
name: Install deps
command: npm install
- checkout
- node/install-packages:
with-cache: false
override-ci-command: npm install
- run:
name: Build
command: npm run build
- run:
name: Release
Expand All @@ -139,46 +77,49 @@ workflows:
- snyk-bot-slack
channel: os-team-managed-alerts

- install:
name: Install
filters:
branches:
ignore:
- master
- lint:
name: Lint
requires:
- Install
filters:
branches:
ignore:
- master
- main

- build:
name: Build
requires:
- Install
filters:
branches:
ignore:
- master
- main

- test:
name: Node << matrix.node_version >>, Python << matrix.python_version >>, Pip << matrix.pip_version >>
name: Node << matrix.node_version >>, Python << matrix.python_version >>
requires:
- Lint
- Build
matrix:
parameters:
node_version: ['14', '16']
pip_version: ['10.0.0','18.1.0']
python_version: ['2.7','3.6', '3.7', '3.8', '3.9']
node_version: [
'14',
'16',
'18',
]
python_version: [
'3.8',
'3.9',
'3.10',
'3.11',
]
filters:
branches:
ignore:
- master
- main

- release:
name: Release
context: nodejs-lib-release
requires:
- Scan repository for secrets
filters:
branches:
only:
- master
- main
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ Remember that you're developing for multiple platforms and versions of node, so

## Contributor Agreement

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/)).
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/)).
13 changes: 13 additions & 0 deletions .github/workflows/pr-housekeeping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on:
schedule:
- cron: '0 0 * * *' # Every day at midnight
workflow_dispatch:

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
with:
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."
close-pr-message: "Your PR has now been stale for 7 days. I'm closing it."
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ their corresponding positions in the original manifest file.

## Contributing

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

### Developing and Testing

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
build: off
branches:
only:
- master
- main

init:
- git config --global core.autocrlf true
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"format:check": "prettier --check '{lib,test}/**/*.{js,ts}'",
"format": "prettier --write '{lib,test}/**/*.{js,ts}'",
"prepare": "npm run build",
"test": "npm run test:pysrc && npm run test:tap && npm run test:jest",
"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",
"test": "npm run test:pysrc && npm run test:jest",
"test:jest": "jest",
"test:pysrc": "python -m unittest discover pysrc",
"lint": "npm run build-tests && npm run format:check && eslint --cache '{lib,test}/**/*.{js,ts}'"
Expand All @@ -30,7 +29,6 @@
"tmp": "0.2.1"
},
"devDependencies": {
"@snyk/types-tap": "^1.1.0",
"@types/jest": "^28.1.3",
"@types/node": "^16.11.66",
"@types/tmp": "^0.1.0",
Expand All @@ -44,7 +42,6 @@
"jest-junit": "^10.0.0",
"prettier": "^2.7.1",
"sinon": "^2.3.2",
"tap": "^12.6.1",
"ts-jest": "^28.0.8",
"ts-node": "^8.10.2",
"typescript": "^4.8.4"
Expand Down
32 changes: 32 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG NODE_VERSION
FROM node:${NODE_VERSION}

ARG DEVUSER=node
USER ${DEVUSER}

SHELL ["/bin/bash", "-c"]

WORKDIR /home/${DEVUSER}

ARG PYTHON_VERSION
ENV PYTHON_VERSION $PYTHON_VERSION

RUN set -ex \
&& curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash \
&& export PATH="$HOME/.pyenv/bin:$PATH" \
&& pyenv update \
&& pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION \
&& pyenv rehash

ENV PATH="/home/${DEVUSER}/.pyenv/shims:${PATH}"
RUN python --version

COPY --chown=${DEVUSER}:${DEVUSER} . ./

RUN npm install

ENV PATH="/home/${DEVUSER}/.local/bin:${PATH}"
RUN python -m pip install --user --quiet -r dev-requirements.txt --disable-pip-version-check

CMD ["npm", "run", "test", "--", "--runInBand"]
18 changes: 0 additions & 18 deletions test/_setup.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/fixtures/updated-manifest/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Jinja2==2.7.2
Django==2.0.1
python-etcd==0.4.5
Django-Select2==6.0.1 # this version installs with lowercase so it catches a previous bug in pip_resolve.py
irc==16.2 # this has a cyclic dependecy (interanl jaraco.text <==> jaraco.collections)
irc==16.2 # this has a cyclic dependecy (internal jaraco.text <==> jaraco.collections)
testtools==\
2.3.0 # this has a cycle (fixtures ==> testtols);
./packages/prometheus_client-0.6.0
transitive>=1.1.1 # not directly required, pinned by Snyk to avoid a vulnerability
transitive>=1.1.1 # not directly required, pinned by Snyk to avoid a vulnerability
Loading

0 comments on commit bf90287

Please sign in to comment.