Skip to content

Commit 7157e5e

Browse files
committed
chore: test new
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent a1868a3 commit 7157e5e

2 files changed

Lines changed: 60 additions & 38 deletions

File tree

.github/workflows/sync-issue-labels-add.yml

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@ on:
44
workflow_dispatch:
55
inputs:
66
upstream_run_id:
7+
description: "Upstream compute workflow run ID"
78
required: true
89
type: string
910
pr_number:
11+
description: "Pull request number"
1012
required: true
1113
type: string
1214
dry_run:
15+
description: "Dry run flag"
1316
required: false
1417
type: string
1518
default: "true"
1619
is_fork_pr:
20+
description: "Fork PR flag"
1721
required: false
1822
type: string
1923
default: "false"
24+
defaults:
25+
run:
26+
shell: bash
27+
permissions:
28+
actions: read
29+
issues: write
2030

2131
jobs:
2232
add-labels:
33+
concurrency:
34+
group: sync-issue-labels-pr-${{ github.event.inputs.pr_number }}
35+
cancel-in-progress: true
2336
runs-on: ubuntu-latest
24-
permissions:
25-
actions: read
26-
issues: write
27-
pull-requests: write # Added this to ensure labels can be written
2837
steps:
2938
- name: Harden the runner
3039
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
@@ -34,7 +43,7 @@ jobs:
3443
- name: Download labels artifact
3544
id: download
3645
continue-on-error: true
37-
uses: actions/download-artifact@v4 # Updated to v4 for compatibility
46+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
3847
with:
3948
name: pr-labels-${{ github.event.inputs.pr_number }}
4049
path: artifacts
@@ -43,63 +52,76 @@ jobs:
4352

4453
- name: Read labels payload
4554
id: read
55+
env:
56+
INPUT_PR_NUMBER: ${{ github.event.inputs.pr_number }}
57+
INPUT_IS_FORK_PR: ${{ github.event.inputs.is_fork_pr }}
58+
INPUT_DRY_RUN: ${{ github.event.inputs.dry_run }}
4659
run: |
4760
labels_file="artifacts/labels.json"
4861
if [ ! -f "$labels_file" ]; then
49-
echo "::error::Labels artifact not found."
62+
echo "::error::Labels artifact not found. Cross-workflow handoff is broken."
63+
echo "labels=[]" >> "$GITHUB_OUTPUT"
64+
echo "labels_count=0" >> "$GITHUB_OUTPUT"
65+
echo "labels_multiline=" >> "$GITHUB_OUTPUT"
66+
echo "pr_number=$INPUT_PR_NUMBER" >> "$GITHUB_OUTPUT"
67+
echo "is_fork_pr=$INPUT_IS_FORK_PR" >> "$GITHUB_OUTPUT"
68+
echo "dry_run=$INPUT_DRY_RUN" >> "$GITHUB_OUTPUT"
69+
echo "source_event=workflow_dispatch" >> "$GITHUB_OUTPUT"
5070
exit 1
5171
fi
52-
53-
# Extract values
5472
labels=$(jq -c '.labels // []' "$labels_file")
5573
pr_number=$(jq -r '.pr_number // 0' "$labels_file")
5674
is_fork_pr=$(jq -r '.is_fork_pr // false' "$labels_file")
5775
dry_run=$(jq -r '.dry_run // "true"' "$labels_file")
58-
59-
# Prepare multiline output for the labeling action
60-
labels_multiline=$(jq -r '.labels // [] | join("\n")' "$labels_file")
61-
76+
source_event=$(jq -r '.source_event // ""' "$labels_file")
77+
labels_multiline=$(jq -r '.labels // [] | .[]' "$labels_file")
78+
labels_count=$(echo "$labels" | jq 'length')
6279
echo "labels=$labels" >> "$GITHUB_OUTPUT"
63-
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
64-
echo "is_fork_pr=$is_fork_pr" >> "$GITHUB_OUTPUT"
65-
echo "dry_run=$dry_run" >> "$GITHUB_OUTPUT"
80+
echo "labels_count=$labels_count" >> "$GITHUB_OUTPUT"
6681
{
6782
echo "labels_multiline<<EOF"
6883
echo "$labels_multiline"
6984
echo "EOF"
7085
} >> "$GITHUB_OUTPUT"
86+
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
87+
echo "is_fork_pr=$is_fork_pr" >> "$GITHUB_OUTPUT"
88+
echo "dry_run=$dry_run" >> "$GITHUB_OUTPUT"
89+
echo "source_event=$source_event" >> "$GITHUB_OUTPUT"
7190
72-
- name: Validate and Determine Action
91+
- name: Validate labels payload
92+
id: validate
93+
run: |
94+
if [ "$PR_NUMBER" = "0" ] || [ "$(echo "$LABELS" | jq -r '. | length')" = "0" ]; then
95+
echo "Invalid payload: pr_number=$PR_NUMBER or labels empty. Skipping label addition."
96+
echo "valid_payload=false" >> "$GITHUB_OUTPUT"
97+
else
98+
echo "valid_payload=true" >> "$GITHUB_OUTPUT"
99+
fi
100+
env:
101+
PR_NUMBER: ${{ steps.read.outputs.pr_number }}
102+
LABELS: ${{ steps.read.outputs.labels }}
103+
104+
- name: Determine if labels should be applied
73105
id: should_apply
74106
run: |
75-
HAS_LABELS=$(echo '${{ steps.read.outputs.labels }}' | jq 'length > 0')
76-
77-
if [ "$HAS_LABELS" != "true" ]; then
107+
if [ "${{ steps.read.outputs.is_fork_pr }}" = "true" ]; then
108+
echo "apply=false" >> "$GITHUB_OUTPUT"
109+
echo "reason=fork PR" >> "$GITHUB_OUTPUT"
110+
elif [ "${{ steps.validate.outputs.valid_payload }}" != "true" ]; then
78111
echo "apply=false" >> "$GITHUB_OUTPUT"
79-
echo "reason=No labels found in payload" >> "$GITHUB_OUTPUT"
80-
elif [ "${{ steps.read.outputs.dry_run }}" = "true" ]; then
112+
echo "reason=invalid payload" >> "$GITHUB_OUTPUT"
113+
elif [ "${{ steps.read.outputs.source_event }}" = "workflow_dispatch" ] && [ "${{ steps.read.outputs.dry_run }}" = "true" ]; then
81114
echo "apply=false" >> "$GITHUB_OUTPUT"
82-
echo "reason=Dry run is enabled" >> "$GITHUB_OUTPUT"
115+
echo "reason=dry run" >> "$GITHUB_OUTPUT"
83116
else
84117
echo "apply=true" >> "$GITHUB_OUTPUT"
85-
echo "reason=Validated and ready" >> "$GITHUB_OUTPUT"
118+
echo "reason=" >> "$GITHUB_OUTPUT"
86119
fi
87120
88-
echo "-----------------------------------"
89-
echo "DEBUG INFO:"
90-
echo "Apply Flag: ${{ steps.should_apply.outputs.apply }}"
91-
echo "Reason: ${{ steps.should_apply.outputs.reason }}"
92-
echo "Is Fork PR: ${{ steps.read.outputs.is_fork_pr }}"
93-
echo "PR Number: ${{ steps.read.outputs.pr_number }}"
94-
echo "Labels Found:"
95-
echo "${{ steps.read.outputs.labels_multiline }}"
96-
echo "-----------------------------------"
97-
98-
99121
- name: Add labels to PR
100-
if: steps.should_apply.outputs.apply == 'true'
101-
uses: actions-ecosystem/action-add-labels@v1
122+
if: ${{ steps.should_apply.outputs.apply == 'true' }}
123+
uses: actions-ecosystem/action-add-labels@1a9c3715c0037e96b97bb38cb4c4b56a1f1d4871 # main
102124
with:
103125
github_token: ${{ secrets.GITHUB_TOKEN }}
104126
labels: ${{ steps.read.outputs.labels_multiline }}
105-
number: ${{ steps.read.outputs.pr_number }}
127+
number: ${{ steps.read.outputs.pr_number }}

.github/workflows/sync-issue-labels-compute.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ jobs:
204204
upstream_run_id: "${{ github.run_id }}",
205205
pr_number: "${{ needs.compute-labels.outputs.pr_number }}",
206206
dry_run: "${{ needs.compute-labels.outputs.dry_run }}",
207-
is_fork_pr: "${{ needs.compute-labels.outputs.is_fork_pr }}"
207+
is_fork_pr: "false"
208208
}
209209
});
210210

0 commit comments

Comments
 (0)