Skip to content

Commit f6e1cb5

Browse files
committed
Some action tweaks
1 parent 6d6b3c7 commit f6e1cb5

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ jobs:
9191
draft: false
9292
prerelease: false
9393

94+
- name: Mark release as latest
95+
run: |
96+
TAG=${{ steps.get_version.outputs.tag }}
97+
REPO="${{ github.repository }}"
98+
99+
# Get the release ID
100+
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
101+
"https://api.github.com/repos/${REPO}/releases/tags/${TAG}" | \
102+
grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
103+
104+
if [ -n "$RELEASE_ID" ]; then
105+
# Mark as latest
106+
curl -X PATCH \
107+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
108+
-H "Accept: application/vnd.github.v3+json" \
109+
"https://api.github.com/repos/${REPO}/releases/${RELEASE_ID}" \
110+
-d '{"make_latest": true}'
111+
echo "✅ Release marked as latest"
112+
else
113+
echo "⚠️ Could not find release ID for tag ${TAG}"
114+
fi
115+
94116
- name: Wait for GitHub to generate tarball
95117
run: sleep 10
96118

@@ -120,6 +142,15 @@ jobs:
120142
121143
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
122144
145+
- name: Checkout main branch
146+
run: |
147+
# Determine the default branch name
148+
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
149+
150+
# Checkout the default branch (tags are in detached HEAD state)
151+
git checkout "$DEFAULT_BRANCH"
152+
git pull origin "$DEFAULT_BRANCH"
153+
123154
- name: Update Homebrew formula
124155
run: |
125156
TAG=${{ steps.get_version.outputs.tag }}
@@ -139,9 +170,8 @@ jobs:
139170
TAG=${{ steps.get_version.outputs.tag }}
140171
BRANCH_NAME="update-homebrew-formula-${TAG}"
141172
142-
# Checkout the main branch (tags are in detached HEAD state)
143-
git checkout main || git checkout master
144-
git pull
173+
# Determine the default branch name again
174+
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
145175
146176
# Check if there are changes
147177
if git diff --quiet Formula/swift-mock-generator.rb; then
@@ -160,4 +190,4 @@ jobs:
160190
git push -u origin "$BRANCH_NAME"
161191
162192
echo "✅ Branch '$BRANCH_NAME' created and pushed successfully"
163-
echo "You can now create a PR from this branch to main"
193+
echo "You can now create a PR from this branch to $DEFAULT_BRANCH"

0 commit comments

Comments
 (0)