Skip to content

Commit df6f3c4

Browse files
test: cover pull request label creation cleanup (#62)
* test: cover pull request label creation cleanup Add an end-to-end scenario for action-pull-request that exercises create_missing_labels with a zzz-prefixed label containing /, verifies the label is attached to the created PR, and deletes the temporary label during cleanup so test artifacts do not pollute repository labels. Make the generated branch and label names rerun-safe by including github.run_attempt, preventing stale artifacts from causing false positives or rerun failures. * fix: quote branch names in e2e action pull request workflow --------- Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent 746a6a7 commit df6f3c4

2 files changed

Lines changed: 124 additions & 1 deletion

File tree

.github/workflows/e2e-action-pull-request.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,129 @@ jobs:
399399
fi
400400
git push origin --delete test/e2e-pr-project-${{ github.run_id }} 2>/dev/null || true
401401
402+
pull-request-with-created-labels:
403+
name: Pull request with created labels
404+
needs: [preflight]
405+
runs-on: ubuntu-24.04-arm
406+
env:
407+
TEST_ID: ${{ github.run_id }}-${{ github.run_attempt }}
408+
TEST_LABEL: zzz-e2e/action-pull-request-${{ github.run_id }}-${{ github.run_attempt }}
409+
steps:
410+
- name: Checkout repository
411+
uses: actions/checkout@v7
412+
with:
413+
fetch-depth: 0
414+
415+
- name: Create test branch with a commit
416+
run: |
417+
git config user.name "github-actions[bot]"
418+
git config user.email "github-actions[bot]@users.noreply.github.com"
419+
git checkout -b "test/e2e-pr-labels-${TEST_ID}"
420+
echo "E2E PR label creation test $(date -u)" > e2e-pr-label-test.txt
421+
git add -f e2e-pr-label-test.txt
422+
git commit -m "test(pull-request): label creation PR test"
423+
git push origin "test/e2e-pr-labels-${TEST_ID}"
424+
425+
- name: Checkout action under test
426+
if: ${{ inputs.mode == 'ref' }}
427+
uses: actions/checkout@v7
428+
with:
429+
repository: devops-infra/action-pull-request
430+
ref: ${{ inputs.action_ref }}
431+
path: .tmp/action-pull-request
432+
433+
- name: Create pull request with created labels
434+
if: ${{ inputs.mode == 'ref' }}
435+
id: pr
436+
uses: ./.tmp/action-pull-request
437+
with:
438+
github_token: ${{ secrets.GITHUB_TOKEN }}
439+
title: "test(pull-request): label creation test - safe to close"
440+
body: "Automated end-to-end test for missing label creation."
441+
target_branch: master
442+
label: ${{ env.TEST_LABEL }}
443+
create_missing_labels: "true"
444+
445+
- name: Create pull request via docker image
446+
if: ${{ inputs.mode == 'image' }}
447+
env:
448+
ACTION_IMAGE: devopsinfra/action-pull-request:${{ inputs.image_tag }}
449+
run: |
450+
if [ -z "${{ inputs.image_tag }}" ]; then
451+
echo "image_tag is required when mode=image"
452+
exit 1
453+
fi
454+
mkdir -p .tmp
455+
: > .tmp/e2e-pr-labels.outputs
456+
docker pull "${ACTION_IMAGE}"
457+
docker run --rm \
458+
-e GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
459+
-e GITHUB_REPOSITORY="${{ github.repository }}" \
460+
-e GITHUB_WORKSPACE=/github/workspace \
461+
-e GITHUB_ACTOR="${{ github.actor }}" \
462+
-e GITHUB_OUTPUT=/github/workspace/.tmp/e2e-pr-labels.outputs \
463+
-e INPUT_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
464+
-e INPUT_SOURCE_BRANCH="test/e2e-pr-labels-${TEST_ID}" \
465+
-e INPUT_TITLE="test(pull-request): label creation test - safe to close" \
466+
-e INPUT_BODY="Automated end-to-end test for missing label creation." \
467+
-e INPUT_TARGET_BRANCH=master \
468+
-e INPUT_LABEL="${TEST_LABEL}" \
469+
-e INPUT_CREATE_MISSING_LABELS=true \
470+
-v "$PWD:/github/workspace" \
471+
-w /github/workspace \
472+
"${ACTION_IMAGE}"
473+
474+
- name: Verify outputs
475+
if: ${{ inputs.mode == 'ref' }}
476+
run: |
477+
echo "url=${{ steps.pr.outputs.url }}"
478+
echo "pr_number=${{ steps.pr.outputs.pr_number }}"
479+
test -n "${{ steps.pr.outputs.url }}"
480+
test -n "${{ steps.pr.outputs.pr_number }}"
481+
482+
- name: Verify outputs from docker image
483+
if: ${{ inputs.mode == 'image' }}
484+
run: |
485+
URL="$(sed -n 's/^url=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
486+
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
487+
echo "url=${URL}"
488+
echo "pr_number=${PR_NUMBER}"
489+
test -n "${URL}"
490+
test -n "${PR_NUMBER}"
491+
492+
- name: Verify label assignment
493+
env:
494+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
495+
run: |
496+
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
497+
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-labels.outputs ]; then
498+
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
499+
fi
500+
test -n "${PR_NUMBER}"
501+
502+
LABEL_FOUND="$(
503+
gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json labels \
504+
| jq -r --arg label "${TEST_LABEL}" 'any(.labels[]?; .name == $label)'
505+
)"
506+
507+
test "${LABEL_FOUND}" = "true"
508+
509+
- name: Cleanup - close PR, delete label, and delete test branch
510+
if: ${{ always() }}
511+
env:
512+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
513+
run: |
514+
PR_NUMBER="${{ steps.pr.outputs.pr_number }}"
515+
if [ -z "$PR_NUMBER" ] && [ -f .tmp/e2e-pr-labels.outputs ]; then
516+
PR_NUMBER="$(sed -n 's/^pr_number=//p' .tmp/e2e-pr-labels.outputs | tail -1)"
517+
fi
518+
if [ -n "$PR_NUMBER" ]; then
519+
gh pr close "$PR_NUMBER" --repo "${{ github.repository }}" 2>/dev/null || true
520+
fi
521+
ENCODED_LABEL="$(python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "${TEST_LABEL}")"
522+
gh api --method DELETE "repos/${{ github.repository }}/labels/${ENCODED_LABEL}" 2>/dev/null || true
523+
git push origin --delete "test/e2e-pr-labels-${TEST_ID}" 2>/dev/null || true
524+
402525
pull-request-with-repository-path:
403526
name: Pull request using custom checkout path and explicit repository
404527
needs: [preflight]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In Slavic mythology, Triglav represents three realms. That maps well to this fra
2525
| Action | Workflow | Test Coverage |
2626
|------------------------------------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2727
| `devops-infra/action-commit-push` | `.github/workflows/e2e-action-commit-push.yml` | branch creation/push, custom message/prefix, custom commit name/email, empty commit mode, amend with force-with-lease, GPG and SSH signed commits, output verification, cleanup |
28-
| `devops-infra/action-pull-request` | `.github/workflows/e2e-action-pull-request.yml` | PR creation/update paths, custom title/body, project assignment, draft + `get_diff`, `repository` + `repository_path`, output verification, cleanup |
28+
| `devops-infra/action-pull-request` | `.github/workflows/e2e-action-pull-request.yml` | PR creation/update paths, custom title/body, missing-label creation, project assignment, draft + `get_diff`, `repository` + `repository_path`, output verification, cleanup |
2929
| `devops-infra/action-format-hcl` | `.github/workflows/e2e-action-format-hcl.yml` | check mode pass/fail, write mode, list/diff mode, malformed input detection |
3030
| `devops-infra/action-container-structure-test` | `.github/workflows/e2e-action-container-structure-test.yml` | text/json/junit output modes, report file creation, multi-config execution, output counters |
3131
| `devops-infra/action-terraform-copy-vars` | `.github/workflows/e2e-action-terraform-copy-vars.yml` | variable propagation across modules, custom path inputs, strict missing-variable failure mode |

0 commit comments

Comments
 (0)