|
| 1 | +--- |
| 2 | +name: "CI" |
| 3 | +concurrency: # Cancel any existing runs of this workflow for this same PR |
| 4 | + group: "${{ github.workflow }}-${{ github.ref }}" |
| 5 | + cancel-in-progress: true |
| 6 | +on: # yamllint disable-line rule:truthy rule:comments |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - "main" |
| 10 | + - "develop" |
| 11 | + tags: |
| 12 | + - "v*" |
| 13 | + pull_request: ~ |
| 14 | + |
| 15 | +env: |
| 16 | + IMAGE_NAME: "pyntc" |
| 17 | + |
| 18 | +jobs: |
| 19 | + black: |
| 20 | + runs-on: "ubuntu-20.04" |
| 21 | + env: |
| 22 | + INVOKE_LOCAL: "True" |
| 23 | + steps: |
| 24 | + - name: "Check out repository code" |
| 25 | + uses: "actions/checkout@v2" |
| 26 | + - name: "Setup environment" |
| 27 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 28 | + - name: "Linting: black" |
| 29 | + run: "poetry run invoke black" |
| 30 | + bandit: |
| 31 | + runs-on: "ubuntu-20.04" |
| 32 | + env: |
| 33 | + INVOKE_LOCAL: "True" |
| 34 | + steps: |
| 35 | + - name: "Check out repository code" |
| 36 | + uses: "actions/checkout@v2" |
| 37 | + - name: "Setup environment" |
| 38 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 39 | + - name: "Linting: bandit" |
| 40 | + run: "poetry run invoke bandit" |
| 41 | + needs: |
| 42 | + - "black" |
| 43 | + pydocstyle: |
| 44 | + runs-on: "ubuntu-20.04" |
| 45 | + env: |
| 46 | + INVOKE_LOCAL: "True" |
| 47 | + steps: |
| 48 | + - name: "Check out repository code" |
| 49 | + uses: "actions/checkout@v2" |
| 50 | + - name: "Setup environment" |
| 51 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 52 | + - name: "Linting: pydocstyle" |
| 53 | + run: "poetry run invoke pydocstyle" |
| 54 | + needs: |
| 55 | + - "black" |
| 56 | + flake8: |
| 57 | + runs-on: "ubuntu-20.04" |
| 58 | + env: |
| 59 | + INVOKE_LOCAL: "True" |
| 60 | + steps: |
| 61 | + - name: "Check out repository code" |
| 62 | + uses: "actions/checkout@v2" |
| 63 | + - name: "Setup environment" |
| 64 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 65 | + - name: "Linting: flake8" |
| 66 | + run: "poetry run invoke flake8" |
| 67 | + needs: |
| 68 | + - "black" |
| 69 | + yamllint: |
| 70 | + runs-on: "ubuntu-20.04" |
| 71 | + env: |
| 72 | + INVOKE_LOCAL: "True" |
| 73 | + steps: |
| 74 | + - name: "Check out repository code" |
| 75 | + uses: "actions/checkout@v2" |
| 76 | + - name: "Setup environment" |
| 77 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 78 | + - name: "Linting: yamllint" |
| 79 | + run: "poetry run invoke yamllint" |
| 80 | + needs: |
| 81 | + - "black" |
| 82 | + build: |
| 83 | + strategy: |
| 84 | + fail-fast: true |
| 85 | + matrix: |
| 86 | + python-version: ["3.7", "3.8", "3.9", "3.10"] |
| 87 | + runs-on: "ubuntu-20.04" |
| 88 | + env: |
| 89 | + PYTHON_VER: "${{ matrix.python-version }}" |
| 90 | + steps: |
| 91 | + - name: "Check out repository code" |
| 92 | + uses: "actions/checkout@v2" |
| 93 | + - name: "Setup environment" |
| 94 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 95 | + - name: "Get image version" |
| 96 | + run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV" |
| 97 | + - name: "Set up Docker Buildx" |
| 98 | + id: "buildx" |
| 99 | + uses: "docker/setup-buildx-action@v1" |
| 100 | + - name: "Build" |
| 101 | + uses: "docker/build-push-action@v2" |
| 102 | + with: |
| 103 | + builder: "${{ steps.buildx.outputs.name }}" |
| 104 | + context: "./" |
| 105 | + push: false |
| 106 | + tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}" |
| 107 | + file: "./Dockerfile" |
| 108 | + cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 109 | + cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 110 | + build-args: | |
| 111 | + PYTHON_VER=${{ env.PYTHON_VER }} |
| 112 | + needs: |
| 113 | + - "bandit" |
| 114 | + - "pydocstyle" |
| 115 | + - "flake8" |
| 116 | + - "yamllint" |
| 117 | + # TODO: Re-enable after initial pylint issue is completed. https://github.com/networktocode/pyntc/issues/249 |
| 118 | + # pylint: |
| 119 | + # runs-on: "ubuntu-20.04" |
| 120 | + # strategy: |
| 121 | + # fail-fast: true |
| 122 | + # matrix: |
| 123 | + # python-version: ["3.7"] |
| 124 | + # env: |
| 125 | + # PYTHON_VER: "${{ matrix.python-version }}" |
| 126 | + # steps: |
| 127 | + # - name: "Check out repository code" |
| 128 | + # uses: "actions/checkout@v2" |
| 129 | + # - name: "Setup environment" |
| 130 | + # uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 131 | + # - name: "Get image version" |
| 132 | + # run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV" |
| 133 | + # - name: "Set up Docker Buildx" |
| 134 | + # id: "buildx" |
| 135 | + # uses: "docker/setup-buildx-action@v1" |
| 136 | + # - name: "Load the image from cache" |
| 137 | + # uses: "docker/build-push-action@v2" |
| 138 | + # with: |
| 139 | + # builder: "${{ steps.buildx.outputs.name }}" |
| 140 | + # context: "./" |
| 141 | + # push: false |
| 142 | + # load: true |
| 143 | + # tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}" |
| 144 | + # file: "./Dockerfile" |
| 145 | + # cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 146 | + # cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 147 | + # build-args: | |
| 148 | + # PYTHON_VER=${{ env.PYTHON_VER }} |
| 149 | + # - name: "Debug: Show docker images" |
| 150 | + # run: "docker image ls" |
| 151 | + # - name: "Linting: Pylint" |
| 152 | + # run: "poetry run invoke pylint" |
| 153 | + # needs: |
| 154 | + # - "build" |
| 155 | + pytest: |
| 156 | + strategy: |
| 157 | + fail-fast: true |
| 158 | + matrix: |
| 159 | + python-version: ["3.7", "3.8", "3.9", "3.10"] |
| 160 | + runs-on: "ubuntu-20.04" |
| 161 | + env: |
| 162 | + PYTHON_VER: "${{ matrix.python-version }}" |
| 163 | + steps: |
| 164 | + - name: "Check out repository code" |
| 165 | + uses: "actions/checkout@v2" |
| 166 | + - name: "Setup environment" |
| 167 | + uses: "networktocode/gh-action-setup-poetry-environment@v2" |
| 168 | + - name: "Get image version" |
| 169 | + run: "echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV" |
| 170 | + - name: "Set up Docker Buildx" |
| 171 | + id: "buildx" |
| 172 | + uses: "docker/setup-buildx-action@v1" |
| 173 | + - name: "Load the image from cache" |
| 174 | + uses: "docker/build-push-action@v2" |
| 175 | + with: |
| 176 | + builder: "${{ steps.buildx.outputs.name }}" |
| 177 | + context: "./" |
| 178 | + push: false |
| 179 | + load: true |
| 180 | + tags: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}" |
| 181 | + file: "./Dockerfile" |
| 182 | + cache-from: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 183 | + cache-to: "type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}" |
| 184 | + build-args: | |
| 185 | + PYTHON_VER=${{ env.PYTHON_VER }} |
| 186 | + - name: "Debug: Show docker images" |
| 187 | + run: "docker image ls" |
| 188 | + - name: "Run Tests" |
| 189 | + run: "poetry run invoke pytest" |
| 190 | + needs: |
| 191 | + # Remove everything but pylint once pylint is passing. |
| 192 | + # - "pylint" |
| 193 | + - "bandit" |
| 194 | + - "pydocstyle" |
| 195 | + - "flake8" |
| 196 | + - "yamllint" |
| 197 | + publish_gh: |
| 198 | + name: "Publish to GitHub" |
| 199 | + runs-on: "ubuntu-20.04" |
| 200 | + if: "startsWith(github.ref, 'refs/tags/v')" |
| 201 | + steps: |
| 202 | + - name: "Check out repository code" |
| 203 | + uses: "actions/checkout@v2" |
| 204 | + - name: "Set up Python" |
| 205 | + uses: "actions/setup-python@v2" |
| 206 | + with: |
| 207 | + python-version: "3.9" |
| 208 | + - name: "Install Python Packages" |
| 209 | + run: "pip install poetry" |
| 210 | + - name: "Set env" |
| 211 | + run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" |
| 212 | + - name: "Run Poetry Version" |
| 213 | + run: "poetry version $RELEASE_VERSION" |
| 214 | + - name: "Run Poetry Build" |
| 215 | + run: "poetry build" |
| 216 | + - name: "Upload binaries to release" |
| 217 | + uses: "svenstaro/upload-release-action@v2" |
| 218 | + with: |
| 219 | + repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}" |
| 220 | + file: "dist/*" |
| 221 | + tag: "${{ github.ref }}" |
| 222 | + overwrite: true |
| 223 | + file_glob: true |
| 224 | + needs: |
| 225 | + - "pytest" |
| 226 | + publish_pypi: |
| 227 | + name: "Push Package to PyPI" |
| 228 | + runs-on: "ubuntu-20.04" |
| 229 | + if: "startsWith(github.ref, 'refs/tags/v')" |
| 230 | + steps: |
| 231 | + - name: "Check out repository code" |
| 232 | + uses: "actions/checkout@v2" |
| 233 | + - name: "Set up Python" |
| 234 | + uses: "actions/setup-python@v2" |
| 235 | + with: |
| 236 | + python-version: "3.9" |
| 237 | + - name: "Install Python Packages" |
| 238 | + run: "pip install poetry" |
| 239 | + - name: "Set env" |
| 240 | + run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" |
| 241 | + - name: "Run Poetry Version" |
| 242 | + run: "poetry version $RELEASE_VERSION" |
| 243 | + - name: "Run Poetry Build" |
| 244 | + run: "poetry build" |
| 245 | + - name: "Push to PyPI" |
| 246 | + uses: "pypa/gh-action-pypi-publish@release/v1" |
| 247 | + with: |
| 248 | + user: "__token__" |
| 249 | + password: "${{ secrets.PYPI_API_TOKEN }}" |
| 250 | + needs: |
| 251 | + - "pytest" |
0 commit comments