selective-ruby-core 0.2.8-x86_64-linux → 0.2.9-x86_64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a270fd09fb9cd882d558e32f7d394a39ff7c47b1c2d8762a84e72fd27113cfc0
4
- data.tar.gz: 0a014564409691b0fa5c298aa96db0614a2702e663adefbc8577af425812e1f2
3
+ metadata.gz: 369c09163355a9d86417468a38a5768d77cc9fc53903ee453c1c34eb79eb04d7
4
+ data.tar.gz: ac08486406ee1073707bfae1c302f7344d7f7342a3f0800ee91b01c1400fa262
5
5
  SHA512:
6
- metadata.gz: 93cb6c86f820709d59f5cce287516f9e0284c71375f686022c04d69ccdfb428937f1a96ec85f1574e316f11863d73fb41bd07fd9a115134c32fd17bbbadd0d05
7
- data.tar.gz: 867a6d14e18eb8d486424bc1d09335fbf458ce286e71637e947829890d0f422babc8d20644bf7c846965b339809aa3f8171641bb6f1b2c691757abe6e3d3b40c
6
+ metadata.gz: 47ce141d533247886053e389d1e4c70494cc6e88bf33121a8d2a53b2cd0308d82d40680c1d18d0990e5934e0a3ef0c79314a127587617d18ecb93050fbc65d88
7
+ data.tar.gz: 968cb36da6363776c63daeb80e0bb799dcfe33662204a6a6664fef161d457060ef37870d32ea4dd91407e02f6b3a849bb2e764abf14096922322a762a0cdbc8f
data/lib/bin/build_env.sh CHANGED
@@ -1,6 +1,28 @@
1
1
  #!/bin/bash
2
2
 
3
- # Detect the platform (only GitHub Actions in this case)
3
+ # Parse an "owner/repo" slug out of a git remote URL (SSH or HTTPS) that points
4
+ # at github.com. Emits an empty string when the URL is not a github.com URL.
5
+ parse_github_slug() {
6
+ local url="$1"
7
+ case "$url" in
8
+ git@github.com:*|git://github.com/*|https://github.com/*|http://github.com/*|ssh://git@github.com/*)
9
+ echo "$url" | sed -E 's#^(git@|(git|https?|ssh)://(git@)?)github\.com[:/]##; s#\.git/?$##'
10
+ ;;
11
+ esac
12
+ }
13
+
14
+ # Given a git remote URL, classify the provider as github|gitlab|bitbucket or
15
+ # empty when unrecognized. Used for the git_provider hint.
16
+ detect_git_provider_from_url() {
17
+ local url="$1"
18
+ case "$url" in
19
+ *github.com*) echo "github" ;;
20
+ *gitlab.com*) echo "gitlab" ;;
21
+ *bitbucket.org*) echo "bitbucket" ;;
22
+ esac
23
+ }
24
+
25
+ # Detect the platform
4
26
  if [ -n "$GITHUB_ACTIONS" ]; then
5
27
  platform=github_actions
6
28
  branch=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}
@@ -13,6 +35,24 @@ if [ -n "$GITHUB_ACTIONS" ]; then
13
35
  commit_message=$(git log --format=%s -n 1 $sha)
14
36
  committer_name=$(git show -s --format='%an' -n 1 $sha)
15
37
  committer_email=$(git show -s --format='%ae' -n 1 $sha)
38
+ git_repo_full_name=$GITHUB_REPOSITORY
39
+ git_provider=github
40
+ # Extract base_sha from the webhook event payload GitHub drops at
41
+ # $GITHUB_EVENT_PATH. Prefer jq when available (handles both push and PR
42
+ # events); fall back to a grep-based parse for the top-level "before" field
43
+ # on push events when jq is missing.
44
+ if [ -f "$GITHUB_EVENT_PATH" ]; then
45
+ if command -v jq >/dev/null 2>&1; then
46
+ base_sha=$(jq -r '.pull_request.base.sha // .before // empty' < "$GITHUB_EVENT_PATH" 2>/dev/null)
47
+ else
48
+ base_sha=$(grep -o '"before"[[:space:]]*:[[:space:]]*"[^"]*"' "$GITHUB_EVENT_PATH" | head -1 | sed -E 's/.*"[^"]*"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/')
49
+ fi
50
+ # GitHub emits all-zero SHAs when the ref was just created and has no prior
51
+ # state. Treat that as "no base" so the server falls through to head-only.
52
+ if [ "$base_sha" = "0000000000000000000000000000000000000000" ]; then
53
+ base_sha=""
54
+ fi
55
+ fi
16
56
  elif [ -n "$CIRCLECI" ]; then
17
57
  platform=circleci
18
58
  branch=$CIRCLE_BRANCH
@@ -23,6 +63,19 @@ elif [ -n "$CIRCLECI" ]; then
23
63
  commit_message=$(git log --format=%s -n 1 $sha)
24
64
  committer_name=$(git show -s --format='%an' -n 1 $sha)
25
65
  committer_email=$(git show -s --format='%ae' -n 1 $sha)
66
+ # CircleCI has no single "slug" env var. Compose from username + reponame.
67
+ # These work for both GitHub OAuth and GitHub App pipelines. For non-GitHub
68
+ # pipelines (GitLab, Bitbucket) the same vars exist but we gate on the repo
69
+ # URL to avoid emitting a non-GitHub slug.
70
+ if [ -n "$CIRCLE_PROJECT_USERNAME" ] && [ -n "$CIRCLE_PROJECT_REPONAME" ]; then
71
+ git_provider=$(detect_git_provider_from_url "$CIRCLE_REPOSITORY_URL")
72
+ if [ "$git_provider" = "github" ] || [ -z "$CIRCLE_REPOSITORY_URL" ]; then
73
+ git_repo_full_name="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}"
74
+ # If we fell through the "no repo URL" path, default provider to github
75
+ # since the slug composition path is specific to GitHub-style owner/repo.
76
+ [ -z "$git_provider" ] && git_provider=github
77
+ fi
78
+ fi
26
79
  elif [ -n "$SEMAPHORE" ]; then
27
80
  platform=semaphore
28
81
  branch=${SEMAPHORE_GIT_PR_BRANCH:-$SEMAPHORE_GIT_BRANCH}
@@ -38,6 +91,35 @@ elif [ -n "$SEMAPHORE" ]; then
38
91
  commit_message=$(git log --format=%s -n 1 $sha)
39
92
  committer_name=$(git show -s --format='%an' -n 1 $sha)
40
93
  committer_email=$(git show -s --format='%ae' -n 1 $sha)
94
+ git_provider=$SEMAPHORE_GIT_PROVIDER
95
+ if [ "$git_provider" = "github" ]; then
96
+ git_repo_full_name=$SEMAPHORE_GIT_REPO_SLUG
97
+ fi
98
+ # SEMAPHORE_GIT_COMMIT_RANGE is "<base>...<head>" on push/PR events; take the
99
+ # left side. It is unset when the build isn't commit-scoped.
100
+ if [ -n "$SEMAPHORE_GIT_COMMIT_RANGE" ]; then
101
+ base_sha=$(echo "$SEMAPHORE_GIT_COMMIT_RANGE" | sed -E 's/\.\.\..*//')
102
+ fi
103
+ elif [ -n "$BUILDKITE" ]; then
104
+ platform=buildkite
105
+ branch=$BUILDKITE_BRANCH
106
+ target_branch=$BUILDKITE_PULL_REQUEST_BASE_BRANCH
107
+ actor=$BUILDKITE_BUILD_AUTHOR
108
+ sha=$BUILDKITE_COMMIT
109
+ run_id=$BUILDKITE_BUILD_ID
110
+ run_attempt=$BUILDKITE_RETRY_COUNT
111
+ runner_id=$BUILDKITE_PARALLEL_JOB
112
+ pr_title=$BUILDKITE_PULL_REQUEST_TITLE
113
+ commit_message=$BUILDKITE_MESSAGE
114
+ committer_name=$BUILDKITE_BUILD_AUTHOR
115
+ committer_email=$BUILDKITE_BUILD_AUTHOR_EMAIL
116
+ # Buildkite tells us the provider explicitly, and BUILDKITE_REPO is the URL.
117
+ if [ "$BUILDKITE_PIPELINE_PROVIDER" = "github" ]; then
118
+ git_provider=github
119
+ git_repo_full_name=$(parse_github_slug "$BUILDKITE_REPO")
120
+ else
121
+ git_provider=$BUILDKITE_PIPELINE_PROVIDER
122
+ fi
41
123
  elif [ -n "$RWX" ]; then
42
124
  platform=rwx
43
125
  branch="${RWX_GIT_REF_NAME}"
@@ -52,6 +134,13 @@ elif [ -n "$RWX" ]; then
52
134
  commit_message="${RWX_GIT_COMMIT_SUMMARY}"
53
135
  committer_name="${RWX_GIT_COMMITTER_NAME}"
54
136
  committer_email="${RWX_GIT_COMMITTER_EMAIL}"
137
+ # RWX_GIT_REPOSITORY_NAME is extracted by the git/clone package from whatever
138
+ # URL was cloned. For non-GitHub hosts this still looks like "owner/repo" but
139
+ # points elsewhere, so cross-check the URL host before trusting it.
140
+ git_provider=$(detect_git_provider_from_url "$RWX_GIT_REPOSITORY_URL")
141
+ if [ "$git_provider" = "github" ]; then
142
+ git_repo_full_name="${RWX_GIT_REPOSITORY_NAME}"
143
+ fi
55
144
  elif [ -n "$MINT" ]; then
56
145
  platform=rwx
57
146
  branch="${MINT_GIT_REF_NAME}"
@@ -66,6 +155,27 @@ elif [ -n "$MINT" ]; then
66
155
  commit_message="${MINT_GIT_COMMIT_SUMMARY}"
67
156
  committer_name="${MINT_GIT_COMMITTER_NAME}"
68
157
  committer_email="${MINT_GIT_COMMITTER_EMAIL}"
158
+ git_provider=$(detect_git_provider_from_url "$MINT_GIT_REPOSITORY_URL")
159
+ if [ "$git_provider" = "github" ]; then
160
+ git_repo_full_name="${MINT_GIT_REPOSITORY_NAME}"
161
+ fi
162
+ fi
163
+
164
+ # Final fallbacks when we haven't resolved the GitHub slug from a known CI
165
+ # platform. Order:
166
+ # 1. Explicit SELECTIVE_GIT_REPO override (always wins; see below).
167
+ # 2. git config --get remote.origin.url on a local checkout.
168
+ if [ -z "$git_repo_full_name" ] && command -v git >/dev/null 2>&1; then
169
+ origin_url=$(git config --get remote.origin.url 2>/dev/null || true)
170
+ if [ -n "$origin_url" ]; then
171
+ parsed_slug=$(parse_github_slug "$origin_url")
172
+ if [ -n "$parsed_slug" ]; then
173
+ git_repo_full_name="$parsed_slug"
174
+ [ -z "$git_provider" ] && git_provider=github
175
+ elif [ -z "$git_provider" ]; then
176
+ git_provider=$(detect_git_provider_from_url "$origin_url")
177
+ fi
178
+ fi
69
179
  fi
70
180
 
71
181
  function escape() {
@@ -83,11 +193,14 @@ cat <<EOF
83
193
  "target_branch": "$(escape "${SELECTIVE_TARGET_BRANCH:-$target_branch}")",
84
194
  "actor": "$(escape "${SELECTIVE_ACTOR:-$actor}")",
85
195
  "sha": "$(escape "${SELECTIVE_SHA:-$sha}")",
196
+ "base_sha": "$(escape "${SELECTIVE_BASE_SHA:-$base_sha}")",
86
197
  "run_id": "$(escape "${SELECTIVE_RUN_ID:-$run_id}")",
87
198
  "run_attempt": "$(escape "${SELECTIVE_RUN_ATTEMPT:-$run_attempt}")",
88
199
  "runner_id": "$(escape "${SELECTIVE_RUNNER_ID:-$runner_id}")",
89
200
  "commit_message": "$(escape "${SELECTIVE_COMMIT_MESSAGE:-$commit_message}")",
90
201
  "committer_name": "$(escape "${SELECTIVE_COMMITTER_NAME:-$committer_name}")",
91
- "committer_email": "$(escape "${SELECTIVE_COMMITTER_EMAIL:-$committer_email}")"
202
+ "committer_email": "$(escape "${SELECTIVE_COMMITTER_EMAIL:-$committer_email}")",
203
+ "git_repo_full_name": "$(escape "${SELECTIVE_GIT_REPO:-$git_repo_full_name}")",
204
+ "git_provider": "$(escape "${SELECTIVE_GIT_PROVIDER:-$git_provider}")"
92
205
  }
93
206
  EOF
@@ -16,7 +16,10 @@ module Selective
16
16
  "platform" => "SELECTIVE_PLATFORM",
17
17
  "run_id" => "SELECTIVE_RUN_ID",
18
18
  "run_attempt" => "SELECTIVE_RUN_ATTEMPT",
19
- "branch" => "SELECTIVE_BRANCH"
19
+ "branch" => "SELECTIVE_BRANCH",
20
+ "sha" => "SELECTIVE_SHA",
21
+ "git_repo_full_name" => "SELECTIVE_GIT_REPO",
22
+ "git_provider" => "SELECTIVE_GIT_PROVIDER"
20
23
  }.freeze
21
24
 
22
25
  def initialize(runner_class, runner_args, debug: false, log: false)
@@ -3,7 +3,7 @@
3
3
  module Selective
4
4
  module Ruby
5
5
  module Core
6
- VERSION = "0.2.8"
6
+ VERSION = "0.2.9"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selective-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Benjamin Wood
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2026-04-22 00:00:00.000000000 Z
12
+ date: 2026-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: logger
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: zeitwerk
16
30
  requirement: !ruby/object:Gem::Requirement