-
Notifications
You must be signed in to change notification settings - Fork 0
feat(release): add build-identifier script (epic 005 T006) #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
| # Computes the deterministic build identifier for a release run (FR-005): | ||
| # GITHUB_RUN_NUMBER.GITHUB_RUN_ATTEMPT, both required to be present and | ||
| # numeric so "strictly increase" can later be evaluated numerically as the | ||
| # pair (GITHUB_RUN_NUMBER, GITHUB_RUN_ATTEMPT) (SC-003). | ||
| set -euo pipefail | ||
|
|
||
| run_number="${GITHUB_RUN_NUMBER:-}" | ||
| run_attempt="${GITHUB_RUN_ATTEMPT:-}" | ||
|
|
||
| if [ -z "$run_number" ] || [ -z "$run_attempt" ]; then | ||
| echo "error: GITHUB_RUN_NUMBER and GITHUB_RUN_ATTEMPT must both be set" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! [[ "$run_number" =~ ^[0-9]+$ ]] || ! [[ "$run_attempt" =~ ^[0-9]+$ ]]; then | ||
| echo "error: GITHUB_RUN_NUMBER ('$run_number') and GITHUB_RUN_ATTEMPT ('$run_attempt') must both be base-10 integers" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "${run_number}.${run_attempt}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bash | ||
| # Fixture-based tests for build-identifier.sh (T006, Constitution I). Run | ||
| # manually: | ||
| # bash .github/scripts/tests/test-build-identifier.sh | ||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| script="$script_dir/../build-identifier.sh" | ||
|
|
||
| pass=0 | ||
| fail=0 | ||
|
|
||
| check_eq() { | ||
| local desc="$1" expected="$2" actual="$3" | ||
| if [ "$expected" == "$actual" ]; then | ||
| pass=$((pass + 1)) | ||
| else | ||
| fail=$((fail + 1)) | ||
| echo "FAIL: $desc (expected '$expected', got '$actual')" | ||
| fi | ||
| } | ||
|
|
||
| assert_fail() { | ||
| local desc="$1"; shift | ||
| if "$@" >/dev/null 2>&1; then | ||
| fail=$((fail + 1)) | ||
| echo "FAIL (expected failure but succeeded): $desc" | ||
| else | ||
| pass=$((pass + 1)) | ||
| fi | ||
| } | ||
|
|
||
| out="$(GITHUB_RUN_NUMBER=42 GITHUB_RUN_ATTEMPT=1 bash "$script")" | ||
| check_eq "basic case" "42.1" "$out" | ||
|
|
||
| out="$(GITHUB_RUN_NUMBER=1 GITHUB_RUN_ATTEMPT=3 bash "$script")" | ||
| check_eq "retry attempt" "1.3" "$out" | ||
|
|
||
| assert_fail "missing GITHUB_RUN_NUMBER fails" env -u GITHUB_RUN_NUMBER GITHUB_RUN_ATTEMPT=1 bash "$script" | ||
| assert_fail "missing GITHUB_RUN_ATTEMPT fails" env GITHUB_RUN_NUMBER=1 -u GITHUB_RUN_ATTEMPT bash "$script" | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
|
||
| assert_fail "non-numeric run number fails" env GITHUB_RUN_NUMBER=abc GITHUB_RUN_ATTEMPT=1 bash "$script" | ||
| assert_fail "non-numeric run attempt fails" env GITHUB_RUN_NUMBER=1 GITHUB_RUN_ATTEMPT=abc bash "$script" | ||
| assert_fail "negative number fails (not base-10 unsigned per FR-005)" env GITHUB_RUN_NUMBER=-1 GITHUB_RUN_ATTEMPT=1 bash "$script" | ||
|
|
||
| # Numeric-pair ordering sanity (SC-003's "strictly increasing" comparison | ||
| # basis) -- not exercised by the script itself, but documents the contract | ||
| # callers must use rather than lexicographic string comparison. | ||
| a_run=9; a_attempt=9 | ||
|
rsenna marked this conversation as resolved.
|
||
| b_run=10; b_attempt=1 | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| if [ "$a_run" -lt "$b_run" ]; then | ||
| pass=$((pass + 1)) | ||
| else | ||
| fail=$((fail + 1)) | ||
| echo "FAIL: numeric run-number comparison sanity check" | ||
| fi | ||
|
|
||
| echo "----" | ||
| echo "pass=$pass fail=$fail" | ||
| [ "$fail" -eq 0 ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.