Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into add/react-data-sync-…
Browse files Browse the repository at this point in the history
…client/react-query-devtools
  • Loading branch information
LiamSarsfield committed Jan 29, 2025
2 parents fbc9d2d + 76d6bff commit 203df62
Show file tree
Hide file tree
Showing 117 changed files with 2,119 additions and 1,212 deletions.
85 changes: 85 additions & 0 deletions .github/files/coverage-munger/upload-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
## Environment used by this script:
#
# Required:
# - API_TOKEN_GITHUB: GitHub API token.
# - GITHUB_API_URL: GitHub API URL.
# - GITHUB_TOKEN: GitHub API token.
# - GITHUB_REPOSITORY: GitHub repo.
# - GITHUB_SHA: Commit SHA.
# - PR_HEAD: SHA for the PR head commit (versus GITHUB_SHA which is a merge commit)
# - PR_ID: PR number or "trunk".
# - SECRET: Shared secret.
# - STATUS: Status of the coverage run.

set -eo pipefail

Expand Down Expand Up @@ -95,3 +101,82 @@ done
do_req "op=finish&token=$TOKEN"
TOKEN=
echo '::endgroup::'

if [[ "$PR_ID" != "trunk" ]]; then
echo "::group::Setting GitHub status"
if jq -e '.covinfo' <<<"$JSON" &>/dev/null; then
JSON=$( jq '.covinfo' <<<"$JSON" )
if [[ "$STATUS" != 'success' ]]; then
JSON=$( jq '.state |= "pending" | .description |= "Waiting for tests to pass" | .msg |= "Cannot generate coverage summary while tests are failing. :zipper_mouth_face:\n\nPlease fix the tests, or re-run the Code coverage job if it was something being flaky."' <<<"$JSON" )
fi
else
JSON='{"state":"error","description":"No covinfo received from server","msg":"","footer":""}'
fi
jq . <<<"$JSON"
curl -v -L --fail \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/$( jq --arg V "$PR_HEAD" -nr '$V | @uri' )" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c --arg PR "$PR_ID" '{
context: "Code coverage requirement",
state: .state,
target_url: "https://jetpackcodecoverage.atomicsites.blog/prs/\( $PR | @uri )/",
description: .description,
}' <<<"$JSON" )"
echo "::endgroup::"

# Find the last comment starting with "### Code Coverage Summary"
echo "::group::Looking for existing comment"
PAGE=1
while true; do
J=$( curl -v -L fail \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${ID}/comments?per_page=100&page=$PAGE" \
--header "authorization: Bearer $API_TOKEN_GITHUB"
)
CID=$( jq -r --arg CID "$CID" '[ { id: $CID }, ( .[] | select( .user.login == "github-actions[bot]" ) | select( .body | test( "^### Code Coverage Summary" ) ) ) ] | last | .id' <<<"$J" )
if jq -e 'length < 100' <<<"$J" &>/dev/null; then
break
fi
PAGE=$(( PAGE + 1 ))
done
echo "::endgroup::"
if [[ -n "$CID" ]]; then
echo "Existing comment ID=$CID"
else
echo "No existing comment found"
fi

if jq -e '.msg != ""' <<<"$JSON" &>/dev/null; then
if [[ -n "$CID" ]]; then
echo "::group::Updating comment"
curl -v -L --fail \
-X PATCH \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/comments/${CID}" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c '{
body: "### Code Coverage Summary\n\n\( .msg )\n\n\( .footer )",
}' <<<"$JSON" )"
echo "::endgroup::"
else
echo "::group::Creating comment"
curl -v -L --fail \
-X POST \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${ID}/comments" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c '{
body: "### Code Coverage Summary\n\n\( .msg )\n\n\( .footer )",
}' <<<"$JSON" )"
echo "::endgroup::"
fi
elif [[ -n "$CID" ]]; then
# No message, delete existing comment.
echo "::group::Deleting comment"
curl -v -L --fail \
-X DELETE \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/comments/${CID}" \
--header "authorization: Bearer $API_TOKEN_GITHUB"
echo "::endgroup::"
fi
fi
13 changes: 12 additions & 1 deletion .github/files/renovate-post-upgrade-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ if [[ ! -e /tmp/dummy-log/xdebug_remote.log ]]; then
fi

docker pull --quiet ghcr.io/automattic/jetpack-wordpress-dev:latest
docker run --rm --workdir "$PWD" --user $EUID --volume /tmp/:/tmp/ --volume /tmp/dummy-log:/var/log/php ghcr.io/automattic/jetpack-wordpress-dev:latest /tmp/monorepo/.github/files/renovate-post-upgrade.sh "$@"

# Work around https://github.com/fabiospampinato/atomically/issues/13 by extracting /etc/passwd from the container and appending the entry for $EUID to it.
TMPFILE=$( mktemp )
function cleanup {
rm -f "$TMPFILE"
}
trap cleanup exit
chmod 0644 "$TMPFILE"
docker run --rm ghcr.io/automattic/jetpack-wordpress-dev:latest cat /etc/passwd > "$TMPFILE"
getent passwd $EUID >> "$TMPFILE"

docker run --rm --workdir "$PWD" --user $EUID --volume "$TMPFILE":/etc/passwd --volume /tmp/:/tmp/ --volume /tmp/dummy-log:/var/log/php ghcr.io/automattic/jetpack-wordpress-dev:latest /tmp/monorepo/.github/files/renovate-post-upgrade.sh "$@"
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
# Note matrix-job outputs are kind of weird. Last-to-run job that sets a non-empty value wins.
outputs:
did-coverage: ${{ ( steps.run-tests.conclusion != 'cancelled' && steps.process-coverage.conclusion == 'success' && steps.upload-artifacts.conclusion == 'success' ) && 'true' || '' }}
coverage-status: ${{ matrix.script == 'test-coverage' && steps.run-tests.conclusion || '' }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -305,6 +306,9 @@ jobs:
env:
PR_ID: ${{ github.event_name != 'pull_request' && 'trunk' || github.event.pull_request.number }}
SECRET: ${{ secrets.CODECOV_SECRET }}
STATUS: ${{ needs.run-tests.outputs.coverage-status }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
run: .github/files/coverage-munger/upload-coverage.sh

storybook-test:
Expand Down
12 changes: 11 additions & 1 deletion .phan/stubs/wpcom-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* `bin/teamcity-builds/jetpack-stubs/stub-defs.php` and regenerate the stubs
* by triggering the Jetpack Staging → Update WPCOM Stubs job in TeamCity.
*
* Stubs automatically generated from WordPress.com commit 25fe8874f126229252809211e216317f571c666f.
* Stubs automatically generated from WordPress.com commit 58daa278d1c6807cf18400dee1d9f45815e24fae.
*/

namespace {
Expand Down Expand Up @@ -1524,6 +1524,16 @@ function get_blog_subscriptions_aggregate_count(int $blog_id = null, $post_term_
{
}
}
namespace WPCOM\Experiments\Internal {
/**
* @param string $name
* @return \WPCOM\Experiments\Models\Experiment|null
* @throws File_Cache_Failure
*/
function get_cached_experiment_by_name(string $name): ?\WPCOM\Experiments\Models\Experiment
{
}
}
namespace WPCOM\Jetpack_AI {
class Feature_Control
{
Expand Down
6 changes: 3 additions & 3 deletions docs/unison-wordpress-com.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Jetpack currently uses a `sun`/`moon` strategy where the current production files are in one folder and the "staging/test" version are in the other folder.

If you don't want to keep track of which folder is in use during development, you can update your Unison preference file to point to `wp-content/mu-plugins/jetpack-plugin/production` on your sandbox. The `production` directory will always be pointed at the current production files.
If you don't want to keep track of which folder is in use during development, you can update your Unison preference file to point to `wp-content/mu-plugins/jetpack-plugin/dev` on your sandbox. If this directory exists, it will be used instead of `sun` or `moon`.

In the event that you want to sync changes to both `sun` and `moon`, you may want to create _two_ Unison preference files, one file which syncs to the `sun` location and one file which syncs to the `moon` location. Then you would run two separate instances of `unison watch` (as described above).

For even more advanced usage, you can use the following command to launch tmux with each unison command running in a separate window.
Expand All @@ -12,4 +12,4 @@
tmux new-session -d 'unison -ui text -repeat watch jetpack-plugin-moon' \; split-window -d 'unison -ui text -repeat watch jetpack-plugin-sun' \; attach
```

Note: You will need to adjust the above command depending on the name(s) of your Unison configuration files.
Note: You will need to adjust the above command depending on the name(s) of your Unison configuration files.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Move initial state from Social plugin to publicize package
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Replace getSite selector with getEntityRecord to avoid redundant API calls
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const SocialAdminPage = () => {

return {
isModuleEnabled: settings.publicize_active,
showPricingPage: store.shouldShowPricingPage(),
showPricingPage: store.getSocialSettings().showPricingPage,
isUpdatingJetpackSettings: store.isSavingSocialPluginSettings(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe( 'load the app', () => {
test( 'container renders', () => {
let storeSelect;
renderHook( () => useSelect( select => ( storeSelect = select( SOCIAL_STORE_ID ) ) ) );
jest.spyOn( storeSelect, 'getSocialPluginSettings' ).mockReset().mockReturnValue( {
show_pricing_page: true,
jest.spyOn( storeSelect, 'getSocialSettings' ).mockReset().mockReturnValue( {
showPricingPage: true,
} );
render( <SocialAdminPage /> );
expect( screen.getByText( `Jetpack Social ${ version }` ) ).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SocialImageGeneratorToggle: React.FC< SocialImageGeneratorToggleProps > =
disabled,
} ) => {
const { isEnabled, isUpdating, defaultTemplate } = useSelect( select => {
const config = select( socialStore ).getSocialImageGeneratorConfig();
const config = select( socialStore ).getSocialSettings().socialImageGenerator;

return {
isEnabled: config.enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const SocialNotesToggle: React.FC< SocialNotesToggleProps > = ( { disabled } ) =
const store = select( socialStore );

return {
isEnabled: store.isSocialNotesEnabled(),
notesConfig: store.getSocialNotesConfig(),
isEnabled: store.getSocialSettings().socialNotes.enabled,
notesConfig: store.getSocialSettings().socialNotes.config,
isUpdating: store.isSavingSiteSettings(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type UtmToggleProps = {
const UtmToggle: React.FC< UtmToggleProps > = ( { disabled } ) => {
const { isEnabled, isUpdating } = useSelect( select => {
return {
isEnabled: select( socialStore ).getUtmSettings().enabled,
isEnabled: select( socialStore ).getSocialSettings().utmSettings.enabled,
isUpdating: select( socialStore ).isSavingSiteSettings(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TemplatePickerButton: React.FC = () => {
const { isEnabled, isUpdating, defaultTemplate } = useSelect( select => {
const store = select( socialStore );

const config = store.getSocialImageGeneratorConfig();
const config = store.getSocialSettings().socialImageGenerator;
return {
isEnabled: config.enabled,
defaultTemplate: config.template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SocialImageGeneratorToggle: React.FC< SocialImageGeneratorToggleProps > =
const store = select( socialStore );

return {
isEnabled: store.getSocialImageGeneratorConfig().enabled,
isEnabled: store.getSocialSettings().socialImageGenerator.enabled,
isUpdating: store.isSavingSiteSettings(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ToggleProps = {
const UtmToggle: React.FC< ToggleProps > = ( { toggleClass, children } ) => {
const { isEnabled, isUpdating } = useSelect( select => {
return {
isEnabled: select( socialStore ).getUtmSettings().enabled,
isEnabled: select( socialStore ).getSocialSettings().utmSettings.enabled,
isUpdating: select( socialStore ).isSavingSiteSettings(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ declare module '@wordpress/core-data' {
export interface PerPackageEntityRecords {
'jetpack/v4': SocialPluginSettings;
}
export interface PerPackageEntityRecords {
root: SocialSettingsFields;
}

export namespace BaseEntityRecords {
export interface Settings extends SocialSettingsFields {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import { store as coreStore } from '@wordpress/core-data';
import { createRegistrySelector } from '@wordpress/data';
import * as connectionDataSelectors from './connection-data';
import * as pricingPageSelectors from './pricing-page';
import * as shareStatusSelectors from './share-status';
import * as sigSelectors from './social-image-generator';
import * as socialNoteSelectors from './social-notes';
import * as socialPluginSelectors from './social-plugin-settings';
import * as utmSelectors from './utm-settings';

/**
* Returns whether the site settings are being saved.
*/
export const isSavingSiteSettings = createRegistrySelector( select => () => {
return select( coreStore ).isSavingEntityRecord( 'root', 'site', undefined );
} );
import * as socialSettingsSelectors from './social-settings';

const selectors = {
...connectionDataSelectors,
...shareStatusSelectors,
isSavingSiteSettings,
...sigSelectors,
...utmSelectors,
...socialNoteSelectors,
...pricingPageSelectors,
...socialPluginSelectors,
...socialSettingsSelectors,
};

export default selectors;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { PostShareStatus, SocialStoreState } from '../types';

/**
* Get the post share status.
*
* @param {SocialStoreState} state - State object.
* @param {number} postId - The post ID.
*
* @return {PostShareStatus} - The post share status.
*/
export const getPostShareStatus = createRegistrySelector(
select =>
Expand All @@ -18,7 +13,7 @@ export const getPostShareStatus = createRegistrySelector(

return state.shareStatus?.[ id ] ?? { shares: [] };
}
) as ( state: SocialStoreState, postId?: number ) => PostShareStatus;
);

/**
* Whether the share status modal is open.
Expand Down

This file was deleted.

Loading

0 comments on commit 203df62

Please sign in to comment.