diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..6e5e9033 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,98 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + python-version: [3.6, 3.7, 3.8] + name: Test - ${{ matrix.os }}, ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + + - name: Fetch all history and metadata + run: | + git fetch --prune --unshallow + git checkout -b pr + git branch -f master origin/master + + - name: Install clang-format + shell: bash + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get install clang-format-10 + elif [ "$RUNNER_OS" == "Windows" ]; then + choco install llvm --version 10.0.0 + elif [ "$RUNNER_OS" == "macOS" ]; then + brew install clang-format + else + echo "$RUNNER_OS not supported" + exit 1 + fi + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install wpiformat + run: | + cd wpiformat + pip install -e . + + - name: Install test dependencies + shell: bash + run: | + if [ "$RUNNER_OS" == "Windows" ]; then + # This pytest dependency is installed manually with bash because the + # installation prints to stderr. Prints to stderr cause Powershell to + # report a nonzero return code and cause the tests to fail. + pip install wheel iniconfig + fi + + - name: Run unit tests + run: | + git config --global user.email "you@example.com" + git config --global user.name "Your Name" + cd wpiformat + python setup.py test + + - name: wpiformat - whole repo + run: | + python -m wpiformat -v + + - name: wpiformat - one file + run: | + cd wpiformat + python -m wpiformat -f wpiformat/__init__.py -v + + - name: wpiformat - absolute path to file + shell: bash + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + python -m wpiformat -f /home/runner/work/styleguide/styleguide/wpiformat/wpiformat/__init__.py -v + elif [ "$RUNNER_OS" == "Windows" ]; then + python -m wpiformat -f /d/a/styleguide/styleguide/wpiformat/wpiformat/__init__.py -v + elif [ "$RUNNER_OS" == "macOS" ]; then + python -m wpiformat -f /Users/runner/work/styleguide/styleguide/wpiformat/wpiformat/__init__.py -v + else + echo "$RUNNER_OS not supported" + exit 1 + fi + + - name: wpiformat - multiple files + run: | + cd wpiformat + python -m wpiformat -f wpiformat/__init__.py wpiformat/__main__.py -v + + - name: wpiformat - directory + run: | + cd wpiformat + python -m wpiformat -f wpiformat -v + + - name: Ensure formatter made no changes + run: git --no-pager diff --exit-code HEAD diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 9bc43946..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,114 +0,0 @@ -# Gradle -# Build your Java projects and run tests with Gradle using a Gradle wrapper script. -# Add steps that analyze code, save build artifacts, deploy, and more: -# https://docs.microsoft.com/vsts/pipelines/languages/java - -resources: - containers: - - container: ubuntu18 - image: ubuntu:18.04 - options: "--name ci-container -v /usr/bin/docker:/tmp/docker:ro" - -jobs: - - job: Linux - pool: - vmImage: 'Ubuntu 16.04' - - container: ubuntu18 - - steps: - - script: | - /tmp/docker exec -t -u 0 ci-container \ - sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo" - displayName: Set up sudo - - script: | - sudo apt-get update -y - sudo apt-get install clang-format gcc g++ python3-setuptools python3-dev git -y - displayName: 'Install Dependencies' - - script: | - git fetch --unshallow - cd wpiformat - python3 setup.py build - sudo python3 setup.py install --optimize=1 --skip-build - displayName: 'Build' - - script: | - git config --global user.email "you@example.com" - git config --global user.name "Your Name" - git checkout -b pr - git checkout master - git checkout pr - displayName: 'Make sure .git/refs/heads/master exists' - - script: | - cd wpiformat - python3 setup.py test - displayName: 'Run unit tests' - - script: | - python3 -m wpiformat -v - displayName: 'Run wpiformat' - - script: | - cd wpiformat - python3 -m wpiformat -f wpiformat/__init__.py -v - displayName: 'One file' - - script: | - cd wpiformat - python3 -m wpiformat -f /__w/1/s/wpiformat/wpiformat/__init__.py -v - displayName: 'Absolute path to file' - - script: | - cd wpiformat - python3 -m wpiformat -f wpiformat/__init__.py wpiformat/__main__.py -v - displayName: 'Multiple files' - - script: | - cd wpiformat - python3 -m wpiformat -f wpiformat -v - displayName: 'Directory' - - script: | - git --no-pager diff --exit-code HEAD - displayName: 'Ensure formatter made no changes' - - - job: Windows - pool: - vmImage: 'vs2017-win2016' - - steps: - - script: | - choco install llvm --version 6.0.1 - displayName: 'Install Dependencies' - - script: | - git fetch --unshallow - cd wpiformat - py -3 setup.py build - py -3 setup.py install --optimize=1 --skip-build - displayName: 'Build' - - powershell: | - git config --global user.email "you@example.com" - git config --global user.name "Your Name" - git checkout -b pr - git checkout master - git checkout pr - displayName: 'Make sure .git/refs/heads/master exists' - - powershell: | - cd wpiformat - py -3 setup.py test - displayName: 'Run unit tests' - - powershell: | - py -3 -m wpiformat -v - displayName: 'Run wpiformat' - - powershell: | - cd wpiformat - py -3 -m wpiformat -f wpiformat\__init__.py -v - displayName: 'One file' - - powershell: | - cd wpiformat - py -3 -m wpiformat -f D:\a\1\s\wpiformat\wpiformat\__init__.py -v - displayName: 'Absolute path to file' - - powershell: | - cd wpiformat - py -3 -m wpiformat -f wpiformat\__init__.py wpiformat\__main__.py -v - displayName: 'Multiple files' - - powershell: | - cd wpiformat - py -3 -m wpiformat -f wpiformat -v - displayName: 'Directory' - - powershell: | - git --no-pager diff --exit-code HEAD - displayName: 'Ensure formatter made no changes' diff --git a/wpiformat/wpiformat/__init__.py b/wpiformat/wpiformat/__init__.py index 4665b360..d1115c66 100644 --- a/wpiformat/wpiformat/__init__.py +++ b/wpiformat/wpiformat/__init__.py @@ -287,6 +287,12 @@ def main(): else: files.append(name) + # Throw an error if any files or directories don't exist + for f in files: + if not os.path.exists(f): + print(f"error: {f}: No such file or directory") + sys.exit(1) + # Convert relative paths of files to absolute paths files = [os.path.abspath(name) for name in files]