Skip to content

Commit d18076b

Browse files
committed
ref_override
1 parent 3526768 commit d18076b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
| Input | Description | Required | Default |
8282
|-------|-------------|----------|---------|
8383
| `target_repository` | The repository to search for (e.g., `owner/repo`) | Yes | - |
84+
| `ref_override` | Explicit ref to use (bypasses extraction) | No | - |
8485
| `default_ref` | Ref to use if extraction fails | No | Target repo's default branch |
8586
| `fail_on_multiple_refs` | Whether to fail if multiple different refs are found | No | `true` |
8687

@@ -89,7 +90,7 @@ jobs:
8990
| Output | Description | Example |
9091
|--------|-------------|---------|
9192
| `ref` | The extracted ref or default | `v1.2.3`, `main`, `abc123` |
92-
| `extraction_method` | How the ref was determined | `extracted`, `default`, `error` |
93+
| `extraction_method` | How the ref was determined | `override`, `same-repo`, `extracted`, `default`, `error` |
9394

9495
## How It Works
9596

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
target_repository:
1010
description: 'The repository containing the called workflow (e.g., owner/repo)'
1111
required: true
12+
ref_override:
13+
description: 'Explicit ref to use (bypasses extraction when provided)'
14+
required: false
15+
default: ''
1216
default_ref:
1317
description: 'Default ref to use if extraction fails (if not provided, fetches target repository default branch)'
1418
required: false
@@ -37,8 +41,31 @@ runs:
3741
run: |
3842
echo "::group::Extract Called Workflow Ref"
3943
echo "Target repository: ${{ inputs.target_repository }}"
44+
echo "Ref override: ${{ inputs.ref_override }}"
4045
echo "Fail on multiple refs: ${{ inputs.fail_on_multiple_refs }}"
4146
47+
# Check for explicit ref override
48+
if [ -n "${{ inputs.ref_override }}" ]; then
49+
echo "✅ Using explicit ref override: ${{ inputs.ref_override }}"
50+
echo "ref=${{ inputs.ref_override }}" >> $GITHUB_OUTPUT
51+
echo "method=override" >> $GITHUB_OUTPUT
52+
echo "::endgroup::"
53+
exit 0
54+
fi
55+
56+
# Check if running from within the target repository
57+
if [[ "${{ github.repository }}" == "${{ inputs.target_repository }}" ]]; then
58+
echo "✅ Running from within target repository, using current ref"
59+
REF="${{ github.ref }}"
60+
# Extract just the ref name (remove refs/heads/ or refs/tags/)
61+
REF="${REF#refs/heads/}"
62+
REF="${REF#refs/tags/}"
63+
echo "ref=$REF" >> $GITHUB_OUTPUT
64+
echo "method=same-repo" >> $GITHUB_OUTPUT
65+
echo "::endgroup::"
66+
exit 0
67+
fi
68+
4269
# Determine default ref
4370
if [ -n "${{ inputs.default_ref }}" ]; then
4471
DEFAULT_REF="${{ inputs.default_ref }}"

0 commit comments

Comments
 (0)