From ba71767faf00eb184054bafddc46c7697c60c87a Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Fri, 22 Sep 2023 14:28:01 +0000 Subject: [PATCH] Build/Test Tools: Simplify some logic in GitHub Action workflows. This simplifies the logic within the `slack-notifications` and `failed-workflow` steps in GitHub Action workflows to use the `contains()` function and object filtering. This makes it simpler to perform the needed checks by removing the need to list out every single dependent job defined in `needs`. See #58867. git-svn-id: https://develop.svn.wordpress.org/trunk@56660 602fd350-edb4-49c9-b593-d223f7449a82 --- .github/workflows/coding-standards.yml | 6 +++--- .github/workflows/javascript-tests.yml | 5 +++-- .github/workflows/performance.yml | 5 +++-- .github/workflows/php-compatibility.yml | 5 +++-- .github/workflows/phpunit-tests.yml | 6 +++--- .github/workflows/test-and-zip-default-themes.yml | 6 +++--- .github/workflows/test-coverage.yml | 5 +++-- .github/workflows/test-npm.yml | 6 +++--- .github/workflows/test-old-branches.yml | 2 +- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 3cf5836f83..1501349cdb 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -182,7 +182,7 @@ jobs: needs: [ phpcs, jshint ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.phpcs.result == 'success' && needs.jshint.result == 'success' && 'success' || ( needs.phpcs.result == 'cancelled' || needs.jshint.result == 'cancelled' ) && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -201,8 +201,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.phpcs.result == 'cancelled' || needs.phpcs.result == 'failure' || - needs.jshint.result == 'cancelled' || needs.jshint.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/javascript-tests.yml b/.github/workflows/javascript-tests.yml index 5ba18a62c5..0fdda3be77 100644 --- a/.github/workflows/javascript-tests.yml +++ b/.github/workflows/javascript-tests.yml @@ -97,7 +97,7 @@ jobs: needs: [ test-js ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.test-js.result == 'success' && 'success' || needs.test-js.result == 'cancelled' && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -116,7 +116,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.test-js.result == 'cancelled' || needs.test-js.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index 44026c5593..4ec15b9591 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -251,7 +251,7 @@ jobs: needs: [ performance ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.performance.result == 'success' && 'success' || needs.performance.result == 'cancelled' && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -270,7 +270,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.performance.result == 'cancelled' || needs.performance.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/php-compatibility.yml b/.github/workflows/php-compatibility.yml index 5d1c5b03c3..dad158970d 100644 --- a/.github/workflows/php-compatibility.yml +++ b/.github/workflows/php-compatibility.yml @@ -122,7 +122,7 @@ jobs: needs: [ php-compatibility ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.php-compatibility.result == 'success' && 'success' || needs.php-compatibility.result == 'cancelled' && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -141,7 +141,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.php-compatibility.result == 'cancelled' || needs.php-compatibility.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 7edf916080..85f9a09f6b 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -136,7 +136,7 @@ jobs: needs: [ test-with-mysql, test-with-mariadb ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.test-with-mysql.result == 'success' && needs.test-with-mariadb.result == 'success' && 'success' || ( needs.test-with-mysql.result == 'cancelled' || needs.test-with-mariadb.result == 'cancelled' ) && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -155,8 +155,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.test-with-mysql.result == 'cancelled' || needs.test-with-mysql.result == 'failure' || - needs.test-with-mariadb.result == 'cancelled' || needs.test-with-mariadb.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/test-and-zip-default-themes.yml b/.github/workflows/test-and-zip-default-themes.yml index 1953c7f124..916b53b0d6 100644 --- a/.github/workflows/test-and-zip-default-themes.yml +++ b/.github/workflows/test-and-zip-default-themes.yml @@ -155,7 +155,7 @@ jobs: needs: [ bundle-theme, test-build-scripts ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.test-build-scripts.result == 'success' && needs.bundle-theme.result == 'success' && 'success' || ( needs.test-build-scripts.result == 'cancelled' || needs.bundle-theme.result == 'cancelled' ) && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -174,8 +174,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.test-build-scripts.result == 'cancelled' || needs.test-build-scripts.result == 'failure' || - needs.bundle-theme.result == 'cancelled' || needs.bundle-theme.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index 01db2eec5c..cd00e9b7f0 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -183,7 +183,7 @@ jobs: needs: [ test-coverage-report ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.test-coverage-report.result == 'success' && 'success' || needs.test-coverage-report.result == 'cancelled' && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -202,7 +202,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.test-coverage-report.result == 'cancelled' || needs.test-coverage-report.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/test-npm.yml b/.github/workflows/test-npm.yml index 7c6f018f15..d53c8ec825 100644 --- a/.github/workflows/test-npm.yml +++ b/.github/workflows/test-npm.yml @@ -184,7 +184,7 @@ jobs: needs: [ test-npm, test-npm-macos ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.test-npm.result == 'success' && needs.test-npm-macos.result == 'success' && 'success' || ( needs.test-npm.result == 'cancelled' || needs.test-npm-macos.result == 'cancelled' ) && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }} @@ -203,8 +203,8 @@ jobs: github.event_name != 'pull_request' && github.run_attempt < 2 && ( - needs.test-npm.result == 'cancelled' || needs.test-npm.result == 'failure' || - needs.test-npm-macos.result == 'cancelled' || needs.test-npm-macos.result == 'failure' + contains( needs.*.result, 'cancelled' ) || + contains( needs.*.result, 'failure' ) ) steps: diff --git a/.github/workflows/test-old-branches.yml b/.github/workflows/test-old-branches.yml index 03ccb4f974..9e37c8b5e6 100644 --- a/.github/workflows/test-old-branches.yml +++ b/.github/workflows/test-old-branches.yml @@ -106,7 +106,7 @@ jobs: needs: [ dispatch-workflows-for-old-branches ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: - calling_status: ${{ needs.dispatch-workflows-for-old-branches.result == 'success' && 'success' || needs.dispatch-workflows-for-old-branches.result == 'cancelled' && 'cancelled' || 'failure' }} + calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} secrets: SLACK_GHA_SUCCESS_WEBHOOK: ${{ secrets.SLACK_GHA_SUCCESS_WEBHOOK }} SLACK_GHA_CANCELLED_WEBHOOK: ${{ secrets.SLACK_GHA_CANCELLED_WEBHOOK }}