Skip to content

Commit ff6d297

Browse files
authored
Merge pull request #8681 from bluetech/ci-permissions
ci: few security/permissions improvements
2 parents d52cd08 + 864a2bc commit ff6d297

7 files changed

+80
-13
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ on:
1313
branches:
1414
- main
1515
- "[0-9]+.[0-9]+.x"
16+
1617
env:
1718
PYTEST_ADDOPTS: "--color=yes"
1819

20+
# Set permissions at the job level.
21+
permissions: {}
22+
1923
jobs:
2024
build:
2125
runs-on: ${{ matrix.os }}
2226
timeout-minutes: 30
27+
permissions:
28+
contents: read
2329

2430
strategy:
2531
fail-fast: false
@@ -139,10 +145,13 @@ jobs:
139145
- uses: actions/checkout@v2
140146
with:
141147
fetch-depth: 0
148+
persist-credentials: false
149+
142150
- name: Set up Python ${{ matrix.python }}
143151
uses: actions/setup-python@v2
144152
with:
145153
python-version: ${{ matrix.python }}
154+
146155
- name: Install dependencies
147156
run: |
148157
python -m pip install --upgrade pip
@@ -164,52 +173,70 @@ jobs:
164173

165174
linting:
166175
runs-on: ubuntu-latest
176+
permissions:
177+
contents: read
178+
167179
steps:
168180
- uses: actions/checkout@v2
181+
with:
182+
persist-credentials: false
183+
169184
- uses: actions/setup-python@v2
185+
170186
- name: set PY
171187
run: echo "name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
188+
172189
- uses: actions/cache@v2
173190
with:
174191
path: ~/.cache/pre-commit
175192
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
193+
176194
- name: Install dependencies
177195
run: |
178196
python -m pip install --upgrade pip
179197
pip install tox
198+
180199
- run: tox -e linting
181200

182201
deploy:
183202
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && github.repository == 'pytest-dev/pytest'
184203

185204
runs-on: ubuntu-latest
186205
timeout-minutes: 30
206+
permissions:
207+
contents: write
187208

188209
needs: [build]
189210

190211
steps:
191212
- uses: actions/checkout@v2
192213
with:
193214
fetch-depth: 0
215+
persist-credentials: false
216+
194217
- name: Set up Python
195218
uses: actions/setup-python@v2
196219
with:
197220
python-version: "3.7"
221+
198222
- name: Install dependencies
199223
run: |
200224
python -m pip install --upgrade pip
201225
pip install --upgrade wheel setuptools tox
226+
202227
- name: Build package
203228
run: |
204229
python setup.py sdist bdist_wheel
230+
205231
- name: Publish package to PyPI
206232
uses: pypa/gh-action-pypi-publish@master
207233
with:
208234
user: __token__
209235
password: ${{ secrets.pypi_token }}
236+
210237
- name: Publish GitHub release notes
211238
env:
212-
GH_RELEASE_NOTES_TOKEN: ${{ secrets.release_notes }}
239+
GH_RELEASE_NOTES_TOKEN: ${{ github.token }}
213240
run: |
214241
sudo apt-get install pandoc
215242
tox -e publish-gh-release-notes

.github/workflows/prepare-release-pr.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ on:
1212
required: true
1313
default: 'no'
1414

15+
# Set permissions at the job level.
16+
permissions: {}
17+
1518
jobs:
1619
build:
1720
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
pull-requests: write
1824

1925
steps:
2026
- uses: actions/checkout@v2
2127
with:
2228
fetch-depth: 0
29+
persist-credentials: false
2330

2431
- name: Set up Python
2532
uses: actions/setup-python@v2
@@ -34,9 +41,9 @@ jobs:
3441
- name: Prepare release PR (minor/patch release)
3542
if: github.event.inputs.major == 'no'
3643
run: |
37-
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ secrets.chatops }}
44+
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }}
3845
3946
- name: Prepare release PR (major release)
4047
if: github.event.inputs.major == 'yes'
4148
run: |
42-
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ secrets.chatops }} --major
49+
tox -e prepare-release-pr -- ${{ github.event.inputs.branch }} ${{ github.token }} --major

.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 }}

.github/workflows/update-plugin-list.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@ on:
77
- cron: '0 0 * * 0'
88
workflow_dispatch:
99

10+
# Set permissions at the job level.
11+
permissions: {}
12+
1013
jobs:
1114
createPullRequest:
1215
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
1320
steps:
1421
- name: Checkout
1522
uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
25+
1626
- name: Setup Python
1727
uses: actions/setup-python@v2
1828
with:
1929
python-version: 3.8
30+
2031
- name: Install dependencies
2132
run: |
2233
python -m pip install --upgrade pip
2334
pip install packaging requests tabulate[widechars]
35+
2436
- name: Update Plugin List
2537
run: python scripts/update-plugin-list.py
38+
2639
- name: Create Pull Request
2740
uses: peter-evans/create-pull-request@2455e1596942c2902952003bbb574afbbe2ab2e6
2841
with:

scripts/prepare-release-pr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
1010
After that, it will create a release using the `release` tox environment, and push a new PR.
1111
12-
**Secret**: currently the secret is defined in the @pytestbot account,
13-
which the core maintainers have access to. There we created a new secret named `chatops`
14-
with write access to the repository.
12+
**Token**: currently the token from the GitHub Actions is used, pushed with
13+
`pytest bot <[email protected]>` commit author.
1514
"""
1615
import argparse
1716
import re

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/upload-coverage.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
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 xml
16+
17+
# Download and verify latest Codecov bash uploader.
1418
# Set --connect-timeout to work around https://github.com/curl/curl/issues/4461
15-
curl -S -L --connect-timeout 5 --retry 6 -s https://codecov.io/bash -o codecov-upload.sh
16-
bash codecov-upload.sh -Z -X fix -f coverage.xml "$@"
19+
curl --silent --show-error --location --connect-timeout 5 --retry 6 -o codecov https://codecov.io/bash
20+
VERSION=$(grep --only-matching 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2)
21+
if command -v sha256sum; then
22+
sha256sum --check --strict --ignore-missing --quiet <(curl --silent "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA256SUM")
23+
else
24+
shasum --algorithm 256 --check --strict --ignore-missing --quiet <(curl --silent "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA256SUM")
25+
fi
26+
27+
# Upload coverage.
28+
bash codecov -Z -X fix -f coverage.xml "$@"

0 commit comments

Comments
 (0)