Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/scripts/tests/test_pr_status_labels_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import re
from pathlib import Path
from typing import Any

import pytest
import yaml

WORKFLOW_PATH = Path(__file__).parents[2] / "workflows" / "pr-status-labels.yml"
TEST_PARSER_PATH = Path(__file__).parents[2] / "workflows" / "test-parser.yml"


@pytest.fixture(name="workflow")
def workflow_fixture() -> dict[Any, Any]:
return yaml.safe_load(WORKFLOW_PATH.read_text())


def test_runs_on_events_that_change_status(workflow: dict[Any, Any]) -> None:
# PyYAML reads the bare key `on` as the boolean True.
assert workflow[True] == {
"pull_request_target": {
"types": ["opened", "reopened", "ready_for_review", "synchronize"]
}
}


def test_calls_shared_workflow_pinned_to_commit(workflow: dict[Any, Any]) -> None:
uses = workflow["jobs"]["pr-status-labels"]["uses"]

assert re.fullmatch(
r"aws/aws-durable-execution-ci/\.github/workflows/pr-status-labels\.yml"
r"@[0-9a-f]{40}",
uses,
)


def test_grants_only_label_permissions(workflow: dict[Any, Any]) -> None:
assert workflow["permissions"] == {}
assert workflow["jobs"]["pr-status-labels"]["permissions"] == {
"contents": "read",
"pull-requests": "write",
}


def test_passes_no_secrets(workflow: dict[Any, Any]) -> None:
# pull_request_target runs for fork pull requests with the base
# repository's token, so the job gets no secrets.
assert "secrets" not in workflow["jobs"]["pr-status-labels"]


def test_workflow_triggers_script_tests() -> None:
parser = yaml.safe_load(TEST_PARSER_PATH.read_text())
path = ".github/workflows/pr-status-labels.yml"

assert path in parser[True]["pull_request"]["paths"]
assert path in parser[True]["push"]["paths"]
14 changes: 14 additions & 0 deletions .github/workflows/pr-status-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: PR Status Labels

on:
pull_request_target:
types: [opened, reopened, ready_for_review, synchronize]
Comment thread
yaythomas marked this conversation as resolved.
Resolved

permissions: {}

jobs:
pr-status-labels:
permissions:
contents: read
pull-requests: write
uses: aws/aws-durable-execution-ci/.github/workflows/pr-status-labels.yml@c28fdc7df300996309e282ee6bfe54658ba53351 # v0.7.0
3 changes: 3 additions & 0 deletions .github/workflows/test-parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- '.github/workflows/closed-issue-comment.yml'
- '.github/workflows/issue-triage.yml'
- '.github/workflows/notify.yml'
- '.github/workflows/pr-status-labels.yml'
Comment thread
yaythomas marked this conversation as resolved.
Resolved
- '.github/workflows/stale-issue-closer.yml'
- '.github/workflows/opentelemetry-conformance-tests.yml'
- '.github/workflows/test-parser.yml'
Expand All @@ -34,6 +35,7 @@ on:
- '.github/workflows/closed-issue-comment.yml'
- '.github/workflows/issue-triage.yml'
- '.github/workflows/notify.yml'
- '.github/workflows/pr-status-labels.yml'
- '.github/workflows/stale-issue-closer.yml'
- '.github/workflows/opentelemetry-conformance-tests.yml'
- '.github/workflows/test-parser.yml'
Expand Down Expand Up @@ -80,6 +82,7 @@ jobs:
.github/scripts/tests/test_opentelemetry_conformance_workflow.py \
.github/scripts/tests/test_parse_sdk_branch.py \
.github/scripts/tests/test_parse_testing_version.py \
.github/scripts/tests/test_pr_status_labels_workflow.py \
.github/scripts/tests/test_release_workflow_dependencies.py \
.github/scripts/tests/e2e/test_ecr_release_workflow.py \
.github/scripts/tests/test_shared_workflow_runners.py