Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Migrate CI to GitHub actions #166

Merged
merged 8 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: Build

on:
push:
branches: [ master ]
branches:
- master
pull_request:
branches: [ master ]
branches:
- master

jobs:
build:

runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy3]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change mean in practice (some versions are dropped)?

Copy link
Member

@Gallaecio Gallaecio Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Versions in this file are indicated along job definitions under include.

But these versions have actually been moved to the new tests.yml file. This file is now only for static tests (maybe Build is not the best name, Check as we use in Scrapy is slightly better).

include:
- python-version: 3.7
env:
TOXENV: docs
- python-version: 3.8
env:
TOXENV: flake8
- python-version: 3.8
env:
TOXENV: pylint
- python-version: 3.8
env:
TOXENV: security

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Greet
run: python -c "print('hello there')"

- name: Run check
env: ${{ matrix.env }}
run: |
pip install --upgrade pip
pip install --upgrade tox
tox
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish

on:
push:
tags:
- v*

jobs:
publish:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Check Tag
id: check-release-tag
run: |
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+[.][0-9]+[.][0-9]+(rc[0-9]+|[.]dev[0-9]+)?$ ]]; then
echo ::set-output name=release_tag::true
fi

- name: Publish to PyPI
if: steps.check-release-tag.outputs.release_tag == 'true'
run: |
pip install --upgrade pip
pip install --upgrade setuptools wheel twine
python setup.py sdist bdist_wheel
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }}
twine upload dist/*
34 changes: 34 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:

runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy3]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Run tests
run: |
pip install --upgrade pip
pip install --upgrade tox
tox -e py

- name: Upload coverage report
run: bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dist
docs/_build
_trial_temp
.coverage
.cache
coverage.xml
.cache
60 changes: 0 additions & 60 deletions .travis.yml

This file was deleted.

24 changes: 14 additions & 10 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from __future__ import absolute_import
import os
import unittest

import pytest
from six.moves.urllib.parse import urlparse

from w3lib.url import (is_url, safe_url_string, safe_download_url,
url_query_parameter, add_or_replace_parameter, url_query_cleaner,
file_uri_to_path, parse_data_uri, path_to_file_uri, any_to_uri,
urljoin_rfc, canonicalize_url, parse_url, add_or_replace_parameters)
from six.moves.urllib.parse import urlparse


class UrlTests(unittest.TestCase):
Expand Down Expand Up @@ -76,17 +79,16 @@ def test_safe_url_string_remove_ascii_tab_and_newlines(self):
def test_safe_url_string_unsafe_chars(self):
safeurl = safe_url_string(r"http://localhost:8001/unwise{,},|,\,^,[,],`?|=[]&[]=|")
self.assertEqual(safeurl, r"http://localhost:8001/unwise%7B,%7D,|,%5C,%5E,[,],%60?|=[]&[]=|")

def test_safe_url_string_quote_path(self):
safeurl = safe_url_string(u'http://google.com/"hello"', quote_path=True)
self.assertEqual(safeurl, u'http://google.com/%22hello%22')

safeurl = safe_url_string(u'http://google.com/"hello"', quote_path=False)
self.assertEqual(safeurl, u'http://google.com/"hello"')

safeurl = safe_url_string(u'http://google.com/"hello"')
self.assertEqual(safeurl, u'http://google.com/%22hello%22')


def test_safe_url_string_with_query(self):
safeurl = safe_url_string(u"http://www.example.com/£?unit=µ")
Expand Down Expand Up @@ -310,10 +312,6 @@ def test_add_or_replace_parameter(self):
self.assertEqual(add_or_replace_parameter(url, 'arg3', 'nv3'),
'http://domain/test?arg1=v1&arg2=v2&arg3=nv3')

url = 'http://domain/test?arg1=v1;arg2=v2'
self.assertEqual(add_or_replace_parameter(url, 'arg1', 'v3'),
'http://domain/test?arg1=v3&arg2=v2')

self.assertEqual(add_or_replace_parameter("http://domain/moreInfo.asp?prodID=", 'prodID', '20'),
'http://domain/moreInfo.asp?prodID=20')
url = 'http://rmc-offers.co.uk/productlist.asp?BCat=2%2C60&CatID=60'
Expand All @@ -338,6 +336,13 @@ def test_add_or_replace_parameter(self):
self.assertEqual(add_or_replace_parameter(url, 'arg1', 'v3'),
'http://domain/test?arg1=v3&arg2=v2')

@pytest.mark.xfail(reason="https://github.com/scrapy/w3lib/issues/164")
def test_add_or_replace_parameter_fail(self):
self.assertEqual(
add_or_replace_parameter('http://domain/test?arg1=v1;arg2=v2', 'arg1', 'v3'),
'http://domain/test?arg1=v3&arg2=v2'
)

Comment on lines +339 to +345
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a temporary workaround to avoid having the workflows fail (#164)

def test_add_or_replace_parameters(self):
url = 'http://domain/test'
self.assertEqual(add_or_replace_parameters(url, {'arg': 'v'}),
Expand Down Expand Up @@ -767,4 +772,3 @@ def test_scheme_case_insensitive(self):

if __name__ == "__main__":
unittest.main()

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ deps =
commands =
py.test \
--doctest-modules \
--cov=w3lib --cov-report=term \
--cov=w3lib --cov-report=term --cov-report=xml \
{posargs:w3lib tests}

[testenv:security]
Expand Down