Skip to content

Commit a0bb5c4

Browse files
committed
Improve version handling in zip file
1 parent cb3ff55 commit a0bb5c4

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

.github/workflows/playground.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
actions: read
1313

1414
steps:
15-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1616

1717
# Prepare a folder named exactly like the repo as the plugin root.
1818
# If the repo already has such a folder (common for WP plugins), use it.
@@ -45,9 +45,30 @@ jobs:
4545
PLUGIN_FILE="${{ steps.prep.outputs.PKG_DIR }}/${{ github.event.repository.name }}.php"
4646
PR_NUMBER="${{ github.event.number }}"
4747
48-
# Extract current version and add PR number
48+
# Extract current version
4949
CURRENT_VERSION=$(grep -o "Version:[[:space:]]*[0-9.]*" "$PLUGIN_FILE" | sed 's/Version:[[:space:]]*//')
50-
NEW_VERSION="${CURRENT_VERSION} - PR ${PR_NUMBER}"
50+
51+
# Increment patch version if it exists, otherwise increment minor version
52+
# Handle versions like 2.1.5 or 2.1
53+
if [[ "$CURRENT_VERSION" =~ ^([0-9]+)\.([0-9]+)(\.([0-9]+))?$ ]]; then
54+
MAJOR="${BASH_REMATCH[1]}"
55+
MINOR="${BASH_REMATCH[2]}"
56+
PATCH="${BASH_REMATCH[4]}"
57+
58+
# Build new version with 'b' suffix
59+
if [ -n "$PATCH" ]; then
60+
# If patch exists, increment patch by 1
61+
PATCH=$((PATCH + 1))
62+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}b - PR ${PR_NUMBER}"
63+
else
64+
# If no patch, increment minor by 1
65+
MINOR=$((MINOR + 1))
66+
NEW_VERSION="${MAJOR}.${MINOR}b - PR ${PR_NUMBER}"
67+
fi
68+
else
69+
# Fallback: if version format is unexpected, just add .1 and 'b'
70+
NEW_VERSION="${CURRENT_VERSION}.1b - PR ${PR_NUMBER}"
71+
fi
5172
5273
# Replace the version line
5374
sed -i "s/Version:[[:space:]]*[0-9.]*/Version: ${NEW_VERSION}/" "$PLUGIN_FILE"
@@ -76,7 +97,7 @@ jobs:
7697
# Upload the FOLDER (not a .zip). The artifact service zips it for us,
7798
# keeping the top-level folder name inside the archive.
7899
- name: Upload plugin artifact
79-
uses: actions/upload-artifact@v4
100+
uses: actions/upload-artifact@v5
80101
with:
81102
name: ${{ github.event.repository.name }}
82103
path: ${{ steps.prep.outputs.PKG_DIR }}

0 commit comments

Comments
 (0)