Added functionality for release testing workflow
This commit is contained in:
parent
63ff7c800e
commit
cd012edceb
|
@ -6,6 +6,7 @@
|
|||
- Added plugin zip utility functions:
|
||||
- `checkNestedZip( zipFilePath, savePath )` checks a plugin zip file for any nested zip files. If one is found, it is extracted. Returns the path where the zip file is located.
|
||||
- `downloadZip( fileUrl, downloadPath )` downloads a plugin zip file from a remote location to the provided path.
|
||||
- Added `getLatestReleaseZipUrl( owner, repository, getPrerelease, perPage )` util function to get the latest release zip from a GitHub repository
|
||||
|
||||
# 0.2.2
|
||||
|
||||
|
|
|
@ -196,6 +196,14 @@ The above method also makes use of the following utility methods which can also
|
|||
- `checkNestedZip( zipFilePath, savePath )` used to check a plugin zip file for any nested zip files. If one is found, it is extracted. Returns the path where the zip file is located.
|
||||
- `downloadZip( fileUrl, downloadPath )` can be used to directly download a plugin zip file from a remote location to the provided path.
|
||||
|
||||
### Get the latest released zip URL
|
||||
|
||||
If you would like to get the latest release zip URL, which can be used in the methods mentioned above, you can use the following helper function to do so:
|
||||
|
||||
`getLatestReleaseZipUrl( owner, repository, getPrerelease, perPage )`
|
||||
|
||||
This will return a string with the latest release URL. Optionally, you can use the `getPrerelease` boolean flag, which defaults to false, on whether or not to get a prerelease instead. The `perPage` flag can be used to return more results when getting the list of releases. The default value is 3.
|
||||
|
||||
## Additional information
|
||||
|
||||
Refer to [`tests/e2e/core-tests`](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e/core-tests) for some test examples, and [`tests/e2e`](https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e) for general information on e2e tests.
|
||||
|
|
|
@ -29,6 +29,52 @@ const getRemotePluginZip = async ( fileUrl ) => {
|
|||
return filePath;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the latest release zip for a plugin from a GiHub repository.
|
||||
*
|
||||
* @param {string} owner The owner of the plugin repository.
|
||||
* @param {string} repository The repository name.
|
||||
* @param {boolean} getPrerelease Flag on whether to get a prelease or not.
|
||||
* @param {number} perPage Limit of entries returned from the latest releases list, defaults to 3.
|
||||
* @returns {Promise<string>}} Returns the URL for the release zip file.
|
||||
*/
|
||||
const getLatestReleaseZipUrl = async ( owner, repository, getPrerelease = false, perPage = 3 ) => {
|
||||
let requesturl;
|
||||
|
||||
if ( getPrerelease ) {
|
||||
requesturl = `https://api.github.com/repos/${owner}/${repository}/releases?per_page=${perPage}`;
|
||||
} else {
|
||||
requesturl = `https://api.github.com/repos/${owner}/${repository}/releases/latest`;
|
||||
}
|
||||
|
||||
const options = {
|
||||
url: requesturl,
|
||||
method: 'GET',
|
||||
json: true,
|
||||
headers: {'user-agent': 'node.js'}
|
||||
};
|
||||
|
||||
// Wrap in a promise to make the request async
|
||||
return new Promise( function( resolve, reject ) {
|
||||
request.get(options, function( err, resp, body ) {
|
||||
if ( err ) {
|
||||
reject( err );
|
||||
} else {
|
||||
if ( getPrerelease ) {
|
||||
// Loop until we find the first pre-release, then return it.
|
||||
body.forEach(release => {
|
||||
if ( release.prerelease ) {
|
||||
resolve( release.zipball_url );
|
||||
}
|
||||
});
|
||||
} else {
|
||||
resolve( body.zipball_url );
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the zip file for any nested zips. If one is found, extract it.
|
||||
*
|
||||
|
@ -80,6 +126,7 @@ const downloadZip = async ( fileUrl, downloadPath ) => {
|
|||
|
||||
module.exports = {
|
||||
getRemotePluginZip,
|
||||
getLatestReleaseZipUrl,
|
||||
checkNestedZip,
|
||||
downloadZip,
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const getAppRoot = require( './app-root' );
|
||||
const { getAppName, getAppBase } = require( './app-name' );
|
||||
const { getTestConfig, getAdminConfig } = require( './test-config' );
|
||||
const { getRemotePluginZip } = require('./get-plugin-zip');
|
||||
const { getRemotePluginZip, getLatestReleaseZipUrl } = require('./get-plugin-zip');
|
||||
const takeScreenshotFor = require( './take-screenshot' );
|
||||
const updateReadyPageStatus = require('./update-ready-page');
|
||||
const consoleUtils = require( './filter-console' );
|
||||
|
@ -13,6 +13,7 @@ module.exports = {
|
|||
getTestConfig,
|
||||
getAdminConfig,
|
||||
getRemotePluginZip,
|
||||
getLatestReleaseZipUrl,
|
||||
takeScreenshotFor,
|
||||
updateReadyPageStatus,
|
||||
...consoleUtils,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
const { merchant, utils } = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
const { getRemotePluginZip } = require( '@woocommerce/e2e-environment' );
|
||||
const { getRemotePluginZip, getLatestReleaseZipUrl } = require( '@woocommerce/e2e-environment' );
|
||||
|
||||
/**
|
||||
* External dependencies
|
||||
|
@ -13,16 +13,23 @@ const {
|
|||
beforeAll,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
const { UPDATE_WC } = process.env;
|
||||
const { UPDATE_WC, TEST_RELEASE } = process.env;
|
||||
|
||||
const nightlyZip = 'https://github.com/woocommerce/woocommerce/releases/download/nightly/woocommerce-trunk-nightly.zip';
|
||||
let zipUrl;
|
||||
const pluginName = 'WooCommerce';
|
||||
|
||||
let pluginPath;
|
||||
|
||||
utils.describeIf( UPDATE_WC )( 'WooCommerce plugin can be uploaded and activated', () => {
|
||||
beforeAll( async () => {
|
||||
pluginPath = await getRemotePluginZip( nightlyZip );
|
||||
|
||||
if ( TEST_RELEASE ) {
|
||||
zipUrl = await getLatestReleaseZipUrl('woocommerce', 'woocommerce');
|
||||
} else {
|
||||
zipUrl = 'https://github.com/woocommerce/woocommerce/releases/download/nightly/woocommerce-trunk-nightly.zip';
|
||||
}
|
||||
|
||||
pluginPath = await getRemotePluginZip( zipUrl );
|
||||
await merchant.login();
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue