Skip to content

Commit d439524

Browse files
committed
Fix: Prevent duplicate workflow runs for issues opened with enhancement label
- Check if opened event has enhancement label already present - Skip opened event if label exists (labeled event will handle it) - Set cancel-in-progress: true to cancel older runs - Prevents duplicate runs when both opened and labeled events fire
1 parent 099707b commit d439524

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/feature-request-enhance.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ on:
1111
type: string
1212

1313
# Prevent parallel runs for the same issue
14+
# When both 'opened' and 'labeled' events fire, cancel the older run
1415
concurrency:
1516
group: enhance-feature-request-${{ github.event.issue.number || inputs.issue_number }}
16-
cancel-in-progress: false
17+
cancel-in-progress: true
1718

1819
permissions:
1920
issues: write
@@ -27,6 +28,7 @@ jobs:
2728
has_enhancement: ${{ steps.check.outputs.has_enhancement }}
2829
already_enhanced: ${{ steps.check.outputs.already_enhanced }}
2930
issue_number: ${{ steps.set_issue.outputs.issue_number }}
31+
should_skip: ${{ steps.skip-opened.outputs.skip }}
3032
steps:
3133
- name: Set issue number
3234
id: set_issue
@@ -37,6 +39,30 @@ jobs:
3739
echo "issue_number=${{ github.event.issue.number }}" >> "$GITHUB_OUTPUT"
3840
fi
3941
42+
- name: Check if opened event should be skipped
43+
id: skip-opened
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
ISSUE_NUMBER: ${{ github.event.issue.number }}
47+
run: |
48+
# Default to not skipping (for labeled events and workflow_dispatch)
49+
SKIP_VALUE="false"
50+
51+
# If issue is opened with enhancement label already present,
52+
# skip this run (labeled event will handle it to avoid duplicate runs)
53+
if [ "${{ github.event_name }}" = "issues" ] && [ "${{ github.event.action }}" = "opened" ]; then
54+
ISSUE_JSON=$(curl -s \
55+
-H "Authorization: token $GITHUB_TOKEN" \
56+
-H "Accept: application/vnd.github+json" \
57+
"https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER")
58+
LABELS=$(echo "$ISSUE_JSON" | jq -r '.labels[].name' | tr '\n' ' ')
59+
if echo "$LABELS" | grep -qw "enhancement"; then
60+
echo "⚠️ Issue opened with enhancement label already present - skipping (labeled event will handle it)"
61+
SKIP_VALUE="true"
62+
fi
63+
fi
64+
echo "skip=$SKIP_VALUE" >> "$GITHUB_OUTPUT"
65+
4066
- name: Fetch and check issue
4167
id: check
4268
env:
@@ -79,7 +105,7 @@ jobs:
79105
preprocess:
80106
runs-on: ubuntu-latest
81107
needs: check-label
82-
if: needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
108+
if: needs.check-label.outputs.should_skip != 'true' && needs.check-label.outputs.has_enhancement == 'true' && needs.check-label.outputs.already_enhanced == 'false'
83109
outputs:
84110
enhanced_task: ${{ steps.preprocess.outputs.enhanced_task }}
85111
issue_title: ${{ steps.fetch.outputs.issue_title }}

0 commit comments

Comments
 (0)