1name: CI
2
3on: [ push, pull_request ]
4
5permissions:
6  contents: read
7
8jobs:
9  lint-pr:
10    if: github.event_name == 'pull_request'
11    runs-on: ubuntu-latest
12    steps:
13      - uses: actions/checkout@v2
14        with:
15          persist-credentials: false
16      - uses: TrueBrain/actions-flake8@9a43ff1b2c7b96f3edffc48a49973ce3de116ba1
17        # mirrored at https://github.com/mitmproxy/mitmproxy/settings/actions
18  lint-local:
19    if: github.event_name == 'push'
20    runs-on: ubuntu-latest
21    steps:
22      - uses: actions/checkout@v2
23        with:
24          persist-credentials: false
25      - uses: actions/setup-python@v2
26        with:
27          python-version: '3.9'
28      - run: pip install tox
29      - run: tox -e flake8
30  filename-matching:
31    runs-on: ubuntu-latest
32    steps:
33      - uses: actions/checkout@v2
34        with:
35          persist-credentials: false
36      - uses: actions/setup-python@v2
37        with:
38          python-version: '3.9'
39      - run: pip install tox
40      - run: tox -e filename_matching
41  mypy:
42    runs-on: ubuntu-latest
43    steps:
44      - uses: actions/checkout@v2
45        with:
46          persist-credentials: false
47      - uses: actions/setup-python@v2
48        with:
49          python-version: '3.9'
50      - run: pip install tox
51      - run: tox -e mypy
52  individual-coverage:
53    runs-on: ubuntu-latest
54    steps:
55      - uses: actions/checkout@v2
56        with:
57          persist-credentials: false
58          fetch-depth: 0
59      - uses: actions/setup-python@v2
60        with:
61          python-version: '3.9'
62      - run: pip install tox
63      - run: tox -e individual_coverage
64  test:
65    strategy:
66      fail-fast: false
67      matrix:
68        include:
69          - os: windows-latest
70            py: 3.9
71          - os: macos-latest
72            py: 3.9
73          - os: ubuntu-latest
74            py: 3.9
75          - os: ubuntu-latest
76            py: 3.8
77    runs-on: ${{ matrix.os }}
78    steps:
79      - run: printenv
80      - uses: actions/checkout@v2
81        with:
82          persist-credentials: false
83          fetch-depth: 0
84      - uses: actions/setup-python@v2
85        with:
86          python-version: ${{ matrix.py }}
87      - run: pip install tox
88      - run: tox -e py
89      - uses: codecov/codecov-action@a1ed4b322b4b38cb846afb5a0ebfa17086917d27
90        # mirrored below and at https://github.com/mitmproxy/mitmproxy/settings/actions
91        with:
92          file: ./coverage.xml
93          name: ${{ matrix.os }}
94
95  build:
96    strategy:
97      fail-fast: false
98      matrix:
99        include:
100          - image: macos-10.15
101            platform: macos
102          - image: windows-2019
103            platform: windows
104          - image: ubuntu-18.04  # Old Ubuntu version for old glibc
105            platform: linux
106    runs-on: ${{ matrix.image }}
107    env:
108      CI_BUILD_WHEEL: ${{ matrix.platform == 'linux' }}
109      CI_BUILD_PYINSTALLER: 1
110      CI_BUILD_WININSTALLER: ${{ matrix.platform == 'windows' }}
111      CI_BUILD_KEY: ${{ secrets.CI_BUILD_KEY }}
112    steps:
113      - uses: actions/checkout@v2
114        with:
115          persist-credentials: false
116          fetch-depth: 0
117      - uses: actions/setup-python@v2
118        with:
119          python-version: '3.9'
120      - if: matrix.platform == 'windows'
121        uses: actions/cache@v2
122        with:
123          path: release/installbuilder/setup
124          key: installbuilder
125      - run: pip install -e .[dev]
126      - run: python release/cibuild.py build
127      # artifacts must have different names, see https://github.com/actions/upload-artifact/issues/24
128      - uses: actions/upload-artifact@v2
129        with:
130          name: binaries.${{ matrix.platform }}
131          path: release/dist
132
133  test-web-ui:
134    runs-on: ubuntu-latest
135    steps:
136      - uses: actions/checkout@v2
137        with:
138          persist-credentials: false
139      - run: git rev-parse --abbrev-ref HEAD
140      - uses: actions/setup-node@v1
141      - id: yarn-cache
142        run: echo "::set-output name=dir::$(yarn cache dir)"
143      - uses: actions/cache@v1
144        with:
145          path: ${{ steps.yarn-cache.outputs.dir }}
146          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
147          restore-keys: |
148            ${{ runner.os }}-yarn-
149      - working-directory: ./web
150        run: yarn
151      - working-directory: ./web
152        run: npm test
153      - uses: codecov/codecov-action@a1ed4b322b4b38cb846afb5a0ebfa17086917d27
154        # mirrored above and at https://github.com/mitmproxy/mitmproxy/settings/actions
155        with:
156          file: ./web/coverage/coverage-final.json
157          name: web
158
159  docs:
160    runs-on: ubuntu-latest
161    steps:
162      - uses: actions/checkout@v2
163        with:
164          persist-credentials: false
165      - uses: actions/setup-python@v2
166        with:
167          python-version: '3.9'
168      - run: |
169          wget -q https://github.com/gohugoio/hugo/releases/download/v0.83.1/hugo_extended_0.83.1_Linux-64bit.deb
170          echo "9487ea3b80f8ddd0ba600d42850b96b6a8b0bb9b41bc08cb285635ebbd41328d hugo_extended_0.83.1_Linux-64bit.deb" | sha256sum -c
171          sudo dpkg -i hugo*.deb
172      - run: pip install -e .[dev]
173      - run: ./docs/build.py
174      - uses: actions/upload-artifact@v2
175        with:
176          name: docs
177          path: docs/public
178
179  # Separate from everything else because slow.
180  build-and-deploy-docker:
181    if: github.repository == 'mitmproxy/mitmproxy' && (
182      github.ref == 'refs/heads/main' ||
183      github.ref == 'refs/heads/dockertest' ||
184      startsWith(github.ref, 'refs/tags/')
185      )
186    environment: deploy-docker
187    needs:
188     - test
189     - test-web-ui
190     - build
191     - docs
192    runs-on: ubuntu-latest
193    env:
194      CI_BUILD_DOCKER: 1
195      DOCKER_USERNAME: mitmbot
196      DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
197    steps:
198      - uses: actions/checkout@v2
199        with:
200          persist-credentials: false
201      - uses: actions/setup-python@v2
202        with:
203          python-version: '3.9'
204      - uses: actions/download-artifact@v2
205        with:
206          name: binaries.linux
207          path: release/dist
208      - uses: docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480
209      - uses: docker/setup-buildx-action@b1f1f719c7cd5364be7c82e366366da322d01f7c
210      - run: pip install -e .[dev]
211      - run: python release/cibuild.py build
212      - run: python release/cibuild.py upload
213
214  deploy:
215    # This action has access to our AWS keys, so we are extra careful here.
216    # In particular, we don't blindly `pip install` anything to minimize the risk of supply chain attacks.
217    if: github.repository == 'mitmproxy/mitmproxy' && github.event_name == 'push'
218    environment: deploy
219    needs:
220      - test
221      - test-web-ui
222      - build
223      - docs
224    runs-on: ubuntu-latest
225    env:
226      TWINE_USERNAME: mitmproxy
227      TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
228      AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
229      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
230      AWS_DEFAULT_REGION: us-west-2
231    steps:
232      - uses: actions/checkout@v2
233        with:
234          persist-credentials: false
235      - uses: actions/setup-python@v2
236        with:
237          python-version: '3.9'
238      - run: sudo apt-get update
239      - run: sudo apt-get install -y twine awscli
240      - uses: actions/download-artifact@v2
241        with:
242          path: release/dist
243      - run: mv release/dist/docs docs/public
244      # move artifacts from their subfolders into release/dist
245      - run: find release/dist -mindepth 2 -type f -exec mv {} release/dist \;
246      # and then delete the empty folders
247      - run: find release/dist -type d -empty -delete
248      - run: ls release/dist
249      - run: ./release/deploy.py
250