Skip to content

Commit f636830

Browse files
authored
fix: hash extraction for source branches in forks (#3)
1 parent 5d5b385 commit f636830

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,20 @@ runs:
5959
command_prefix="/home/$USERNAME/runner-scripts/run.sh"
6060
fi
6161
62-
# Fetch the hashes (without checking out the code)
62+
# Fetch hash of main branch
6363
_hash_main=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
6464
"https://api.github.com/repos/${{ github.repository }}/commits/${{ github.base_ref }}" | jq -r '.sha')
65+
66+
# Fetch hash of feature branch (via PR number, also works for branches from forks)
67+
pr_details=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
68+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}")
69+
# Extract the repository and ref (branch name)
70+
source_repo=$(echo "$pr_details" | jq -r '.head.repo.full_name')
71+
branch_name=$(echo "$pr_details" | jq -r '.head.ref')
72+
# Get the latest commit hash from the source repository
6573
_hash_feature=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
66-
"https://api.github.com/repos/${{ github.repository }}/commits/${{ github.head_ref }}" | jq -r '.sha')
74+
"https://api.github.com/repos/$source_repo/commits/$branch_name" | jq -r '.sha')
75+
6776
echo "Main branch (${{ github.base_ref }}) hash: $_hash_main"
6877
echo "Feature branch (${{ github.head_ref }}) hash: $_hash_feature"
6978

0 commit comments

Comments
 (0)