Skip to content

Commit e1622ac

Browse files
authored
React before replying with SimDeck URL (#33)
1 parent 6e619fa commit e1622ac

2 files changed

Lines changed: 55 additions & 28 deletions

File tree

actions/run-ios-comment-session/action.yml

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ inputs:
1010
description: Original issue comment body. Flags such as no-cache-sim, latest-device, and quality=tiny are honored.
1111
required: false
1212
default: simdeck run ios
13+
command_comment_id:
14+
description: GitHub issue comment id that triggered the session. When set, the action reacts to this comment immediately.
15+
required: false
16+
default: ""
17+
command_comment_author:
18+
description: GitHub username to mention when the URL is ready.
19+
required: false
20+
default: ""
21+
command_reaction:
22+
description: Reaction to add to the triggering comment. Use one of +1, -1, laugh, confused, heart, hooray, rocket, eyes.
23+
required: false
24+
default: eyes
1325
pr_sha:
1426
description: Optional pull request head SHA. When omitted, the action resolves it through the GitHub API.
1527
required: false
@@ -82,6 +94,9 @@ runs:
8294
PR_NUMBER_VALUE: ${{ inputs.pr_number }}
8395
PR_SHA_INPUT_VALUE: ${{ inputs.pr_sha }}
8496
SIMDECK_COMMENT_BODY_VALUE: ${{ inputs.command }}
97+
COMMAND_COMMENT_ID_VALUE: ${{ inputs.command_comment_id }}
98+
COMMAND_COMMENT_AUTHOR_VALUE: ${{ inputs.command_comment_author }}
99+
COMMAND_REACTION_VALUE: ${{ inputs.command_reaction }}
85100
SIMDECK_BUNDLE_ID_VALUE: ${{ inputs.bundle_id }}
86101
SIMDECK_PORT_VALUE: ${{ inputs.simdeck_port }}
87102
SIMDECK_PACKAGE_VALUE: ${{ inputs.simdeck_package }}
@@ -114,6 +129,9 @@ runs:
114129
write_env "PR_NUMBER" "${PR_NUMBER_VALUE}"
115130
write_env "PR_SHA_INPUT" "${PR_SHA_INPUT_VALUE}"
116131
write_env "SIMDECK_COMMENT_BODY" "${SIMDECK_COMMENT_BODY_VALUE}"
132+
write_env "COMMAND_COMMENT_ID" "${COMMAND_COMMENT_ID_VALUE}"
133+
write_env "COMMAND_COMMENT_AUTHOR" "${COMMAND_COMMENT_AUTHOR_VALUE}"
134+
write_env "COMMAND_REACTION" "${COMMAND_REACTION_VALUE}"
117135
write_env "SIMDECK_BUNDLE_ID" "${SIMDECK_BUNDLE_ID_VALUE}"
118136
write_env "SIMDECK_PORT" "${SIMDECK_PORT_VALUE}"
119137
write_env "SIMDECK_PACKAGE" "${SIMDECK_PACKAGE_VALUE}"
@@ -128,24 +146,17 @@ runs:
128146
write_env "ARTIFACT_PREFIX" "${ARTIFACT_PREFIX_VALUE}"
129147
write_env "ARTIFACT_NAME_INPUT" "${ARTIFACT_NAME_INPUT_VALUE}"
130148
write_env "FORCE_JAVASCRIPT_ACTIONS_TO_NODE24" "true"
131-
- name: Create status comment and resolve flags
149+
- name: React to command and resolve flags
132150
shell: bash
133151
run: |
134152
set -euo pipefail
135-
status_body="Starting a SimDeck iOS session for this pull request. I will update this comment with the tunnel URL when it is ready."
136-
status_comment_id=""
137153
138-
for attempt in {1..5}; do
139-
if comment_id="$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" -f body="${status_body}" --jq '.id')"; then
140-
status_comment_id="${comment_id}"
141-
echo "SIMDECK_STATUS_COMMENT_ID=${status_comment_id}" >> "${GITHUB_ENV}"
142-
break
143-
fi
144-
sleep $((attempt * 5))
145-
done
146-
147-
if [[ -z "${status_comment_id}" ]]; then
148-
exit 1
154+
if [[ -n "${COMMAND_COMMENT_ID:-}" && -n "${COMMAND_REACTION:-}" ]]; then
155+
gh api \
156+
-X POST \
157+
-H "Accept: application/vnd.github+json" \
158+
"repos/${REPO}/issues/comments/${COMMAND_COMMENT_ID}/reactions" \
159+
-f content="${COMMAND_REACTION}" >/dev/null || true
149160
fi
150161
151162
body="${SIMDECK_COMMENT_BODY}"
@@ -536,17 +547,28 @@ runs:
536547
shell: bash
537548
run: |
538549
set -euo pipefail
550+
mention=""
551+
if [[ -n "${COMMAND_COMMENT_AUTHOR:-}" ]]; then
552+
mention="@${COMMAND_COMMENT_AUTHOR} "
553+
fi
554+
539555
cat > comment.md <<'EOF'
540-
SimDeck iOS session is ready: [Open SimDeck](${{ steps.stream.outputs.url }}?simdeckToken=${{ steps.stream.outputs.access_token }}&device=${{ env.SIMULATOR_UDID }})
556+
__MENTION__SimDeck iOS session is ready: [Open SimDeck](${{ steps.stream.outputs.url }}?simdeckToken=${{ steps.stream.outputs.access_token }}&device=${{ env.SIMULATOR_UDID }})
541557
542558
The selected simulator is booting and the PR app will launch here once its build artifact is installed.
543559
544560
This session will stop after ${{ inputs.keepalive_seconds }} seconds, or earlier if the simulator shuts down.
545561
EOF
546562
547563
body="$(cat comment.md)"
564+
body="${body/__MENTION__/${mention}}"
548565
for attempt in {1..5}; do
549-
if [[ -n "${SIMDECK_STATUS_COMMENT_ID:-}" ]] && gh api -X PATCH "repos/${REPO}/issues/comments/${SIMDECK_STATUS_COMMENT_ID}" -f body="${body}"; then
566+
if [[ -n "${SIMDECK_STATUS_COMMENT_ID:-}" ]]; then
567+
if gh api -X PATCH "repos/${REPO}/issues/comments/${SIMDECK_STATUS_COMMENT_ID}" -f body="${body}"; then
568+
exit 0
569+
fi
570+
elif comment_id="$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" -f body="${body}" --jq '.id')"; then
571+
echo "SIMDECK_STATUS_COMMENT_ID=${comment_id}" >> "${GITHUB_ENV}"
550572
exit 0
551573
fi
552574
sleep $((attempt * 5))

docs/guide/github-actions.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,21 @@ jobs:
8080
with:
8181
pr_number: ${{ github.event.issue.number }}
8282
command: ${{ github.event.comment.body }}
83+
command_comment_id: ${{ github.event.comment.id }}
84+
command_comment_author: ${{ github.event.comment.user.login }}
8385
build_workflow: build-ios-simulator.yml
8486
bundle_id: com.example.app
8587
```
8688

8789
When triggered, the session action:
8890

89-
- creates one status comment and edits that same comment as the session changes;
91+
- reacts to the command comment immediately;
9092
- installs `simdeck` and `cloudflared` on a single macOS runner;
9193
- starts SimDeck with software encoding and the `tiny` stream profile by default;
9294
- prefers `iPhone 17 Pro`, then falls back to the newest available iPhone simulator;
9395
- restores the CoreSimulator device cache when available;
94-
- posts the Cloudflare Tunnel URL only after a simulator UDID has been selected;
96+
- posts the first bot comment only after a simulator UDID has been selected,
97+
mentioning the requester when `command_comment_author` is set;
9598
- downloads the simulator app artifact for the PR head commit, installs it, and
9699
launches it;
97100
- stops after 30 minutes by default, or earlier if the simulator shuts down.
@@ -115,16 +118,18 @@ Supported quality values are `tiny`, `low`, `economy`, `fast`, `smooth`,
115118

116119
The most common session action inputs are:
117120

118-
| Input | Default | Purpose |
119-
| ------------------- | ------------------------- | -------------------------------------------- |
120-
| `bundle_id` | empty | Fallback app bundle id to launch. |
121-
| `build_workflow` | `build-ios-simulator.yml` | Workflow file that uploads the app artifact. |
122-
| `artifact_prefix` | `ios-simulator-app` | Prefix used for `<prefix>-<sha>` artifacts. |
123-
| `simdeck_version` | `latest` | npm version or dist-tag to install. |
124-
| `stream_profile` | `tiny` | Default stream quality profile. |
125-
| `simulator_name` | `iPhone 17 Pro` | Preferred simulator device name. |
126-
| `keepalive_seconds` | `1800` | Session lifetime after app launch. |
127-
| `simulator_cache` | `true` | Restore and save CoreSimulator device cache. |
121+
| Input | Default | Purpose |
122+
| ------------------------ | ------------------------- | --------------------------------------------- |
123+
| `bundle_id` | empty | Fallback app bundle id to launch. |
124+
| `build_workflow` | `build-ios-simulator.yml` | Workflow file that uploads the app artifact. |
125+
| `command_comment_id` | empty | Comment id to react to immediately. |
126+
| `command_comment_author` | empty | GitHub user to mention when the URL is ready. |
127+
| `artifact_prefix` | `ios-simulator-app` | Prefix used for `<prefix>-<sha>` artifacts. |
128+
| `simdeck_version` | `latest` | npm version or dist-tag to install. |
129+
| `stream_profile` | `tiny` | Default stream quality profile. |
130+
| `simulator_name` | `iPhone 17 Pro` | Preferred simulator device name. |
131+
| `keepalive_seconds` | `1800` | Session lifetime after app launch. |
132+
| `simulator_cache` | `true` | Restore and save CoreSimulator device cache. |
128133

129134
The caller workflow owns job-level settings such as `runs-on`,
130135
`timeout-minutes`, permissions, and concurrency. Pin `NativeScript/SimDeck` to a

0 commit comments

Comments
 (0)