@@ -40,19 +40,99 @@ jobs:
4040 get-parameters :
4141 if : github.repository_owner == 'storybookjs'
4242 runs-on : ubuntu-latest
43+ # NB: We'll set the job output from the final step (id: set_workflow).
4344 steps :
44- - if : github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:normal'))
45- run : echo "workflow=normal" >> $GITHUB_ENV
46- - if : github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:docs'))
47- run : echo "workflow=docs" >> $GITHUB_ENV
48- - if : github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci:merged')
49- run : echo "workflow=merged" >> $GITHUB_ENV
50- - if : github.event_name == 'pull_request_target' && (contains(github.event.pull_request.labels.*.name, 'ci:daily'))
51- run : echo "workflow=daily" >> $GITHUB_ENV
45+ - name : Reset workflow (start clean)
46+ run : |
47+ echo "Resetting workflow env"
48+ # ensure workflow env var is empty for the job
49+ echo "workflow=" >> $GITHUB_ENV
50+
51+ - name : Debug - show github context
52+ run : |
53+ echo "=== GITHUB CONTEXT / EVENT INFO ==="
54+ echo "event_name: $GITHUB_EVENT_NAME"
55+ echo "event.action: ${{ github.event.action || 'null' }}"
56+ echo "pull_request exists? : ${{ github.event.pull_request != null }}"
57+ echo "---- full event JSON (truncated to 20000 chars) ----"
58+ # for readability, print parsed JSON (toJSON is safe here)
59+ jq -C . <<<"${{ toJSON(github.event) }}" | sed -n '1,200p'
60+
61+ - name : Determine workflow from labels on pull_request_target labeled event
62+ if : github.event_name == 'pull_request_target' && github.event.action == 'labeled'
63+ run : |
64+ echo "Labeled event detected"
65+ echo "Added label: ${{ github.event.label.name }}"
66+ case "${{ github.event.label.name }}" in
67+ ci:normal) echo "workflow=normal" >> $GITHUB_ENV ;;
68+ ci:docs) echo "workflow=docs" >> $GITHUB_ENV ;;
69+ ci:merged) echo "workflow=merged" >> $GITHUB_ENV ;;
70+ ci:daily) echo "workflow=daily" >> $GITHUB_ENV ;;
71+ *)
72+ echo "Label is not a ci: label — leaving workflow empty"
73+ ;;
74+ esac
75+
76+ - name : Determine workflow from labels on push event
77+ if : github.event_name == 'push' && github.event.pull_request != null
78+ run : |
79+ echo "Push event with associated pull_request detected"
80+ # Collect labels from the embedded pull_request JSON
81+ LABELS=$(jq -r '.pull_request.labels[].name' <<<"${{ toJSON(github.event) }}" 2>/dev/null || true)
82+ echo "PR labels: $LABELS"
83+ for label in $LABELS; do
84+ case "$label" in
85+ ci:normal)
86+ echo "Matched ci:normal"
87+ echo "workflow=normal" >> $GITHUB_ENV
88+ break
89+ ;;
90+ ci:docs)
91+ echo "Matched ci:docs"
92+ echo "workflow=docs" >> $GITHUB_ENV
93+ break
94+ ;;
95+ ci:merged)
96+ echo "Matched ci:merged"
97+ echo "workflow=merged" >> $GITHUB_ENV
98+ break
99+ ;;
100+ ci:daily)
101+ echo "Matched ci:daily"
102+ echo "workflow=daily" >> $GITHUB_ENV
103+ break
104+ ;;
105+ esac
106+ done
107+
108+ - name : Finalize workflow output and debug
109+ id : set_workflow
110+ run : |
111+ echo "=== Finalize and debug workflow value ==="
112+ # Show what was written into the $GITHUB_ENV file (last lines containing workflow)
113+ echo "-- GITHUB_ENV contents for workflow --"
114+ grep '^workflow=' $GITHUB_ENV || echo "(no workflow entry found in GITHUB_ENV)"
115+
116+ # The environment variable 'workflow' should now be available to steps.
117+ echo "ENV workflow (the value we will publish): '${workflow}'"
118+
119+ # For extra safety convert literal 'workflow=' to empty string
120+ # and set the job output explicitly via GITHUB_OUTPUT
121+ # (this makes needs.get-parameters.outputs.workflow deterministic)
122+ # If workflow is unset, this will write an empty value which is what we want.
123+ echo "workflow=${workflow}" >> $GITHUB_OUTPUT
124+
125+ if [ -z "${workflow}" ]; then
126+ echo "FINAL STATE: no ci:* workflow selected (empty)"
127+ else
128+ echo "FINAL STATE: workflow='${workflow}'"
129+ fi
130+
131+ # Make job outputs come from the step (set_workflow)
52132 outputs :
53- workflow : ${{ env .workflow }}
54- ghBaseBranch : ${{ github.event.pull_request. base.ref }}
55- ghPrNumber : ${{ github.event.pull_request. number }}
133+ workflow : ${{ steps.set_workflow.outputs .workflow }}
134+ ghBaseBranch : ${{ github.event.pull_request && github.event.pull_request. base.ref || '' }}
135+ ghPrNumber : ${{ github.event.pull_request && github.event.pull_request. number || '' }}
56136
57137 trigger-circle-ci-workflow :
58138 runs-on : ubuntu-latest
62142 - name : Trigger Normal tests
63143 uses : fjogeleit/http-request-action@v1
64144 with :
65- url : ' https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline'
66- method : ' POST'
145+ url : " https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline"
146+ method : " POST"
67147 customHeaders : ' {"Content-Type": "application/json", "Circle-Token": "${{ secrets.CIRCLE_CI_TOKEN }}"}'
68148 data : ' { "branch": "${{needs.get-branch.outputs.branch}}", "parameters": ${{toJson(needs.get-parameters.outputs)}} }'
0 commit comments