Skip to content

Commit af1db69

Browse files
Merge pull request #407 from pyupio/develop
Safety 2.2.0 patch
2 parents f4ed48f + 003eb3a commit af1db69

15 files changed

Lines changed: 261 additions & 241 deletions

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Safety Action Build And Publish
22

3-
on: [push]
3+
on:
4+
push:
5+
branches: [master]
46

57
env:
68
DOCKER_BUILDKIT: 1

.github/workflows/main.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Python package
2+
3+
on: [ push ]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Display Python version
18+
run: python -c "import sys; print(sys.version)"
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r test_requirements.txt
23+
- name: Test with pytest
24+
run: |
25+
pytest -rP tests/ --cov=dparse/ --cov-report=xml --cov-report=html
26+
27+
build-binaries:
28+
needs: test
29+
runs-on: ${{ matrix.os }}
30+
31+
if: contains(fromJson('["refs/heads/master", "refs/heads/develop", "refs/heads/binaries-fixes"]'), github.ref) || startsWith(github.ref, 'refs/tags')
32+
33+
strategy:
34+
matrix:
35+
os: ['windows-latest', 'ubuntu-latest', 'macos-latest']
36+
env:
37+
BINARY_OS: '${{ matrix.os }}'
38+
steps:
39+
- uses: actions/checkout@v3
40+
- name: Set up Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: '3.10'
44+
- name: Install Dependencies
45+
run: python binaries.py install
46+
- name: Test Safety
47+
run: python binaries.py test
48+
- name: Producing Binaries
49+
run: python binaries.py dist
50+
- uses: actions/upload-artifact@v3
51+
if: ${{ matrix.os == 'windows-latest' }}
52+
with:
53+
name: safety-win-i686.exe
54+
path: dist/safety-win-i686.exe
55+
if-no-files-found: error
56+
- uses: actions/upload-artifact@v3
57+
if: ${{ matrix.os == 'windows-latest' }}
58+
with:
59+
name: safety-win-x86_64.exe
60+
path: dist/safety-win-x86_64.exe
61+
if-no-files-found: error
62+
- uses: actions/upload-artifact@v3
63+
if: ${{ matrix.os == 'ubuntu-latest' }}
64+
with:
65+
name: safety-linux-i686
66+
path: dist/safety-linux-i686
67+
if-no-files-found: error
68+
- uses: actions/upload-artifact@v3
69+
if: ${{ matrix.os == 'ubuntu-latest' }}
70+
with:
71+
name: safety-linux-x86_64
72+
path: dist/safety-linux-x86_64
73+
if-no-files-found: error
74+
- uses: actions/upload-artifact@v3
75+
if: ${{ matrix.os == 'macos-latest' }}
76+
with:
77+
name: safety-macos-x86_64
78+
path: dist/safety-macos-x86_64
79+
if-no-files-found: error
80+
81+
82+
deploy-pypi:
83+
needs: build-binaries
84+
runs-on: ubuntu-latest
85+
86+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
87+
88+
steps:
89+
- uses: actions/checkout@v3
90+
- name: Set up Python
91+
uses: actions/setup-python@v4
92+
with:
93+
python-version: '3.10'
94+
- name: Install dependencies
95+
run: |
96+
python -m pip install --upgrade pip
97+
pip install build
98+
- name: Build package
99+
run: python -m build
100+
- name: Publish package
101+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
102+
with:
103+
user: __token__
104+
password: ${{ secrets.SAFETY_PYPI_API_TOKEN }}
105+
106+
create-gh-release:
107+
needs: deploy-pypi
108+
runs-on: ubuntu-latest
109+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
110+
permissions:
111+
contents: write
112+
steps:
113+
- uses: actions/checkout@v2
114+
- uses: ncipollo/release-action@v1
115+
with:
116+
artifacts: "dist/safety-win-i686.exe,dist/safety-win-x86_64.exe,dist/safety-linux-i686,dist/safety-linux-x86_64,dist/safety-macos-x86_64"
117+
token: ${{ secrets.SAFETY_GITHUB_TOKEN }}

.github/workflows/test-insecure.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
######## set on the action step, and a further step to ensure the previous step failed (and actually fail if it _didn't_)
33
name: Safety Action Insecure Tests
44

5-
on: [push]
5+
on:
6+
push:
7+
branches: [master, develop]
68

79
jobs:
810
##### Auto mode tests

.github/workflows/test-secure.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
######## fail, the pinned version might need to be updated.
44
name: Safety Action Secure Tests
55

6-
on: [push]
6+
on:
7+
push:
8+
branches: [master, develop]
79

810
jobs:
911
##### Auto mode tests

.travis.yml

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

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.
55
The format is partly based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [PEP 440](https://peps.python.org/pep-0440/)
77

8+
## [Unreleased] 2.2.0.dev
9+
810
## [2.1.1] - 2022-07-18
911
- Fix crash when running on systems without git present (Thanks @andyjones)
1012

appveyor.yml

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

appveyor.py renamed to binaries.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
"""AppVeyor Build
1+
"""Github Action Build
22
3-
This file is used to build and distribute the safety binary on appveyor. Take
4-
a look at the corresponding appveyor.yml as well.
3+
This file is used to build and distribute the safety binary on Github actions.
4+
Take a look at the corresponding main.yml as well.
55
66
"""
77
import os
@@ -18,35 +18,38 @@ class environment:
1818

1919
def __init__(self):
2020
os_mapping = {
21-
"Visual Studio 2019": self.WIN,
22-
"Ubuntu": self.LINUX,
23-
"macOS": self.MACOS
21+
"windows-latest": self.WIN,
22+
"ubuntu-latest": self.LINUX,
23+
"macos-latest": self.MACOS
2424
}
25-
self.os = os_mapping[os.getenv("APPVEYOR_BUILD_WORKER_IMAGE")]
25+
self.os = os_mapping[os.getenv("BINARY_OS")]
2626

2727
@property
2828
def python(self):
2929
for arch, python in self.PYTHON_BINARIES[self.os].items():
3030
yield arch, python
3131

32+
WIN_BASE_PATH = "C:\\hostedtoolcache\\windows\\Python\\3.10.7"
33+
3234
PYTHON_BINARIES = {
3335
WIN: {
34-
64: "C:\\Python38-x64\\python.exe",
35-
32: "C:\\Python38\\python.exe",
36+
64: f"{WIN_BASE_PATH}\\x64\\python.exe", # setup-python default
37+
32: f"{WIN_BASE_PATH}\\x86\\python.exe"
3638
},
3739

3840
# Order is important. If the 32 bit release gets built first,
3941
# you'll run into permission problems due to docker clobbering
4042
# up the current working directory.
4143
LINUX: OrderedDict([
42-
(64, "python"),
43-
(32, f"docker run -t -v {os.getcwd()}:/app 32-bit-linux python3"),
44+
(64, "python3"),
45+
(32,
46+
f"docker run --platform linux/386 -t "
47+
f"-v {os.getcwd()}:/app 32-bit-linux "
48+
f"python3"),
4449
]),
4550

4651
MACOS: {
47-
# Trying to use Python 3 compatible with PyInstaller according
48-
# https://www.appveyor.com/docs/macos-images-software/#python
49-
64: "~/venv3.8/bin/python",
52+
64: "python3",
5053
}
5154
}
5255

@@ -59,7 +62,10 @@ def run(self, command):
5962
try:
6063
print(f"RUNNING: {command}")
6164
print("-" * 80)
62-
subprocess.run(command, shell=True, check=True)
65+
result = subprocess.run(command, shell=True, check=True,
66+
stdout=subprocess.PIPE)
67+
if result:
68+
print(result.stdout.decode('utf-8').strip())
6369
except subprocess.CalledProcessError as e:
6470
print(f"ERROR calling '{command}'")
6571
print("-" * 20)
@@ -74,13 +80,12 @@ def install(self):
7480
# - build the 32 bit binary for linux on docker
7581
# - create dist/ path to circumvent permission errors
7682
if self.os == self.LINUX:
77-
self.run("docker build -t 32-bit-linux -f Dockerfilei386 .")
83+
self.run("docker build --platform linux/386 "
84+
"-t 32-bit-linux -f Dockerfilei386 .")
7885

7986
for arch, python in self.python:
80-
self.run(f"{python} -m pip install setuptools")
8187
self.run(f"{python} -m pip install pyinstaller")
82-
self.run(f"{python} -m pip install pytest")
83-
self.run(f"{python} -m pip install -e .")
88+
self.run(f"{python} -m pip install -r test_requirements.txt")
8489

8590
def dist(self):
8691
"""Runs Pyinstaller producing a binary for every platform arch."""
@@ -92,7 +97,7 @@ def dist(self):
9297
f" --distpath {build_path}")
9398

9499
# There seems to be no way to tell pyinstaller the binary name.
95-
# This leads to problems with appveyors artifact collector because
100+
# This leads to problems with artifact collector because
96101
# every binary is named the same.
97102
#
98103
# Move them around so they can be picked up correctly
@@ -113,13 +118,13 @@ def test(self):
113118
Runs tests for every available arch on the current platform.
114119
"""
115120
for arch, python in self.python:
116-
self.run(f"{python} -m pytest")
121+
self.run(f"{python} -m pytest --log-level=DEBUG")
117122

118123

119124
if __name__ == "__main__":
120125

121126
if len(sys.argv) <= 1 or sys.argv[1] not in ['install', 'test', 'dist']:
122-
print("usage: appveyor.py [install|test|dist]")
127+
print("usage: binaries.py [install|test|dist]")
123128
sys.exit(-1)
124129

125130
env = environment()

safety/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.1
1+
2.2.0.dev

0 commit comments

Comments
 (0)