@@ -3,14 +3,36 @@ name: Publish PR Preview
33on :
44 pull_request :
55 types : [labeled]
6+ workflow_dispatch :
7+ inputs :
8+ pr_number :
9+ description : Pull request number to publish
10+ required : true
11+ type : string
12+ publish_test_pypi :
13+ description : Publish the Python package to TestPyPI
14+ required : true
15+ default : true
16+ type : boolean
17+ publish_docker :
18+ description : Publish socketdev/cli:pr-<number> to Docker Hub
19+ required : true
20+ default : false
21+ type : boolean
22+ sdk_preview_version :
23+ description : Optional exact TestPyPI socketdev prerelease for the Docker image
24+ required : false
25+ type : string
626
727concurrency :
8- group : publish-pr-preview-${{ github.event.pull_request.number }}
28+ group : publish-pr-preview-${{ github.event.pull_request.number || inputs.pr_number || github.run_id }}
929 cancel-in-progress : false
30+ queue : max
1031
1132jobs :
1233 context :
1334 if : >-
35+ github.event_name == 'workflow_dispatch' ||
1436 (github.event.label.name == 'publish-preview' ||
1537 github.event.label.name == 'publish-docker-preview') &&
1638 github.event.pull_request.head.repo.full_name == github.repository
@@ -27,15 +49,28 @@ jobs:
2749 id : context
2850 uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
2951 env :
52+ DEFAULT_BRANCH : ${{ github.event.repository.default_branch }}
3053 EVENT_PR_NUMBER : ${{ github.event.pull_request.number }}
54+ INPUT_PR_NUMBER : ${{ inputs.pr_number }}
55+ WORKFLOW_REF : ${{ github.ref }}
3156 with :
3257 script : |
33- const rawPrNumber = process.env.EVENT_PR_NUMBER;
58+ const rawPrNumber = context.eventName === 'workflow_dispatch'
59+ ? process.env.INPUT_PR_NUMBER
60+ : process.env.EVENT_PR_NUMBER;
3461 if (!/^[1-9][0-9]*$/.test(rawPrNumber || '')) {
3562 core.setFailed('Pull request number must contain ASCII digits only.');
3663 return;
3764 }
3865
66+ if (context.eventName === 'workflow_dispatch') {
67+ const defaultRef = `refs/heads/${process.env.DEFAULT_BRANCH}`;
68+ if (process.env.WORKFLOW_REF !== defaultRef) {
69+ core.setFailed(`Run manual previews from ${defaultRef}.`);
70+ return;
71+ }
72+ }
73+
3974 const prNumber = Number(rawPrNumber);
4075 if (!Number.isSafeInteger(prNumber)) {
4176 core.setFailed('Pull request number is outside the supported range.');
@@ -128,7 +163,9 @@ jobs:
128163
129164 publish-package :
130165 needs : [context, build]
131- if : github.event.label.name == 'publish-preview'
166+ if : >-
167+ github.event.label.name == 'publish-preview' ||
168+ (github.event_name == 'workflow_dispatch' && inputs.publish_test_pypi)
132169 runs-on : ubuntu-latest
133170 timeout-minutes : 10
134171 permissions :
@@ -192,7 +229,9 @@ jobs:
192229
193230 publish-docker :
194231 needs : [context, build]
195- if : github.event.label.name == 'publish-docker-preview'
232+ if : >-
233+ github.event.label.name == 'publish-docker-preview' ||
234+ (github.event_name == 'workflow_dispatch' && inputs.publish_docker)
196235 runs-on : ubuntu-latest
197236 timeout-minutes : 15
198237 permissions :
@@ -236,6 +275,8 @@ jobs:
236275 # arm64 layer builds under emulation, so expect roughly double the runtime.
237276 platforms : linux/amd64,linux/arm64
238277 tags : socketdev/cli:pr-${{ needs.context.outputs.pr_number }}
278+ build-args : |
279+ SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }}
239280
240281 - name : Comment on pull request
241282 uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
0 commit comments