Skip to content

Commit ddf7d88

Browse files
authored
Merge pull request #8689 from bluetech/backport-8681
[6.2.x] ci: few security/permissions improvements
2 parents 8317542 + 733f802 commit ddf7d88

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ on:
1414
- master
1515
- "[0-9]+.[0-9]+.x"
1616

17+
# Set permissions at the job level.
18+
permissions: {}
19+
1720
jobs:
1821
build:
1922
runs-on: ${{ matrix.os }}
2023
timeout-minutes: 30
24+
permissions:
25+
contents: read
2126

2227
strategy:
2328
fail-fast: false
@@ -137,10 +142,13 @@ jobs:
137142
- uses: actions/checkout@v2
138143
with:
139144
fetch-depth: 0
145+
persist-credentials: false
146+
140147
- name: Set up Python ${{ matrix.python }}
141148
uses: actions/setup-python@v2
142149
with:
143150
python-version: ${{ matrix.python }}
151+
144152
- name: Install dependencies
145153
run: |
146154
python -m pip install --upgrade pip
@@ -171,52 +179,70 @@ jobs:
171179

172180
linting:
173181
runs-on: ubuntu-latest
182+
permissions:
183+
contents: read
184+
174185
steps:
175186
- uses: actions/checkout@v2
187+
with:
188+
persist-credentials: false
189+
176190
- uses: actions/setup-python@v2
191+
177192
- name: set PY
178193
run: echo "name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
194+
179195
- uses: actions/cache@v2
180196
with:
181197
path: ~/.cache/pre-commit
182198
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
199+
183200
- name: Install dependencies
184201
run: |
185202
python -m pip install --upgrade pip
186203
pip install tox
204+
187205
- run: tox -e linting
188206

189207
deploy:
190208
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pytest-dev/pytest'
191209

192210
runs-on: ubuntu-latest
193211
timeout-minutes: 30
212+
permissions:
213+
contents: write
194214

195215
needs: [build]
196216

197217
steps:
198218
- uses: actions/checkout@v2
199219
with:
200220
fetch-depth: 0
221+
persist-credentials: false
222+
201223
- name: Set up Python
202224
uses: actions/setup-python@v2
203225
with:
204226
python-version: "3.7"
227+
205228
- name: Install dependencies
206229
run: |
207230
python -m pip install --upgrade pip
208231
pip install --upgrade wheel setuptools tox
232+
209233
- name: Build package
210234
run: |
211235
python setup.py sdist bdist_wheel
236+
212237
- name: Publish package to PyPI
213238
uses: pypa/gh-action-pypi-publish@master
214239
with:
215240
user: __token__
216241
password: ${{ secrets.pypi_token }}
242+
217243
- name: Publish GitHub release notes
218244
env:
219-
GH_RELEASE_NOTES_TOKEN: ${{ secrets.release_notes }}
245+
GH_RELEASE_NOTES_TOKEN: ${{ github.token }}
220246
run: |
221247
sudo apt-get install pandoc
222248
tox -e publish-gh-release-notes

.github/workflows/release-on-comment.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@ on:
77
issue_comment:
88
types: [created, edited]
99

10+
# Set permissions at the job level.
11+
permissions: {}
12+
1013
jobs:
1114
build:
1215
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
issues: write
1319

1420
if: (github.event.comment && startsWith(github.event.comment.body, '@pytestbot please')) || (github.event.issue && !github.event.comment && startsWith(github.event.issue.body, '@pytestbot please'))
1521

1622
steps:
1723
- uses: actions/checkout@v2
1824
with:
1925
fetch-depth: 0
26+
persist-credentials: false
2027

2128
- name: Set up Python
2229
uses: actions/setup-python@v2
2330
with:
2431
python-version: "3.8"
32+
2533
- name: Install dependencies
2634
run: |
2735
python -m pip install --upgrade pip
2836
pip install --upgrade setuptools tox
37+
2938
- name: Prepare release
3039
run: |
31-
tox -e release-on-comment -- $GITHUB_EVENT_PATH ${{ secrets.chatops }}
40+
tox -e release-on-comment -- $GITHUB_EVENT_PATH ${{ github.token }}

scripts/release-on-comment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
2424
After that, it will create a release using the `release` tox environment, and push a new PR.
2525
26-
**Secret**: currently the secret is defined in the @pytestbot account, which the core maintainers
27-
have access to. There we created a new secret named `chatops` with write access to the repository.
26+
**Token**: currently the token from the GitHub Actions is used, pushed with
27+
`pytest bot <[email protected]>` commit author.
2828
"""
2929
import argparse
3030
import json

scripts/report-coverage.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44
set -x
55

6-
if [ -z "$TOXENV" ]; then
6+
# Install coverage.
7+
if [[ -z ${TOXENV+x} || -z $TOXENV ]]; then
78
python -m pip install coverage
89
else
910
# Add last TOXENV to $PATH.
1011
PATH="$PWD/.tox/${TOXENV##*,}/bin:$PATH"
1112
fi
1213

14+
# Run coverage.
1315
python -m coverage combine
1416
python -m coverage xml
1517
python -m coverage report -m
18+
19+
# Download and verify latest Codecov bash uploader.
1620
# Set --connect-timeout to work around https://github.com/curl/curl/issues/4461
17-
curl -S -L --connect-timeout 5 --retry 6 -s https://codecov.io/bash -o codecov-upload.sh
18-
bash codecov-upload.sh -Z -X fix -f coverage.xml "$@"
21+
curl --silent --show-error --location --connect-timeout 5 --retry 6 -o codecov https://codecov.io/bash
22+
VERSION=$(grep --only-matching 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2)
23+
if command -v sha256sum; then
24+
sha256sum --check --strict --ignore-missing --quiet <(curl --silent "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA256SUM")
25+
else
26+
shasum --algorithm 256 --check --strict --ignore-missing --quiet <(curl --silent "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA256SUM")
27+
fi
28+
29+
# Upload coverage.
30+
bash codecov -Z -X fix -f coverage.xml "$@"

0 commit comments

Comments
 (0)