|
| 1 | +name: Test and build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + types: [opened, labeled] |
| 9 | + |
| 10 | +jobs: |
| 11 | + pyTest: |
| 12 | + if: | |
| 13 | + github.event_name == 'push' || |
| 14 | + ( |
| 15 | + github.event_name == 'pull_request' && |
| 16 | + ( |
| 17 | + contains(github.event.pull_request.title, '[run ci]') || |
| 18 | + contains(github.event.pull_request.body, '[run ci]') || |
| 19 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 20 | + ) |
| 21 | + ) |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + - name: Set up Python 3.11 |
| 26 | + uses: actions/setup-python@v3 |
| 27 | + with: |
| 28 | + python-version: 3.11 |
| 29 | + - name: Install pip |
| 30 | + run: | |
| 31 | + python -m pip install pip==$(sed -nE 's/pip = "==(.*)"/\1/p' Pipfile) |
| 32 | + - name: Install pipenv |
| 33 | + run: | |
| 34 | + PIPENV_VERSION=$(sed -nE 's/pipenv = "==(.*)"/\1/p' Pipfile) |
| 35 | + python -m pip install pipenv==$PIPENV_VERSION |
| 36 | + - name: Install from pipfile |
| 37 | + run: | |
| 38 | + pipenv install --system |
| 39 | + - name: Running pytest |
| 40 | + run: | |
| 41 | + cd techsupport_bot |
| 42 | + python3.11 -m pytest tests/ -p no:warnings |
| 43 | +
|
| 44 | + black: |
| 45 | + if: | |
| 46 | + github.event_name == 'push' || |
| 47 | + ( |
| 48 | + github.event_name == 'pull_request' && |
| 49 | + ( |
| 50 | + contains(github.event.pull_request.title, '[run ci]') || |
| 51 | + contains(github.event.pull_request.body, '[run ci]') || |
| 52 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 53 | + ) |
| 54 | + ) |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v3 |
| 58 | + - name: Set up Python 3.11 |
| 59 | + uses: actions/setup-python@v3 |
| 60 | + with: |
| 61 | + python-version: 3.11 |
| 62 | + - name: Install dependencies |
| 63 | + run: | |
| 64 | + python -m pip install pip==$(sed -nE 's/pip = "==(.*)"/\1/p' Pipfile) |
| 65 | + BLACK_VERSION=$(sed -nE 's/black = "==(.*)"/\1/p' Pipfile) |
| 66 | + pip install black==$BLACK_VERSION |
| 67 | + - name: Analysing the code with black |
| 68 | + run: | |
| 69 | + black $(git rev-parse --show-toplevel) --check |
| 70 | +
|
| 71 | + pyLint: |
| 72 | + if: | |
| 73 | + github.event_name == 'push' || |
| 74 | + ( |
| 75 | + github.event_name == 'pull_request' && |
| 76 | + ( |
| 77 | + contains(github.event.pull_request.title, '[run ci]') || |
| 78 | + contains(github.event.pull_request.body, '[run ci]') || |
| 79 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 80 | + ) |
| 81 | + ) |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v3 |
| 85 | + - name: Set up Python 3.11 |
| 86 | + uses: actions/setup-python@v3 |
| 87 | + with: |
| 88 | + python-version: 3.11 |
| 89 | + - name: Install dependencies |
| 90 | + run: | |
| 91 | + python -m pip install pip==$(sed -nE 's/pip = "==(.*)"/\1/p' Pipfile) |
| 92 | + PYLINT_VERSION=$(sed -nE 's/pylint = "==(.*)"/\1/p' Pipfile) |
| 93 | + pip install pylint==$PYLINT_VERSION |
| 94 | + - name: Analysing the code with pylint |
| 95 | + run: | |
| 96 | + pylint $(git ls-files '*.py') |
| 97 | +
|
| 98 | + lineEndingCheck: |
| 99 | + if: | |
| 100 | + github.event_name == 'push' || |
| 101 | + ( |
| 102 | + github.event_name == 'pull_request' && |
| 103 | + ( |
| 104 | + contains(github.event.pull_request.title, '[run ci]') || |
| 105 | + contains(github.event.pull_request.body, '[run ci]') || |
| 106 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 107 | + ) |
| 108 | + ) |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v3 |
| 112 | + - name: Check for CRLF line endings |
| 113 | + run: | |
| 114 | + for file in $(git ls-files); do |
| 115 | + if grep -q $'\r$' "$file"; then |
| 116 | + echo "$file has faulty file endings" |
| 117 | + fi |
| 118 | + done |
| 119 | + if git grep -I --name-only $'\r'; then |
| 120 | + echo "CRLF line endings detected" |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | +
|
| 124 | + flake8: |
| 125 | + if: | |
| 126 | + github.event_name == 'push' || |
| 127 | + ( |
| 128 | + github.event_name == 'pull_request' && |
| 129 | + ( |
| 130 | + contains(github.event.pull_request.title, '[run ci]') || |
| 131 | + contains(github.event.pull_request.body, '[run ci]') || |
| 132 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 133 | + ) |
| 134 | + ) |
| 135 | + runs-on: ubuntu-latest |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v3 |
| 138 | + - name: Set up Python 3.11 |
| 139 | + uses: actions/setup-python@v3 |
| 140 | + with: |
| 141 | + python-version: 3.11 |
| 142 | + - name: Install dependencies |
| 143 | + run: | |
| 144 | + python -m pip install pip==$(sed -nE 's/pip = "==(.*)"/\1/p' Pipfile) |
| 145 | + pip install pipenv==$(sed -nE 's/pipenv = "==(.*)"/\1/p' Pipfile) |
| 146 | + pipenv install --system |
| 147 | + - name: Analysing the code with flake8 |
| 148 | + run: | |
| 149 | + flake8 $(git rev-parse --show-toplevel) |
| 150 | +
|
| 151 | + isort: |
| 152 | + if: | |
| 153 | + github.event_name == 'push' || |
| 154 | + ( |
| 155 | + github.event_name == 'pull_request' && |
| 156 | + ( |
| 157 | + contains(github.event.pull_request.title, '[run ci]') || |
| 158 | + contains(github.event.pull_request.body, '[run ci]') || |
| 159 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 160 | + ) |
| 161 | + ) |
| 162 | + runs-on: ubuntu-latest |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v3 |
| 165 | + - name: Set up Python 3.11 |
| 166 | + uses: actions/setup-python@v3 |
| 167 | + with: |
| 168 | + python-version: 3.11 |
| 169 | + - name: Install dependencies |
| 170 | + run: | |
| 171 | + python -m pip install pip==$(sed -nE 's/pip = "==(.*)"/\1/p' Pipfile) |
| 172 | + ISORT_VERSION=$(sed -nE 's/isort = "==(.*)"/\1/p' Pipfile) |
| 173 | + pip install isort==$ISORT_VERSION |
| 174 | + - name: Analysing the code with isort |
| 175 | + run: | |
| 176 | + isort --check-only $(git rev-parse --show-toplevel)/ --profile black |
| 177 | +
|
| 178 | + containerBuild: |
| 179 | + if: | |
| 180 | + github.event_name == 'push' || |
| 181 | + ( |
| 182 | + github.event_name == 'pull_request' && |
| 183 | + ( |
| 184 | + contains(github.event.pull_request.title, '[run ci]') || |
| 185 | + contains(github.event.pull_request.body, '[run ci]') || |
| 186 | + contains(join(github.event.pull_request.labels.*.name), 'run-ci') |
| 187 | + ) |
| 188 | + ) |
| 189 | + runs-on: ubuntu-latest |
| 190 | + needs: |
| 191 | + - pyTest |
| 192 | + - pyLint |
| 193 | + - flake8 |
| 194 | + - isort |
| 195 | + steps: |
| 196 | + - uses: actions/checkout@v3 |
| 197 | + - name: Build the Docker image |
| 198 | + run: make establish_config && docker build -f Dockerfile . -t techsupportbot:$(date +%s) |
| 199 | + |
| 200 | + close_pyTest: |
| 201 | + if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' |
| 202 | + runs-on: ubuntu-latest |
| 203 | + needs: |
| 204 | + - pyTest |
| 205 | + permissions: |
| 206 | + contents: write |
| 207 | + pull-requests: write |
| 208 | + steps: |
| 209 | + - name: Dependabot metadata |
| 210 | + id: dependabot-metadata |
| 211 | + uses: dependabot/fetch-metadata@v2 |
| 212 | + with: |
| 213 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 214 | + - name: Merge PR |
| 215 | + if: steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' && steps.dependabot-metadata.outputs.dependency-names == 'pytest' |
| 216 | + run: gh pr merge --auto --merge "$PR_URL" |
| 217 | + env: |
| 218 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 219 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 220 | + |
| 221 | + close_pyLint: |
| 222 | + if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' |
| 223 | + runs-on: ubuntu-latest |
| 224 | + needs: |
| 225 | + - pyLint |
| 226 | + permissions: |
| 227 | + contents: write |
| 228 | + pull-requests: write |
| 229 | + steps: |
| 230 | + - name: Dependabot metadata |
| 231 | + id: dependabot-metadata |
| 232 | + uses: dependabot/fetch-metadata@v2 |
| 233 | + with: |
| 234 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 235 | + - name: Merge PR |
| 236 | + if: steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' && steps.dependabot-metadata.outputs.dependency-names == 'pylint' |
| 237 | + run: gh pr merge --auto --merge "$PR_URL" |
| 238 | + env: |
| 239 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 240 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 241 | + |
| 242 | + close_flake8: |
| 243 | + if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' |
| 244 | + runs-on: ubuntu-latest |
| 245 | + needs: |
| 246 | + - flake8 |
| 247 | + permissions: |
| 248 | + contents: write |
| 249 | + pull-requests: write |
| 250 | + steps: |
| 251 | + - name: Dependabot metadata |
| 252 | + id: dependabot-metadata |
| 253 | + uses: dependabot/fetch-metadata@v2 |
| 254 | + with: |
| 255 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 256 | + - name: Merge PR |
| 257 | + if: steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' && steps.dependabot-metadata.outputs.dependency-names == 'flake8' |
| 258 | + run: gh pr merge --auto --merge "$PR_URL" |
| 259 | + env: |
| 260 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 261 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 262 | + |
| 263 | + close_isort: |
| 264 | + if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' |
| 265 | + runs-on: ubuntu-latest |
| 266 | + needs: |
| 267 | + - isort |
| 268 | + permissions: |
| 269 | + contents: write |
| 270 | + pull-requests: write |
| 271 | + steps: |
| 272 | + - name: Dependabot metadata |
| 273 | + id: dependabot-metadata |
| 274 | + uses: dependabot/fetch-metadata@v2 |
| 275 | + with: |
| 276 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 277 | + - name: Merge PR |
| 278 | + if: steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' && steps.dependabot-metadata.outputs.dependency-names == 'isort' |
| 279 | + run: gh pr merge --auto --merge "$PR_URL" |
| 280 | + env: |
| 281 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 282 | + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments