Skip to content

Commit

Permalink
Extra credit (#6)
Browse files Browse the repository at this point in the history
* Be more explicit about requirements-dev.txt

* Pin docs requirements and add search

* Pretty build-wheel.sh output

* Fix typing buglet

* Add dependabot config

* Add linters and suggestions

* Even prettier output

* See if lint can get by without a token

* Try with default actions token

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Add mypy to linting

* Generate GitHub releases

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Jordan Webb and github-actions[bot] authored Apr 19, 2021
1 parent a33139b commit 5c17c0e
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 10 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "pip"
directory: "/docs"
schedule:
interval: "daily"
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ jobs:
export BASEPLAT=manylinux2014
fi
echo "::group::Building builder"
docker-compose -f builder/docker-compose.yml build --pull
echo "::endgroup::Building builder"
docker-compose -f builder/docker-compose.yml run manylinux build-wheel.sh
env:
WHICH_PYTHON: ${{ matrix.python }}
Expand All @@ -69,7 +71,9 @@ jobs:
run: |
set -euo pipefail
echo "::group::Building builder"
docker-compose -f builder/docker-compose.yml build --pull
echo "::endgroup::Building builder"
docker-compose -f builder/docker-compose.yml run manylinux /opt/python/cp36-cp36m/bin/python3 setup.py sdist
- uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -111,3 +115,22 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}

- name: Generate changelog
id: generate-changelog
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
onlyLastTag: true

- name: Create GitHub release
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
body: ${{ steps.generate-changelog.outputs.changelog }}
files: |
dist/*.tar.gz
dist/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87 changes: 87 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
on:
pull_request:

name: Lint

jobs:
shellcheck:
name: shellcheck
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: shellcheck
if: always()
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
exclude: "./.git/*"
fail_on_error: true

markdownlint:
name: markdownlint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: markdownlint
uses: reviewdog/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
fail_on_error: true

misspell:
name: misspell
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: misspell
if: always()
uses: reviewdog/action-misspell@v1
with:
reporter: github-pr-review
github_token: ${{ secrets.GITHUB_TOKEN }}
locale: "US"

yamllint:
name: yamllint
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: yamllint
uses: reviewdog/action-yamllint@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review

pyflakes:
name: pyflakes
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: pyflakes
uses: reviewdog/action-pyflakes@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review

mypy:
name: mypy
runs-on: ubuntu-20.04
steps:
- uses: tsuyoshicho/action-mypy@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
84 changes: 84 additions & 0 deletions .github/workflows/suggestions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
on:
pull_request:

name: Suggestions

jobs:
shell:
name: Shell suggestions
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- uses: actions/setup-go@v2
- run: echo "$HOME/go/bin" >> "$GITHUB_PATH"
- run: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt

- name: install shellcheck
run: |
scversion="latest"
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
sudo cp "shellcheck-${scversion}/shellcheck" /usr/local/bin/
rm -rf "shellcheck-${scversion}/shellcheck"
- run: shellcheck -x -f diff $(shfmt -f .) | patch -p1
- run: shfmt -i 2 -ci -w .

- name: suggester / shellcheck
uses: reviewdog/action-suggester@v1
with:
tool_name: shellcheck / shfmt

markdown:
name: Markdown suggestions
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- run: sudo npm install -g markdownlint-cli

- run: markdownlint --fix --ignore site/_includes . || true

- name: suggester / markdown
uses: reviewdog/action-suggester@v1
with:
tool_name: markdownlint-cli

prettier:
name: Prettier suggestions
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- run: sudo npm install -g prettier

- run: prettier -u -w '**/*.yaml' '**/.*.yaml' '**/*.yml' '**/.*.yml' '**/*.json' '**/*.md' || true

- name: suggester / prettier
uses: reviewdog/action-suggester@v1
with:
tool_name: prettier

black:
name: Black formatter
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: Check files using the black formatter
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: "."

- name: suggester / black
uses: reviewdog/action-suggester@v1
with:
tool_name: black
2 changes: 2 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default: true
MD013: false
34 changes: 34 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
yaml-files:
- "*.yaml"
- ".*.yaml"
- "*.yml"
- ".*.yml"

rules:
braces: enable
brackets: enable
colons: enable
commas: enable
comments:
level: warning
comments-indentation:
level: warning
document-end: disable
document-start: disable
empty-lines: enable
empty-values: disable
hyphens: enable
indentation:
spaces: consistent
indent-sequences: whatever
key-duplicates: enable
key-ordering: disable
line-length: disable
new-line-at-end-of-file: enable
new-lines: enable
octal-values: disable
quoted-strings: disable
trailing-spaces: enable
truthy:
level: warning
ignore: .github/workflows
47 changes: 42 additions & 5 deletions builder/manylinux/build-wheel.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
#!/usr/bin/env bash
# Adapted from https://github.com/pypa/python-manylinux-demo/blob/master/travis/build-wheels.sh

set -euo pipefail

WHICH_PYTHON=${WHICH_PYTHON:-cp36-cp36m}

# bash stacktrace from https://gist.github.com/ahendrix/7030300

function errexit() {
local err=$?
set +o xtrace
local code="${1:-1}"
echo "Error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}. '${BASH_COMMAND}' exited with status $err"
# Print out the stack trace described by $function_stack
if [ ${#FUNCNAME[@]} -gt 2 ]; then
echo "Call tree:"
for ((i = 1; i < ${#FUNCNAME[@]} - 1; i++)); do
echo " $i: ${BASH_SOURCE[$i + 1]}:${BASH_LINENO[$i]} ${FUNCNAME[$i]}(...)"
done
fi
echo "Exiting with status ${code}"
exit "${code}"
}

# trap ERR to provide an error handler whenever a command exits nonzero
# this is a more verbose version of set -o errexit
trap 'errexit' ERR
# setting errtrace allows our ERR trap handler to be propagated to functions,
# expansions and subshells
set -o errtrace

function repair_wheel {
wheel="$1"
if ! auditwheel show "$wheel"; then
Expand All @@ -17,6 +41,7 @@ function repair_wheel {
mkdir -p /build/sdist /build/source /build/wheel /build/fixedwheel

# Build and extract sdist
echo "::group::Build and extract sdist"
/opt/python/cp36-cp36m/bin/python3 setup.py sdist -d /build/sdist

find /build
Expand All @@ -29,27 +54,39 @@ if [ -z "$sdist" ] ; then
fi

tar -C /build/source -xvf "$sdist"
echo "::endgroup::"

# Install development requirements
echo "::group::Install requirements-dev.txt"
"/opt/python/${WHICH_PYTHON}/bin/pip3" install -r /mnt/requirements-dev.txt
echo "::endgroup::"

# Compile wheel
echo "::group::Build wheel"
"/opt/python/${WHICH_PYTHON}/bin/pip3" wheel /build/source/"$(basename "$sdist" .tar.gz)" --no-deps -w /build/wheel
echo "::endgroup::"

# Bundle external shared libraries into the wheels
echo "::group::Repair wheel"
for whl in /build/wheel/*.whl; do
repair_wheel "$whl"
repair_wheel "$whl"
done
echo "::endgroup::"

# Install packages and test
cp /mnt/renameat2_test.py /bin/renameat2_test.py
echo "::group::Install package"
"/opt/python/${WHICH_PYTHON}/bin/pip3" install renameat2 --no-index -f /build/fixedwheel
echo "::endgroup::"

echo "::group::Run tests"
cp /mnt/renameat2_test.py /bin/renameat2_test.py
cd / && "/opt/python/${WHICH_PYTHON}/bin/python3" -m pytest /bin/renameat2_test.py
echo "::endgroup::"

# Copy tested wheel over to dist
mnt_uid=$(stat -c '%u' /mnt)
mnt_gid=$(stat -c '%g' /mnt)

# Copy tested wheel over to dist
mkdir -p /mnt/dist
cp /build/fixedwheel/*.whl /mnt/dist
cp -v /build/fixedwheel/*.whl /mnt/dist
chown -R "$mnt_uid:$mnt_gid" /mnt/dist
5 changes: 1 addition & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
from importlib_metadata import version

# sys.path.insert(0, os.path.abspath(".."))

release = version("renameat2")
version = ".".join(release.split(".")[:2])

Expand All @@ -37,6 +33,7 @@
"myst_parser",
"sphinx_rtd_theme",
"sphinx.ext.intersphinx",
"sphinx_search.extension",
]

# source_suffix = [".rst", ".md"]
Expand Down
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Sphinx==3.5.4
importlib-metadata==4.0.0
myst-parser==0.13.6
readthedocs-sphinx-search==0.1.0
sphinx-rtd-theme==0.5.2
2 changes: 1 addition & 1 deletion renameat2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def rename(
:raises OSError: if the system call fails
"""
flags = 0
flags = Flags(0)
if not replace:
flags |= Flags.RENAME_NOREPLACE

Expand Down
Loading

0 comments on commit 5c17c0e

Please sign in to comment.