Skip to content

Commit f094082

Browse files
committed
Move the version check into the same job
1 parent 23dd078 commit f094082

1 file changed

Lines changed: 26 additions & 39 deletions

File tree

.github/workflows/reusable-upgrade-testing.yml

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,6 @@ on:
4242
permissions: {}
4343

4444
jobs:
45-
# Checks that a valid version range is being tested.
46-
#
47-
# Upgrade testing should not occur when the original version is greater than or equal to the new version.
48-
check-version:
49-
name: Check for a valid test scenario
50-
runs-on: ${{ inputs.os }}
51-
permissions:
52-
contents: read
53-
timeout-minutes: 5
54-
55-
steps:
56-
- name: Compare versions
57-
id: compare
58-
run: |
59-
old="${{ inputs.old_version }}"
60-
new="${{ inputs.new_version }}"
61-
62-
# Normalize versions to X.Y.Z format (add .0 if needed)
63-
normalize() {
64-
local ver=$1
65-
if [[ $ver =~ ^[0-9]+\.[0-9]+$ ]]; then
66-
echo "${ver}.0"
67-
else
68-
echo "$ver"
69-
fi
70-
}
71-
72-
old_norm=$(normalize "$old")
73-
new_norm=$(normalize "$new")
74-
75-
# Compare using sort -V (version sort)
76-
if printf '%s\n%s\n' "$old_norm" "$new_norm" | sort -V -C; then
77-
echo "result=true" >> "$GITHUB_OUTPUT"
78-
else
79-
echo "result=false" >> "$GITHUB_OUTPUT"
80-
fi
81-
8245
# Runs upgrade tests on a build of WordPress.
8346
#
8447
# Performs the following steps:
@@ -95,8 +58,6 @@ jobs:
9558
# - Checks the version of WordPress after the upgrade.
9659
upgrade-tests:
9760
name: ${{ inputs.wp }} to ${{ inputs.new-version }} / PHP ${{ inputs.php }} with ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.multisite && ' multisite' || '' }}
98-
needs: [ check-version ]
99-
if: ${{ needs.check-version.outputs.should_run == 'true' }}
10061
permissions:
10162
contents: read
10263
runs-on: ${{ inputs.os }}
@@ -118,39 +79,63 @@ jobs:
11879
-c "exec docker-entrypoint.sh mysqld${{ inputs.db-type == 'mysql' && contains( fromJSON('["7.2", "7.3"]'), inputs.php ) && ' --default-authentication-plugin=mysql_native_password' || '' }}"
11980
12081
steps:
82+
- name: Compare versions
83+
id: version_check
84+
env:
85+
OLD_VERSION: ${{ inputs.wp }}
86+
NEW_VERSION: ${{ inputs.new-version }}
87+
run: |
88+
# Add .0 if version is X.Y format
89+
[[ $OLD_VERSION =~ ^[0-9]+\.[0-9]+$ ]] && OLD_VERSION+=".0"
90+
[[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+$ ]] && NEW_VERSION+=".0"
91+
92+
if printf '%s\n%s\n' "$OLD_VERSION" "$NEW_VERSION" | sort -V -C; then
93+
echo "valid=true" >> "$GITHUB_OUTPUT"
94+
else
95+
echo "valid=false" >> "$GITHUB_OUTPUT"
96+
fi
97+
12198
- name: Set up PHP ${{ inputs.php }}
12299
uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2.35.3
100+
if: ${{ steps.version_check.outputs.valid == 'true' }}
123101
with:
124102
php-version: '${{ inputs.php }}'
125103
coverage: none
126104
tools: wp-cli
127105

128106
- name: Download WordPress ${{ inputs.wp }}
107+
if: ${{ steps.version_check.outputs.valid == 'true' }}
129108
run: wp core download --version="${WP_VERSION}"
130109
env:
131110
WP_VERSION: ${{ inputs.wp }}
132111

133112
- name: Create wp-config.php file
113+
if: ${{ steps.version_check.outputs.valid == 'true' }}
134114
run: wp config create --dbname=test_db --dbuser=root --dbpass=root --dbhost="127.0.0.1:${DB_PORT}"
135115
env:
136116
DB_PORT: ${{ job.services.database.ports['3306'] }}
137117

138118
- name: Install WordPress
119+
if: ${{ steps.version_check.outputs.valid == 'true' }}
139120
run: |
140121
wp core ${{ inputs.multisite && 'multisite-install' || 'install' }} \
141122
--url=http://localhost/ --title="Upgrade Test" --admin_user=admin \
142123
--admin_password=password --admin_email=me@example.org --skip-email
143124
144125
- name: Pre-upgrade version check
126+
if: ${{ steps.version_check.outputs.valid == 'true' }}
145127
run: wp core version
146128

147129
- name: Update to the latest minor version
130+
if: ${{ steps.version_check.outputs.valid == 'true' }}
148131
run: wp core update --minor
149132

150133
- name: Update the database after the minor update
134+
if: ${{ steps.version_check.outputs.valid == 'true' }}
151135
run: wp core update-db ${{ inputs.multisite && '--network' || '' }}
152136

153137
- name: Post-upgrade version check after the minor update
138+
if: ${{ steps.version_check.outputs.valid == 'true' }}
154139
run: wp core version
155140

156141
- name: Download build artifact for the current branch
@@ -172,7 +157,9 @@ jobs:
172157
WP_VERSION: ${{ inputs.new-version }}
173158

174159
- name: Update the database
160+
if: ${{ steps.version_check.outputs.valid == 'true' }}
175161
run: wp core update-db ${{ inputs.multisite && '--network' || '' }}
176162

177163
- name: Post-upgrade version check
164+
if: ${{ steps.version_check.outputs.valid == 'true' }}
178165
run: wp core version

0 commit comments

Comments
 (0)