Update docstring-labeler.yml workflow to safely run in PRs from forks (#4146)

This commit is contained in:
Silvano Cerza 2023-02-16 16:02:41 +01:00 committed by GitHub
parent d27f372b67
commit 689f2cd250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -30,8 +30,14 @@ def docstrings_checksum(python_files: Iterator[Path]):
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--root", help="Haystack root folder", required=True, type=Path)
args = parser.parse_args()
# Get all Haystack and rest_api python files
root = Path(__file__).parent.parent.parent
root: Path = args.root.absolute()
haystack_files = root.glob("haystack/**/*.py")
rest_api_files = root.glob("rest_api/**/*.py")

View File

@ -1,14 +1,11 @@
name: Add label on docstrings edit
on:
pull_request:
pull_request_target:
paths:
- "haystack/**/*.py"
- "rest_api/**/*.py"
permissions:
pull-requests: write
jobs:
label:
runs-on: ubuntu-latest
@ -19,6 +16,12 @@ jobs:
with:
ref: ${{ github.base_ref }}
- name: Copy file
# We copy our script after base ref checkout so we keep executing
# the same version even after checking out the HEAD ref.
# This is done to prevent executing malicious code in forks' PRs.
run: cp .github/utils/docstrings_checksum.py "${{ runner.temp }}/docstrings_checksum.py"
- name: Setup Python
uses: actions/setup-python@v4
with:
@ -27,7 +30,7 @@ jobs:
- name: Get docstrings
id: base-docstrings
run: |
CHECKSUM=$(python .github/utils/docstrings_checksum.py)
CHECKSUM=$(python "${{ runner.temp }}/docstrings_checksum.py" --root "${{ env.GITHUB_WORKSPACE }}")
echo "checksum=$CHECKSUM" >> "$GITHUB_OUTPUT"
- name: Checkout HEAD commit
@ -36,7 +39,7 @@ jobs:
- name: Get docstrings
id: head-docstrings
run: |
CHECKSUM=$(python .github/utils/docstrings_checksum.py)
CHECKSUM=$(python "${{ runner.temp }}/docstrings_checksum.py" --root "${{ env.GITHUB_WORKSPACE }}")
echo "checksum=$CHECKSUM" >> "$GITHUB_OUTPUT"
- name: Check if we should label