Skip to content

Commit 220657c

Browse files
committed
fix: address all Copilot review comments
- Add error handling for grep commands with validation - Validate version code is a valid number before comparison - Remove duplicate version code extraction logic - Fix tag exists exit code to use output variables instead All 4 new Copilot comments have been addressed with proper error handling
1 parent 808fa2c commit 220657c

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,24 @@ jobs:
5454
id: check_version
5555
if: github.event_name == 'push'
5656
run: |
57-
# Get current version from config.gradle
58-
CURRENT_VERSION=$(grep versionName config.gradle | sed -E 's/.*versionName:\s*"([^"]+)".*/\1/')
59-
CURRENT_CODE=$(grep versionCode config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/')
57+
# Get current version from config.gradle with error handling
58+
CURRENT_VERSION=$(grep versionName config.gradle | sed -E 's/.*versionName:\s*"([^"]+)".*/\1/' || echo "")
59+
CURRENT_CODE=$(grep versionCode config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/' || echo "")
60+
61+
# Validate extraction was successful
62+
if [ -z "$CURRENT_VERSION" ] || [ -z "$CURRENT_CODE" ]; then
63+
echo "❌ Error: Failed to extract version information from config.gradle"
64+
echo "CURRENT_VERSION='$CURRENT_VERSION', CURRENT_CODE='$CURRENT_CODE'"
65+
echo "should_release=false" >> $GITHUB_OUTPUT
66+
exit 1
67+
fi
68+
69+
# Validate CURRENT_CODE is a valid number
70+
if ! [[ "$CURRENT_CODE" =~ ^[0-9]+$ ]]; then
71+
echo "❌ Error: Version code is not a valid number: $CURRENT_CODE"
72+
echo "should_release=false" >> $GITHUB_OUTPUT
73+
exit 1
74+
fi
6075
6176
# Get previous version - handle first commit case
6277
if git rev-parse HEAD~1 >/dev/null 2>&1; then
@@ -75,11 +90,16 @@ jobs:
7590
PREV_CODE="0"
7691
fi
7792
93+
# Validate PREV_CODE is a valid number (default to 0 if not)
94+
if ! [[ "$PREV_CODE" =~ ^[0-9]+$ ]]; then
95+
PREV_CODE="0"
96+
fi
97+
7898
echo "Previous: v$PREV_VERSION (code: $PREV_CODE)"
7999
echo "Current: v$CURRENT_VERSION (code: $CURRENT_CODE)"
80100
81101
# Check if version increased
82-
if [ -n "$CURRENT_VERSION" ] && [ "$CURRENT_CODE" -gt "$PREV_CODE" ]; then
102+
if [ "$CURRENT_CODE" -gt "$PREV_CODE" ]; then
83103
echo "✅ Version increased from $PREV_VERSION to $CURRENT_VERSION"
84104
echo "should_release=true" >> $GITHUB_OUTPUT
85105
echo "version=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
@@ -108,30 +128,39 @@ jobs:
108128
- name: Extract version code
109129
id: version_info
110130
run: |
111-
# Extract version code from config.gradle
112-
VERSION_CODE=$(grep "versionCode:" config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/')
131+
# Use version code from check_version step if available, otherwise extract it
132+
if [ -n "${{ steps.check_version.outputs.version_code }}" ]; then
133+
VERSION_CODE="${{ steps.check_version.outputs.version_code }}"
134+
else
135+
# Only extract if not already available (for workflow_dispatch)
136+
VERSION_CODE=$(grep "versionCode:" config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/')
137+
fi
113138
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT
114139
echo "Version Code: $VERSION_CODE"
115140
116141
- name: Create and push tag
117142
if: steps.check_version.outputs.should_release == 'true' && github.event_name == 'push'
143+
id: create_tag
118144
run: |
119145
TAG_NAME="${{ steps.version.outputs.version }}"
120146
121147
# Check if tag already exists
122148
if git ls-remote --tags origin | grep -q "refs/tags/${TAG_NAME}$"; then
123-
echo "⚠️ Tag $TAG_NAME already exists"
124-
exit 0
149+
echo "⚠️ Tag $TAG_NAME already exists, skipping tag creation"
150+
echo "tag_created=false" >> $GITHUB_OUTPUT
151+
echo "tag_exists=true" >> $GITHUB_OUTPUT
152+
else
153+
git config user.name "github-actions[bot]"
154+
git config user.email "github-actions[bot]@users.noreply.github.com"
155+
156+
# Create annotated tag
157+
git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME} (version code: ${{ steps.version_info.outputs.version_code }})"
158+
git push origin "${TAG_NAME}"
159+
160+
echo "🏷️ Created and pushed tag: ${TAG_NAME}"
161+
echo "tag_created=true" >> $GITHUB_OUTPUT
162+
echo "tag_exists=false" >> $GITHUB_OUTPUT
125163
fi
126-
127-
git config user.name "github-actions[bot]"
128-
git config user.email "github-actions[bot]@users.noreply.github.com"
129-
130-
# Create annotated tag
131-
git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME} (version code: ${{ steps.version_info.outputs.version_code }})"
132-
git push origin "${TAG_NAME}"
133-
134-
echo "🏷️ Created and pushed tag: ${TAG_NAME}"
135164
136165
build-apk:
137166
name: Build Release APK

0 commit comments

Comments
 (0)