specguard-ruby 0.3.32 → 0.3.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/specguard/client/configuration.rb +102 -2
- data/lib/specguard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0f1cdce1e2e763d549b0ccb1bd5d9a22b1c5a9da9f63645704af3ecd8149de1
|
|
4
|
+
data.tar.gz: aa80ba0c1f264a50d307c83fd1a8c9a543d6b5eef75037f53ac5ffef68c5d812
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4673b30c851eb2324326704ab72539c4a909b068f1addc354cb461de216816a05ee2f195b01c70a9c78cadd3810760d6d59c89947e6c56a31971ca6915e658e4
|
|
7
|
+
data.tar.gz: fd2ae5c3fafa5ed48b05c71f5109fea22b8b1796b7d0869cf1fb6bcfe2b8adaad440aa79c2cea493c2984bf7fb2a032fe17a7666d19387f4803852692f2f925d
|
data/README.md
CHANGED
|
@@ -1146,8 +1146,8 @@ body is encoded on the wire, never what is in it.
|
|
|
1146
1146
|
|
|
1147
1147
|
| Field | What it holds | Where it comes from |
|
|
1148
1148
|
| --- | --- | --- |
|
|
1149
|
-
| `commit_sha` | the commit the suite ran against | `SPECGUARD_COMMIT_SHA` if you set it, else `GITHUB_SHA`, `CI_COMMIT_SHA`, `CIRCLE_SHA1`, `BUILDKITE_COMMIT`, `GIT_COMMIT`, else `git rev-parse HEAD` |
|
|
1150
|
-
| `branch` | the branch name; `null` on a detached checkout | `SPECGUARD_BRANCH` if you set it, else `GITHUB_REF_NAME`, `CI_COMMIT_REF_NAME`, `CIRCLE_BRANCH`, `BUILDKITE_BRANCH`, `GIT_BRANCH`, else `git symbolic-ref --short -q HEAD` |
|
|
1149
|
+
| `commit_sha` | the commit the suite ran against | `SPECGUARD_COMMIT_SHA` if you set it, else — on a same-repository GitHub Actions `pull_request` / `pull_request_target` run — the pushed head sha from the event payload at `GITHUB_EVENT_PATH` (`GITHUB_SHA` there is an ephemeral merge commit), else `GITHUB_SHA`, `CI_COMMIT_SHA`, `CIRCLE_SHA1`, `BUILDKITE_COMMIT`, `GIT_COMMIT`, else `git rev-parse HEAD` |
|
|
1150
|
+
| `branch` | the branch name; `null` on a detached checkout | `SPECGUARD_BRANCH` if you set it, else — on a same-repository GitHub Actions `pull_request` / `pull_request_target` run — `GITHUB_HEAD_REF` (`GITHUB_REF_NAME` there is `<n>/merge`), else `GITHUB_REF_NAME`, `CI_COMMIT_REF_NAME`, `CIRCLE_BRANCH`, `BUILDKITE_BRANCH`, `GIT_BRANCH`, else `git symbolic-ref --short -q HEAD` |
|
|
1151
1151
|
| `ci_run_id` | your provider's build id, so shards of one run fold together; `null` on a laptop | `SPECGUARD_RUN_ID` if you set it, else `GITHUB_RUN_ID`, `CI_PIPELINE_ID`, `CIRCLE_WORKFLOW_ID`, `BUILDKITE_BUILD_ID`, `BUILD_TAG` |
|
|
1152
1152
|
| `shard_id` | which slice of that run this process is; `null` when unsharded | `SPECGUARD_SHARD_ID` if you set it, else `TEST_ENV_NUMBER`, `CI_NODE_INDEX`, `CIRCLE_NODE_INDEX`, `BUILDKITE_PARALLEL_JOB` |
|
|
1153
1153
|
| `duration_seconds` | wall clock for the whole run | measured by the formatter |
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
3
5
|
module SpecGuard
|
|
4
6
|
module Client
|
|
5
7
|
# Where the checkout is sitting — which commit, and which branch — asked of
|
|
@@ -180,6 +182,12 @@ module SpecGuard
|
|
|
180
182
|
# every GitLab, CircleCI, Buildkite and Jenkins run 400ing as a matter of
|
|
181
183
|
# course — the *default* outcome on four of the five providers this gem is
|
|
182
184
|
# likely to meet.
|
|
185
|
+
#
|
|
186
|
+
# On a GitHub Actions `pull_request` / `pull_request_target` run from the
|
|
187
|
+
# same repository, the pushed head commit in the event payload
|
|
188
|
+
# (`#pull_request_head`) is consulted *between* `SPECGUARD_COMMIT_SHA` and
|
|
189
|
+
# the rest of this list: `GITHUB_SHA` there is the ephemeral merge commit
|
|
190
|
+
# (the base tip on `_target`), a sha nobody pushed.
|
|
183
191
|
COMMIT_SHA_KEYS = %w[
|
|
184
192
|
SPECGUARD_COMMIT_SHA
|
|
185
193
|
GITHUB_SHA
|
|
@@ -195,6 +203,11 @@ module SpecGuard
|
|
|
195
203
|
# (`origin/main` on many setups), because `branch` is a free-form string
|
|
196
204
|
# to the platform and inventing a normalization here would be this gem
|
|
197
205
|
# guessing at somebody's ref layout.
|
|
206
|
+
#
|
|
207
|
+
# On a same-repository GitHub Actions `pull_request` /
|
|
208
|
+
# `pull_request_target` run, {PULL_REQUEST_BRANCH_KEYS} (`GITHUB_HEAD_REF`,
|
|
209
|
+
# the source branch) is consulted between `SPECGUARD_BRANCH` and the rest
|
|
210
|
+
# of this list, because `GITHUB_REF_NAME` there is `<n>/merge`.
|
|
198
211
|
BRANCH_KEYS = %w[
|
|
199
212
|
SPECGUARD_BRANCH
|
|
200
213
|
GITHUB_REF_NAME
|
|
@@ -314,6 +327,22 @@ module SpecGuard
|
|
|
314
327
|
# than absent. See trap 1 above.
|
|
315
328
|
BLANK_MEANS_FIRST_SHARD_KEY = "TEST_ENV_NUMBER"
|
|
316
329
|
|
|
330
|
+
# GitHub Actions only: the event that triggered the run, the file holding
|
|
331
|
+
# its payload, and the source branch of a pull request. They are read
|
|
332
|
+
# only together, by `#pull_request_head`, and only when `GITHUB_EVENT_NAME`
|
|
333
|
+
# is one of {PULL_REQUEST_EVENTS}.
|
|
334
|
+
EVENT_NAME_KEYS = %w[GITHUB_EVENT_NAME].freeze
|
|
335
|
+
EVENT_PATH_KEYS = %w[GITHUB_EVENT_PATH].freeze
|
|
336
|
+
PULL_REQUEST_BRANCH_KEYS = %w[GITHUB_HEAD_REF].freeze
|
|
337
|
+
|
|
338
|
+
# The GitHub events whose `GITHUB_SHA` / `GITHUB_REF_NAME` describe a
|
|
339
|
+
# merge ref rather than anything a person pushed.
|
|
340
|
+
PULL_REQUEST_EVENTS = %w[pull_request pull_request_target].freeze
|
|
341
|
+
|
|
342
|
+
# Largest `GITHUB_EVENT_PATH` payload read; a bigger file is treated as
|
|
343
|
+
# unreadable (mirrors specguard-ts).
|
|
344
|
+
MAX_EVENT_PAYLOAD_BYTES = 1024 * 1024
|
|
345
|
+
|
|
317
346
|
OUTPUT_PATH_KEYS = %w[SPECGUARD_OUTPUT_PATH].freeze
|
|
318
347
|
LOCAL_OUTPUT_PATH_KEYS = %w[SPECGUARD_LOCAL_OUTPUT_PATH].freeze
|
|
319
348
|
ENDPOINT_KEYS = %w[SPECGUARD_ENDPOINT].freeze
|
|
@@ -377,10 +406,22 @@ module SpecGuard
|
|
|
377
406
|
# reason, and so a test does not silently pick up the sha or the branch
|
|
378
407
|
# of whatever repository it runs in.
|
|
379
408
|
def initialize(env: ENV, git: GitCheckout)
|
|
380
|
-
|
|
409
|
+
explicit_sha = first_present(env, COMMIT_SHA_KEYS.first(1))
|
|
410
|
+
explicit_branch = first_present(env, BRANCH_KEYS.first(1))
|
|
411
|
+
# One read of the event payload decides branch and sha together, so
|
|
412
|
+
# they cannot disagree; skipped when both were set explicitly.
|
|
413
|
+
pr_head = explicit_sha && explicit_branch ? nil : pull_request_head(env)
|
|
414
|
+
|
|
381
415
|
# `||` short-circuits, which is the whole of "do not spawn a subprocess
|
|
382
416
|
# when a provider already answered".
|
|
383
|
-
@
|
|
417
|
+
@commit_sha = explicit_sha ||
|
|
418
|
+
pr_head&.fetch(:sha) ||
|
|
419
|
+
first_present(env, COMMIT_SHA_KEYS) ||
|
|
420
|
+
blank_to_nil(git.commit_sha)
|
|
421
|
+
@branch = explicit_branch ||
|
|
422
|
+
(pr_head && first_present(env, PULL_REQUEST_BRANCH_KEYS)) ||
|
|
423
|
+
first_present(env, BRANCH_KEYS) ||
|
|
424
|
+
blank_to_nil(git.branch)
|
|
384
425
|
@run_id = first_present(env, RUN_ID_KEYS)
|
|
385
426
|
@shard_id = resolve_shard_id(env)
|
|
386
427
|
@output_path = first_present(env, OUTPUT_PATH_KEYS) || DEFAULT_OUTPUT_PATH
|
|
@@ -393,6 +434,65 @@ module SpecGuard
|
|
|
393
434
|
|
|
394
435
|
private
|
|
395
436
|
|
|
437
|
+
# The pushed head of a GitHub Actions pull-request run, or nil when it
|
|
438
|
+
# cannot be established as a SAME-REPOSITORY pull request.
|
|
439
|
+
#
|
|
440
|
+
# On `pull_request` / `pull_request_target`, `GITHUB_SHA` is the
|
|
441
|
+
# ephemeral merge commit (the base tip on `_target`) and
|
|
442
|
+
# `GITHUB_REF_NAME` is `<n>/merge` — neither is anything a person pushed.
|
|
443
|
+
# `git rev-parse HEAD` does not rescue it: `actions/checkout` puts the
|
|
444
|
+
# merge commit at HEAD. The real head sha lives only in the event payload
|
|
445
|
+
# at `GITHUB_EVENT_PATH`.
|
|
446
|
+
#
|
|
447
|
+
# A fork PR yields nil: `GITHUB_HEAD_REF` is then the FORK's branch name
|
|
448
|
+
# (`main` on a `contrib:main` PR would be filed under the base
|
|
449
|
+
# repository's own `main`), so the merge-ref behaviour is kept. A
|
|
450
|
+
# missing, unreadable, oversized or garbled payload also yields nil.
|
|
451
|
+
# Never raises and shells out to nothing.
|
|
452
|
+
#
|
|
453
|
+
# @return [Hash{Symbol=>String,nil}, nil] `{sha:}` — sha is nil when the
|
|
454
|
+
# payload's head sha is not 40 hex characters (the branch is still the
|
|
455
|
+
# source branch then) — or nil when this is not a same-repo PR.
|
|
456
|
+
def pull_request_head(env)
|
|
457
|
+
return nil unless PULL_REQUEST_EVENTS.include?(first_present(env, EVENT_NAME_KEYS))
|
|
458
|
+
|
|
459
|
+
path = first_present(env, EVENT_PATH_KEYS)
|
|
460
|
+
return nil if path.nil?
|
|
461
|
+
|
|
462
|
+
pull_request = read_event_payload(path)&.fetch("pull_request", nil)
|
|
463
|
+
return nil unless pull_request.is_a?(Hash)
|
|
464
|
+
|
|
465
|
+
head = pull_request["head"]
|
|
466
|
+
base = pull_request["base"]
|
|
467
|
+
head_repo = repo_full_name(head)
|
|
468
|
+
return nil if head_repo.nil? || head_repo != repo_full_name(base)
|
|
469
|
+
|
|
470
|
+
sha = head["sha"]
|
|
471
|
+
{ sha: sha.is_a?(String) && sha.match?(/\A[0-9a-f]{40}\z/i) ? sha : nil }
|
|
472
|
+
rescue ScriptError, StandardError
|
|
473
|
+
nil
|
|
474
|
+
end
|
|
475
|
+
|
|
476
|
+
def repo_full_name(side)
|
|
477
|
+
return nil unless side.is_a?(Hash) && side["repo"].is_a?(Hash)
|
|
478
|
+
|
|
479
|
+
name = side["repo"]["full_name"]
|
|
480
|
+
name.is_a?(String) && !name.empty? ? name : nil
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
# @return [Hash, nil] the parsed payload, or nil if it is absent, not a
|
|
484
|
+
# regular file, larger than {MAX_EVENT_PAYLOAD_BYTES}, or not a JSON
|
|
485
|
+
# object.
|
|
486
|
+
def read_event_payload(path)
|
|
487
|
+
return nil unless File.file?(path)
|
|
488
|
+
|
|
489
|
+
raw = File.open(path, "rb") { |file| file.read(MAX_EVENT_PAYLOAD_BYTES + 1) }
|
|
490
|
+
return nil if raw.nil? || raw.bytesize > MAX_EVENT_PAYLOAD_BYTES
|
|
491
|
+
|
|
492
|
+
parsed = JSON.parse(raw)
|
|
493
|
+
parsed.is_a?(Hash) ? parsed : nil
|
|
494
|
+
end
|
|
495
|
+
|
|
396
496
|
# {SHARD_ID_KEYS} in order, first non-blank wins — except that a
|
|
397
497
|
# {BLANK_MEANS_FIRST_SHARD_KEY} which is *set* counts as a hit even when
|
|
398
498
|
# it is empty, and resolves to `"1"`.
|
data/lib/specguard/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: specguard-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.33
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- specguard Agent
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|