Skip to content

Commit 1d0f521

Browse files
committed
ci: avoid pushing build on pull_request
1 parent f5a5706 commit 1d0f521

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

.github/workflows/build-and-release.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ jobs:
9191
env:
9292
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9393
run: |
94-
if [ "${{ github.ref_name }}" = "main" ]; then
94+
if [ "${{ github.event_name }}" = "pull_request" ]; then
95+
# For PRs, use pr-NUMBER format
96+
echo "VERSION=pr-${{ github.event.number }}" >> $GITHUB_ENV
97+
echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
98+
elif [ "${{ github.ref_name }}" = "main" ]; then
9599
# Get semantic version for main branch
96100
VERSION=$(npx semantic-release --no-ci --dry-run --branch main 2>&1 | grep -oP 'The next release version is \K[0-9]+\.[0-9]+\.[0-9]+' || echo "")
97101
if [ -z "$VERSION" ]; then
@@ -103,8 +107,9 @@ jobs:
103107
echo "SHOULD_RELEASE=true" >> $GITHUB_ENV
104108
fi
105109
else
106-
# Use branch name for develop
107-
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
110+
# Use branch name for develop (sanitize it)
111+
CLEAN_BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9.-]/-/g')
112+
echo "VERSION=$CLEAN_BRANCH" >> $GITHUB_ENV
108113
echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
109114
fi
110115
echo "Detected VERSION: $VERSION"
@@ -123,8 +128,14 @@ jobs:
123128
echo "${{ secrets.GHCR_PAT }}" > github_token
124129
export GITHUB_TOKEN="${{ secrets.GHCR_PAT }}"
125130
126-
# Build and push to both registries
127-
./build-enhanced --push --ghcr --public-ecr --platform linux/arm64,linux/amd64 tiny micro full
131+
if [ "${{ github.event_name }}" = "pull_request" ]; then
132+
# For PRs, only build (don't push)
133+
echo "PR build - testing only, not pushing"
134+
./build-enhanced --load --platform linux/arm64 tiny micro full
135+
else
136+
# For push events, build and push to both registries
137+
./build-enhanced --push --ghcr --public-ecr --platform linux/arm64,linux/amd64 tiny micro full
138+
fi
128139
129140
# Also tag latest for main branch releases
130141
if [ "${{ github.ref_name }}" = "main" ] && [ "$SHOULD_RELEASE" = "true" ]; then

0 commit comments

Comments
 (0)