Skip to content

Commit

Permalink
Performance Tests Workflow: Polish Bash script (#32284)
Browse files Browse the repository at this point in the history
* Workflows: Performance: Avoid non-POSIX `grep -P`

`grep -P` is a GNU extension to use PCRE regular expressions. While it
is commonly available on GNU/Linux systems, it is not POSIX and cannot
be guaranteed to exist. By replacing it with POSIX-compliant AWK, this
workflow is easier to test locally on different systems, including all
BSD-derived ones.

* Workflows: Performance: Use safer or more modern Bash

* Prefer `$(( ... ))` over antiquated `expr`
* Use double quotes to prevent globbing and word splitting
* Condense `read` options... just because

As a general note, Shellcheck [1] is an excellent tool for linting and
validating shell scripts.

[1]: https://www.shellcheck.net/

* Workflows: Performance: Explicitly require Bash shell

The `run` block for the "Compare performance with current WordPress Core
and previous Gutenberg versions" job relies on a series of Bashisms, so
we should make that an explicit requirement.
  • Loading branch information
mcsf authored May 27, 2021
1 parent c2d96df commit 938fc9e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ jobs:
if: github.event_name == 'release'
env:
PLUGIN_VERSION: ${{ github.event.release.name }}
shell: bash
run: |
IFS='.' read -r -a PLUGIN_VERSION_ARRAY <<< "$PLUGIN_VERSION"
IFS=. read -ra PLUGIN_VERSION_ARRAY <<< "$PLUGIN_VERSION"
CURRENT_RELEASE_BRANCH="release/${PLUGIN_VERSION_ARRAY[0]}.${PLUGIN_VERSION_ARRAY[1]}"
PREVIOUS_VERSION_BASE_10=$(expr ${PLUGIN_VERSION_ARRAY[0]} \* 10 + ${PLUGIN_VERSION_ARRAY[1]} - 1)
PREVIOUS_RELEASE_BRANCH="release/$(expr $PREVIOUS_VERSION_BASE_10 / 10).$(expr $PREVIOUS_VERSION_BASE_10 % 10)"
TESTED_UP_TO_REGEX="Tested up to: \K([0-9]+)\.([0-9]+)\.?([0-9]?)"
WP_VERSION=$(grep -oP "$TESTED_UP_TO_REGEX" ./readme.txt)
IFS='.' read -r -a WP_VERSION_ARRAY <<< "$WP_VERSION"
PREVIOUS_VERSION_BASE_10=$((PLUGIN_VERSION_ARRAY[0] * 10 + PLUGIN_VERSION_ARRAY[1] - 1))
PREVIOUS_RELEASE_BRANCH="release/$((PREVIOUS_VERSION_BASE_10 / 10)).$((PREVIOUS_VERSION_BASE_10 % 10))"
WP_VERSION=$(awk -F ': ' '/^Tested up to/{print $2}' readme.txt)
IFS=. read -ra WP_VERSION_ARRAY <<< "$WP_VERSION"
WP_BRANCH="wp/${WP_VERSION_ARRAY[0]}.${WP_VERSION_ARRAY[1]}"
./bin/plugin/cli.js perf --ci $WP_BRANCH $PREVIOUS_RELEASE_BRANCH $CURRENT_RELEASE_BRANCH --tests-branch $WP_BRANCH
./bin/plugin/cli.js perf --ci "$WP_BRANCH" "$PREVIOUS_RELEASE_BRANCH" "$CURRENT_RELEASE_BRANCH" --tests-branch "$WP_BRANCH"

0 comments on commit 938fc9e

Please sign in to comment.