feat: support workflow_dispatch for build description#20
Conversation
The `description` fallback relied on `head_commit.message`, which is only
populated on `push` events. On `workflow_dispatch` (and `schedule`,
`repository_dispatch`, `workflow_run`) the build description degraded to
`Commit <sha>`.
Adds a `github-token` input (defaulting to `${{ github.token }}`) and
fetches the commit via the GitHub API when the payload lacks it. API
failures are warned and still fall back to `Commit <sha>`.
Also fixes empty `status.required:` in action.yml.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Bump actions/upload-artifact from v3 to v4 so check-dist is no longer
auto-failed by GitHub's deprecation policy during job setup.
- Remove the `test` job in test.yml. It invoked `uses: ./` with only
`milliseconds: 1000` (a leftover from the actions/typescript-action
template), had no valid `action` input, and crashed on the
`const { id, ... } = build` destructure in action.js. It was dead
code that never exercised this action meaningfully; the `units` job
runs the real unit tests.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
|
||
| # test action works running from the graph | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: ./ | ||
| with: | ||
| milliseconds: 1000 |
There was a problem hiding this comment.
Leftover from when the repo was bootstrapped as a fork of actions/javascript-action in 327daaf (2023-04-12): at that commit action.yml declared a milliseconds input and index.js was the template's wait code, so the job passed.
Six days later b52f3e3 ("Build action") replaced the template with the Nullplatform action — milliseconds was gone — but test.yml was never updated. Since then: empty action input → no CREATE/UPDATE match → core.setFailed(...) without return → const { id, ... } = build crashes on null.
No merged PR since has seen it pass (older run logs were purged by retention, but this PR's run_number on units-test was #43 and the only merge since b52f3e3 is docs-only #19). Restoring it properly needs real credentials or a mock server — out of scope here; units already runs npm test.
Move getCommitMessage from action.js into its own module so it can be unit-tested in isolation. action.js still re-imports and uses it the same way (no behavior change). Added src/commit.test.js with @actions/core and @actions/github mocked, covering: empty token short-circuit, success path, and API failure (warns + returns null). Addresses review feedback on PR #20 from @francocirulli95.
Replace the unit test on getCommitMessage (commit.test.js) with an integration test on run() (action.test.js) that mocks @actions/core, @actions/github and HttpClient. The new test asserts the real invariant — the description sent to the nullplatform build API — across five scenarios: - push event with head_commit - workflow_dispatch with valid token (API succeeds) - workflow_dispatch with empty token - workflow_dispatch with API failure - explicit description input wins over payload and API The previous unit test was effectively a tautology: it mocked the same octokit method it then asserted against, so it could not catch a reordering of the `||` chain in createBuild or a misuse of the helper. The integration test covers all three branches of getCommitMessage indirectly while validating the path that actually matters. Addresses review feedback on PR #20 from @francocirulli95. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The dedicated module was overkill for a 20-line helper used in a single place. Inlining keeps action.js self-contained without losing readability. The integration test in action.test.js is unaffected because it asserts on run() behavior, not on the module boundary. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
github-tokeninput (default${{ github.token }}) socreateBuildcan fetch the commit message from the GitHub API when the event payload has nohead_commit(e.g.workflow_dispatch,schedule,repository_dispatch,workflow_run).head_commit.message→ API →Commit <sha>. API errors are logged as warnings and fall through, so the action never breaks on a missing token.status.required:inaction.yml; documents the new input in the README; rebuildsdist/.Permissions
The API call needs
contents: readon the token. Default${{ github.token }}has it unless the consumer restrictspermissions:. On failure we warn and useCommit <sha>.Test plan
npm run lintnpm test(6/6)npm run prepareregeneratesdist/index.jsworkflow_dispatch→ description matches commit messagepush→ payload path still wins (no API call)🤖 Generated with Claude Code