@@ -49,11 +49,37 @@ jobs:
49
49
TAG="${{ github.event.release.tag_name }}"
50
50
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
51
51
52
- # Fetch the commit SHA for this tag
53
- git init -q
54
- git remote add origin "https://github.com/${{ github.repository }}"
55
- git fetch --depth=1 origin "refs/tags/$TAG"
56
- SHA=$(git rev-list -n 1 "$TAG")
52
+ # Method 1: Use the target_commitish from the release event if available
53
+ if [ -n "${{ github.event.release.target_commitish }}" ]; then
54
+ SHA="${{ github.event.release.target_commitish }}"
55
+ echo "Using release target_commitish: $SHA"
56
+ else
57
+ # Method 2: Use GitHub API to get the commit SHA for the tag
58
+ SHA=$(curl -sSL \
59
+ -H "Accept: application/vnd.github+json" \
60
+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
61
+ "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$TAG" \
62
+ | jq -r '.object.sha')
63
+
64
+ # If it's an annotated tag, we need to get the commit it points to
65
+ if [ -z "$SHA" ] || [ "$SHA" = "null" ]; then
66
+ # Try getting the tag object
67
+ TAG_SHA=$(curl -sSL \
68
+ -H "Accept: application/vnd.github+json" \
69
+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
70
+ "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$TAG" \
71
+ | jq -r '.object.sha')
72
+
73
+ # Get the commit SHA from the tag object
74
+ SHA=$(curl -sSL \
75
+ -H "Accept: application/vnd.github+json" \
76
+ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
77
+ "https://api.github.com/repos/${{ github.repository }}/git/tags/$TAG_SHA" \
78
+ | jq -r '.object.sha')
79
+ fi
80
+ fi
81
+
82
+ echo "Resolved commit SHA: $SHA"
57
83
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
58
84
59
85
# ----------------------------------------------------------------------
0 commit comments