Skip to content

Commit

Permalink
[not verified] Merge remote-tracking branch 'origin/master' into add/…
Browse files Browse the repository at this point in the history
…e2e-scheduled-pre-release-gb-job
  • Loading branch information
brbrr committed Mar 18, 2021
2 parents 4efdd2e + 046bdfd commit c7b4d4c
Show file tree
Hide file tree
Showing 442 changed files with 11,110 additions and 3,644 deletions.
2 changes: 2 additions & 0 deletions .github/actions/repo-gardening/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Here is the current list of tasks handled by this action:
- Assign Issues: Adds assignee for issues which are being worked on, and adds the "In Progress" label.
- Add Milestone: Adds a valid milestone to all PRs that get merged and don't already include a milestone.
- Check Description: Checks the contents of a PR description, and ensure it matches our recommendations.
- Add Labels: Adds labels to PRs that touch specific features.
- WordPress.com Commit Reminder: Posts a comment on merged PRs to remind Automatticians to commit the matching WordPress.com change.

## Build your own

Expand Down
2 changes: 1 addition & 1 deletion .github/actions/repo-gardening/src/get-plugin-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function getPluginNames( octokit, owner, repo, number ) {
labels.map( label => {
const plugin = label.match( /^\[Plugin\]\s(?<pluginName>[^/]*)$/ );
if ( plugin && plugin.groups.pluginName ) {
plugins.push( plugin.groups.pluginName.toLowerCase() );
plugins.push( plugin.groups.pluginName.replace( /\s+/, '-' ).toLowerCase() );
}
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ async function addMilestone( payload, octokit ) {
return;
}

if ( plugins.length >= 2 ) {
debug(
`add-milestone: this PR touches multiple plugins, we cannot choose which milestone this should belong to. Aborting.`
);
return;
}

// Get next valid milestone (we can only add one).
const nextMilestone = await getNextValidMilestone( octokit, ownerLogin, repo, plugins[ 0 ] );

if ( ! nextMilestone ) {
throw new Error( 'Could not find a valid milestone' );
throw new Error( `Could not find a valid milestone for ${ plugins[ 0 ] }` );
}

debug( `add-milestone: Adding PR #${ prNumber } to milestone #${ nextMilestone.number }` );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ async function getMilestoneDates( plugin, nextMilestone ) {
codeFreezeDate = firstTuesdayOfMonth.subtract( 8, 'd' ).format( 'LL' );
}

const capitalizedName = plugin
.split( '-' )
// Capitalize first letter of each word.
.map( word => `${ word[ 0 ].toUpperCase() }${ word.slice( 1 ) }` )
// Spaces between words.
.join( ' ' );

return `
******
**${ plugin } plugin:**
**${ capitalizedName } plugin:**
- Next scheduled release: _${ releaseDate }_.
- Scheduled code freeze: _${ codeFreezeDate }_
`;
Expand All @@ -128,6 +135,8 @@ async function buildMilestoneInfo( octokit, owner, repo, number ) {
const plugins = await getPluginNames( octokit, owner, repo, number );
let pluginInfo;

debug( `check-description: This PR impacts the following plugins: ${ plugins.join( ', ' ) }` );

// Get next valid milestone for each plugin.
for await ( const plugin of plugins ) {
const nextMilestone = await getNextValidMilestone( octokit, owner, repo, plugin );
Expand Down Expand Up @@ -194,9 +203,10 @@ async function checkDescription( payload, octokit ) {
When contributing to Jetpack, we have [a few suggestions](https://github.com/Automattic/jetpack/blob/master/.github/PULL_REQUEST_TEMPLATE.md) that can help us test and review your patch:<br>`;

// No PR is too small to include a description of why you made a change
const hasLongDescription = body.length > 200;
comment += `
- ${
body < 10 ? `:red_circle:` : `:white_check_mark:`
! hasLongDescription ? `:red_circle:` : `:white_check_mark:`
} Include a description of your PR changes.<br>`;

// Check all commits in PR.
Expand All @@ -217,15 +227,15 @@ When contributing to Jetpack, we have [a few suggestions](https://github.com/Aut
}

// Check for testing instructions.
const hasTesting = body.includes( 'Testing instructions' );
comment += `
- ${
! body.includes( 'Testing instructions' ) ? `:red_circle:` : `:white_check_mark:`
} Add testing instructions.<br>`;
- ${ ! hasTesting ? `:red_circle:` : `:white_check_mark:` } Add testing instructions.<br>`;

// Check if the Privacy section is filled in.
const hasPrivacy = body.includes( 'data or activity we track or use' );
comment += `
- ${
! body.includes( 'data or activity we track or use' ) ? `:red_circle:` : `:white_check_mark:`
! hasPrivacy ? `:red_circle:` : `:white_check_mark:`
} Specify whether this PR includes any changes to data or privacy.<br>`;

debug( `check-description: privacy checked. our comment so far is ${ comment }` );
Expand All @@ -235,10 +245,57 @@ When contributing to Jetpack, we have [a few suggestions](https://github.com/Aut
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation :robot:
******`;

// If some of the tests are failing, display list of things that could be updated in the PR description to fix things.
const recommendations = `
${
! hasLongDescription
? `Please edit your PR description and explain what functional changes your PR includes, and why those changes are needed.`
: ''
}
${
! hasPrivacy
? `We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:
~~~
#### Does this pull request change what data or activity we track or use?
My PR adds *x* and *y*.
~~~`
: ''
}
${
! hasTesting
? `Please include detailed testing steps, explaining how to test your change, like so:
~~~
#### Testing instructions:
* Go to '..'
*
~~~`
: ''
}
`;

// If we have some recommendations, add them to our comment.
if (
// Remove line breaks from the string to facilitate checking if not empty.
recommendations.replace( /\r?\n|\r/g, '' ).length > 0
) {
comment += `${ recommendations }
******
`;
}

If you are an automattician, once your PR is ready for review add the "[Status] Needs Team review" label and ask someone from your team review the code.
// Display extra info for Automatticians (who can handle labels and who created the PR without a fork).
if ( head.repo.full_name === base.repo.full_name ) {
comment += `
Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.`;
}

// Gather info about the next release for that plugin.
const milestoneInfo = await buildMilestoneInfo( octokit, ownerLogin, repo, number );
Expand Down
21 changes: 15 additions & 6 deletions .github/files/build-all-projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ echo "::group::Changelogger setup"
(cd projects/packages/changelogger && composer install)
echo "::endgroup::"

echo "::group::Determining build order"
TMP="$(tools/get-build-order.php)"
SLUGS=()
mapfile -t SLUGS <<<"$TMP"
echo "::endgroup::"

EXIT=0

REPO="$(jq --arg path "$BUILD_BASE/*/*" -nc '{ type: "path", url: $path, options: { monorepo: true } }')"

touch "$BUILD_BASE/mirrors.txt"
for project in projects/packages/* projects/plugins/* projects/github-actions/*; do
PROJECT_DIR="${BASE}/${project}"
for SLUG in "${SLUGS[@]}"; do
PROJECT_DIR="${BASE}/projects/${SLUG}"
[[ -d "$PROJECT_DIR" ]] || continue # We are only interested in directories (i.e. projects)

printf "\n\n\e[7m Project: %s \e[0m\n" "$project"
printf "\n\n\e[7m Project: %s \e[0m\n" "$SLUG"

cd "${PROJECT_DIR}"

Expand Down Expand Up @@ -72,9 +78,7 @@ for project in projects/packages/* projects/plugins/* projects/github-actions/*;
OLDLOCK=
fi
fi
# Need to remove the "projects/" from the string since the CLI only looks for {type}/{project-name}.
SLUG="${project#projects/}"
if node "$BASE"/tools/cli/bin/jetpack build "${SLUG}" -v --production; then
if (cd $BASE && yarn jetpack build "${SLUG}" -v --production); then
FAIL=false
else
FAIL=true
Expand Down Expand Up @@ -128,6 +132,11 @@ for project in projects/packages/* projects/plugins/* projects/github-actions/*;
# Copy standard .github
cp -r "$BASE/.github/files/mirror-.github" "$BUILD_DIR/.github"

# Copy autotagger if enabled
if jq -e '.extra.autotagger // false' composer.json > /dev/null; then
cp -r "$BASE/.github/files/gh-autotagger/." "$BUILD_DIR/.github/."
fi

# Copy only wanted files, based on .gitignore and .gitattributes.
{
# Include unignored files by default.
Expand Down
23 changes: 23 additions & 0 deletions .github/files/gh-autotagger/workflows/autotagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Auto-tagger

on:
push:
branches: [ 'master' ]

jobs:
tag:
name: Tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Tag
run: |
VER=$(sed -nEe 's/^## \[?([^]]*)\]? - .*/\1/;T;p;q' CHANGELOG.md || true)
echo "Version from changelog is ${VER:-<unknown>}"
if [[ "$VER" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
git config --global user.name "matticbot"
git config --global user.email "matticbot@users.noreply.github.com"
git remote set-url origin "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}"
git tag "v$VER"
git push --tags
fi
88 changes: 13 additions & 75 deletions .github/files/list-changed-projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

// phpcs:disable WordPress.WP.AlternativeFunctions, WordPress.PHP.DiscouragedPHPFunctions, WordPress.Security.EscapeOutput.OutputNotEscaped

ob_start();
require_once __DIR__ . '/../../tools/find-project-deps.php';
ob_end_clean();

// Files that mean all tests should be run.
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$infrastructure_files = array(
Expand Down Expand Up @@ -185,90 +189,24 @@ function get_changed_projects() {
return array_keys( $projects );
}

/**
* Get the path to a file in a project.
*
* @param string $project The project slug to check.
* @param string $path Path components to check.
* @return string
*/
function project_path( $project, $path ) {
return 'monorepo' === $project ? $path : "projects/$project/$path";
}

/**
* Check whether any of a project's extra dependencies have changed.
*
* Dependencies declared in composer.json `.extra.dependencies`.
*
* @param string $project The project slug to check.
* @param array $changed Array mapping project slugs to "changed" flags.
* @return bool
*/
function check_extra_deps( $project, $changed ) {
$json = json_decode( file_get_contents( project_path( $project, 'composer.json' ) ), true );
if ( isset( $json['extra']['dependencies'] ) ) {
foreach ( $json['extra']['dependencies'] as $dep ) {
if ( ! empty( $changed[ $dep ] ) ) {
debug( 'Project %s depends on %s, marking it changed.', $project, $dep );
return true;
}
}
}
return false;
}

/**
* Check whether any of a project's composer dependencies have changed.
*
* @param string $project The project slug to check.
* @param array $changed Array mapping project slugs to "changed" flags.
* @return bool
*/
function check_composer_deps( $project, $changed ) {
static $package_map = null;

if ( null === $package_map ) {
$package_map = array();
foreach ( get_all_projects() as $p ) {
if ( substr( $p, 0, 9 ) === 'packages/' ) {
$json = json_decode( file_get_contents( project_path( $p, 'composer.json' ) ), true );
if ( isset( $json['name'] ) ) {
$package_map[ $json['name'] ] = $p;
}
}
}
}

$json = json_decode( file_get_contents( project_path( $project, 'composer.json' ) ), true );
$deps = array_merge(
isset( $json['require'] ) ? $json['require'] : array(),
isset( $json['require-dev'] ) ? $json['require-dev'] : array()
);
foreach ( $package_map as $package => $p ) {
if ( isset( $deps[ $package ] ) && ! empty( $changed[ $p ] ) ) {
debug( 'Project %s depends on composer package %s from %s, marking it changed.', $project, $package, $p );
return true;
}
}
return false;
}

// Get a list of projects indicating which are changed.
$projects = array_fill_keys( get_changed_projects(), true ) + array_fill_keys( get_all_projects(), false );

// Figure out if any projects depend on a changed project. Repeat to propagate until none are found.
$deps = get_dependencies();
do {
$any = false;
foreach ( $projects as $project => $changed ) {
if ( $changed ) {
if ( $changed || ! isset( $deps[ $project ] ) ) {
continue;
}
if ( check_extra_deps( $project, $projects ) ||
check_composer_deps( $project, $projects )
) {
$projects[ $project ] = true;
$any = true;
foreach ( $deps[ $project ] as $slug ) {
if ( ! empty( $projects[ $slug ] ) ) {
debug( 'Project %s depends on %s, marking it as changed.', $project, $slug );
$projects[ $project ] = true;
$any = true;
break;
}
}
}
} while ( $any );
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
name: Build all projects
runs-on: ubuntu-latest
timeout-minutes: 10 # 2021-01-18: Successful runs seem to take 5-7 minutes
timeout-minutes: 15 # 2021-03-16: Successful runs seem to take 9-10 minutes now.

# Push also covers pull requests for non-forked repos. So only run on PR for forked PRs.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ jobs:
jq --version
- run: yarn install
- run: node tools/cli/bin/jetpack install --all -v # Ensure there are no unresolved import errors.
- run: yarn jetpack install --all -v # Ensure there are no unresolved import errors.
- run: yarn lint-required

### Runs eslint-changed on JS files listed in eslint-excludelist.json.
Expand Down Expand Up @@ -510,7 +510,7 @@ jobs:
jq --version
- run: yarn install
- run: node tools/cli/bin/jetpack install --all -v # Ensure there are no unresolved import errors.
- run: yarn jetpack install --all -v # Ensure there are no unresolved import errors.
- name: Run eslint-changed
env:
FILES: ${{ needs.changed_files.outputs.js_excluded_files }}
Expand Down Expand Up @@ -595,7 +595,7 @@ jobs:
- run: composer install
- run: yarn install
- run: node tools/cli/bin/jetpack install --all -v # Ensure there are no unresolved import errors.
- run: yarn jetpack install --all -v # Ensure there are no unresolved import errors.

- name: Cleanup excludelists
run: tools/cleanup-excludelists.sh
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
WP_BRANCH: ${{ matrix.wp }}
PHP_VERSION: ${{ matrix.php }}
NODE_VERSION: ${{ matrix.node }}
MONOREPO_BASE: ${{ github.workspace }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -142,6 +143,12 @@ jobs:
which jq
jq --version
- name: Monorepo install
run: |
echo "::group::Yarn"
yarn install
echo "::endgroup::"
- name: Run project tests
env:
CHANGED: ${{ steps.changed.outputs.projects }}
Expand Down
Loading

0 comments on commit c7b4d4c

Please sign in to comment.