@@ -76,22 +76,62 @@ jobs:
7676 token : ${{ secrets.github-token }}
7777
7878 # Step 1.5: Get SHA of the github-tools branch
79- - name : Get github-tools branch SHA
80- id : get-sha
79+ - name : Smart SHA resolution
80+ id : resolve
8181 run : |
82- # Extract branch name from workflow_ref
83- BRANCH_REF="${{ github.workflow_ref }}"
84- echo "Full workflow ref: $BRANCH_REF"
85-
86- # Extract just the branch name from refs/heads/branch-name
87- BRANCH_NAME=$(echo "$BRANCH_REF" | sed 's/.*@refs\/heads\///')
88- echo "Extracted branch name: $BRANCH_NAME"
89-
90- # Get the SHA of the branch
91- SHA=$(git ls-remote https://github.com/MetaMask/github-tools.git "refs/heads/$BRANCH_NAME" | cut -f1)
92- echo "Branch SHA: $SHA"
93-
94- # Set as output
82+
83+ echo "=== SHA Resolution Debug ==="
84+ echo "github.workflow_ref: ${{ github.workflow_ref }}"
85+ echo "github.sha: ${{ github.sha }}"
86+ echo "github.ref: ${{ github.ref }}"
87+ echo "=========================="
88+
89+ WORKFLOW_REF="${{ github.workflow_ref }}"
90+
91+ # Try multiple patterns to extract SHA
92+ if [[ "$WORKFLOW_REF" =~ @([a-f0-9]{40})$ ]]; then
93+
94+ # Full 40-character SHA
95+ SHA="${BASH_REMATCH[1]}"
96+ echo "Found full SHA: $SHA"
97+
98+ elif [[ "$WORKFLOW_REF" =~ @([a-f0-9]{7,})$ ]]; then
99+ # Shorter SHA (7+ characters)
100+ SHORT_SHA="${BASH_REMATCH[1]}"
101+ echo "Found short SHA: $SHORT_SHA"
102+
103+ # Resolve to full SHA via API
104+ REPO=$(echo "$WORKFLOW_REF" | sed 's/@.*//')
105+
106+ SHA=$(curl -s -H "Authorization: token ${{ github.token }}" \
107+ "https://api.github.com/repos/$REPO/commits/$SHORT_SHA" | \
108+ jq -r '.sha // empty')
109+
110+ if [ -n "$SHA" ] && [ "$SHA" != "null" ]; then
111+ echo "Resolved to full SHA: $SHA"
112+ else
113+ echo "Failed to resolve short SHA, using as-is: $SHORT_SHA"
114+ SHA="$SHORT_SHA"
115+ fi
116+
117+ else
118+ # Extract branch/tag and resolve
119+ REF=$(echo "$WORKFLOW_REF" | sed 's/.*@//')
120+ REPO=$(echo "$WORKFLOW_REF" | sed 's/@.*//')
121+ echo "Resolving branch/tag '$REF' to SHA..."
122+ SHA=$(curl -s -H "Authorization: token ${{ github.token }}" \
123+ "https://api.github.com/repos/$REPO/commits/$REF" | \
124+ jq -r '.sha // empty')
125+
126+ if [ -n "$SHA" ] && [ "$SHA" != "null" ]; then
127+ echo "Resolved '$REF' to SHA: $SHA"
128+ else
129+ echo "Failed to resolve, using github.sha: ${{ github.sha }}"
130+ SHA="${{ github.sha }}"
131+ fi
132+ fi
133+
134+ echo "Final SHA: $SHA"
95135 echo "sha=$SHA" >> $GITHUB_OUTPUT
96136
97137 # Step 2: Checkout github-tools repository
@@ -104,10 +144,10 @@ jobs:
104144 ref : ${{ steps.get-sha.outputs.sha }}
105145
106146 # Step 3: Setup environment from github-tools
107- - name : Checkout and setup environment
108- uses : ./github-tools/.github/actions/checkout-and-setup
109- with :
110- is-high-risk-environment : true
147+ # - name: Checkout and setup environment
148+ # uses: ./github-tools/.github/actions/checkout-and-setup
149+ # with:
150+ # is-high-risk-environment: true
111151
112152 # Step 4: Print Input Values
113153 - name : Print Input Values
0 commit comments