Allow running of "Smoke test release" on draft releases (#36997)
* Conditionally use authorization token when getting WC Zip download URL. * Exponse error message * Handle undefined authorization token more gracefully * Specify GH token in workflow * Add changelog * Use E2E_GH_TOKEN instead of default github.token * Provide GitHub token to other jobs * Fix getting of tag name from triggered event * Use "inputs" context instead * Add release version to workflow name * Correct concurrency group * Fix workflow name * Add --archive option * Fix output setting * Fix script for verifying asset * Remove unnecessary 'uses' line * Remove node 12 deprecation messages * Re-add "published" release type
This commit is contained in:
parent
dbc3cde987
commit
b60cc128fd
|
@ -1,14 +1,14 @@
|
||||||
name: Smoke test release
|
name: Smoke test release
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [released, prereleased, published]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
tag:
|
tag:
|
||||||
description: 'WooCommerce Release Tag'
|
description: 'WooCommerce Release Tag'
|
||||||
required: true
|
required: true
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.event.release.tag_name || inputs.tag }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
permissions: {}
|
permissions: {}
|
||||||
env:
|
env:
|
||||||
|
@ -23,31 +23,31 @@ jobs:
|
||||||
contents: read
|
contents: read
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
outputs:
|
outputs:
|
||||||
tag: ${{ steps.tag.outputs.result }}
|
tag: ${{ steps.get-tag.outputs.tag }}
|
||||||
created: ${{ steps.created-at.outputs.created }}
|
created: ${{ steps.created-at.outputs.created }}
|
||||||
steps:
|
steps:
|
||||||
- name: Validate tag
|
- name: Validate tag
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' }}
|
if: ${{ github.event_name == 'workflow_dispatch' }}
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
run: gh release view "${{ github.event.inputs.tag }}" --repo=woocommerce/woocommerce
|
run: gh release view "${{ inputs.tag }}" --repo=woocommerce/woocommerce
|
||||||
|
|
||||||
- name: Get tag
|
- name: Get tag from triggered event
|
||||||
uses: actions/github-script@v6
|
id: get-tag
|
||||||
id: tag
|
env:
|
||||||
with:
|
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.tag }}
|
||||||
result-encoding: string
|
run: |
|
||||||
script: |
|
echo "Triggered event: ${{ github.event_name }}"
|
||||||
console.log( "${{ github.event_name }}" );
|
echo "Tag from event: $RELEASE_TAG"
|
||||||
return "${{ github.event.release.tag_name }}" || "${{ github.event.inputs.tag }}"
|
echo "tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Verify woocommerce.zip asset
|
- name: Verify woocommerce.zip asset
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
RELEASE_TAG: ${{ steps.tag.outputs.result }}
|
RELEASE_TAG: ${{ steps.get-tag.outputs.tag }}
|
||||||
run: |
|
run: |
|
||||||
gh release download $RELEASE_TAG --repo woocommerce/woocommerce
|
ASSET_NAMES=$(gh release view $RELEASE_TAG --repo woocommerce/woocommerce --json assets --jq ".assets[].name")
|
||||||
if [[ -f "woocommerce.zip" ]]
|
if [[ $ASSET_NAMES == *"woocommerce.zip"* ]]
|
||||||
then
|
then
|
||||||
echo "$RELEASE_TAG has a valid woocommerce.zip asset."
|
echo "$RELEASE_TAG has a valid woocommerce.zip asset."
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -59,8 +59,8 @@ jobs:
|
||||||
- name: Get 'created-at' of WooCommerce zip
|
- name: Get 'created-at' of WooCommerce zip
|
||||||
id: created-at
|
id: created-at
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
run: echo "created=$(gh release view ${{ steps.tag.outputs.result }} --json assets --jq .assets[0].createdAt --repo woocommerce/woocommerce)" >> $GITHUB_OUTPUT
|
run: echo "created=$(gh release view ${{ steps.get-tag.outputs.tag }} --json assets --jq .assets[0].createdAt --repo woocommerce/woocommerce)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
e2e-update-wc:
|
e2e-update-wc:
|
||||||
name: Test WooCommerce update
|
name: Test WooCommerce update
|
||||||
|
@ -93,6 +93,7 @@ jobs:
|
||||||
CUSTOMER_PASSWORD: ${{ secrets.RELEASE_TEST_CUSTOMER_PASSWORD }}
|
CUSTOMER_PASSWORD: ${{ secrets.RELEASE_TEST_CUSTOMER_PASSWORD }}
|
||||||
CUSTOMER_USER: ${{ secrets.RELEASE_TEST_CUSTOMER_USER }}
|
CUSTOMER_USER: ${{ secrets.RELEASE_TEST_CUSTOMER_USER }}
|
||||||
DEFAULT_TIMEOUT_OVERRIDE: 120000
|
DEFAULT_TIMEOUT_OVERRIDE: 120000
|
||||||
|
GITHUB_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
UPDATE_WC: ${{ needs.get-tag.outputs.tag }}
|
UPDATE_WC: ${{ needs.get-tag.outputs.tag }}
|
||||||
run: |
|
run: |
|
||||||
pnpm exec playwright test \
|
pnpm exec playwright test \
|
||||||
|
@ -106,7 +107,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1-node16
|
||||||
with:
|
with:
|
||||||
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
||||||
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
||||||
|
@ -183,7 +184,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1-node16
|
||||||
with:
|
with:
|
||||||
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
||||||
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
||||||
|
@ -284,7 +285,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1-node16
|
||||||
with:
|
with:
|
||||||
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
||||||
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
||||||
|
@ -393,7 +394,7 @@ jobs:
|
||||||
|
|
||||||
- name: Download release zip
|
- name: Download release zip
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
run: gh release download ${{ needs.get-wp-versions.outputs.tag }} --dir tmp
|
run: gh release download ${{ needs.get-wp-versions.outputs.tag }} --dir tmp
|
||||||
|
|
||||||
- name: Replace `plugins/woocommerce` with unzipped woocommerce release build
|
- name: Replace `plugins/woocommerce` with unzipped woocommerce release build
|
||||||
|
@ -427,7 +428,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1-node16
|
||||||
with:
|
with:
|
||||||
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
||||||
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
||||||
|
@ -567,7 +568,7 @@ jobs:
|
||||||
|
|
||||||
- name: Download release zip
|
- name: Download release zip
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ secrets.E2E_GH_TOKEN }}
|
||||||
run: gh release download ${{ needs.get-tag.outputs.tag }} --dir tmp
|
run: gh release download ${{ needs.get-tag.outputs.tag }} --dir tmp
|
||||||
|
|
||||||
- name: Replace `plugins/woocommerce` with unzipped woocommerce release build
|
- name: Replace `plugins/woocommerce` with unzipped woocommerce release build
|
||||||
|
@ -587,7 +588,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Configure AWS credentials
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
uses: aws-actions/configure-aws-credentials@v1
|
uses: aws-actions/configure-aws-credentials@v1-node16
|
||||||
with:
|
with:
|
||||||
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
aws-region: ${{ secrets.REPORTS_AWS_REGION }}
|
||||||
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
aws-access-key-id: ${{ secrets.REPORTS_AWS_ACCESS_KEY_ID }}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
Support E2E testing of draft releases.
|
|
@ -1,6 +1,6 @@
|
||||||
const axios = require( 'axios' ).default;
|
const axios = require( 'axios' ).default;
|
||||||
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
|
const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
|
||||||
const { ADMINSTATE, UPDATE_WC } = process.env;
|
const { ADMINSTATE, GITHUB_TOKEN, UPDATE_WC } = process.env;
|
||||||
const { downloadZip, deleteZip } = require( '../../utils/plugin-utils' );
|
const { downloadZip, deleteZip } = require( '../../utils/plugin-utils' );
|
||||||
const { test, expect } = require( '@playwright/test' );
|
const { test, expect } = require( '@playwright/test' );
|
||||||
|
|
||||||
|
@ -20,34 +20,67 @@ const skipTestIfUndefined = () => {
|
||||||
}, skipMessage );
|
}, skipMessage );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get download URL of a WooCommerce ZIP asset by sending a `GET` request to `List releases` GitHub API endpoint in the WooCommerce repository.
|
||||||
|
*
|
||||||
|
* If `GITHUB_TOKEN` is defined, use it as `Authorization` header.
|
||||||
|
*
|
||||||
|
* @returns Download URL of the WooCommerce ZIP. This URL depends on whether `GITHUB_TOKEN` was specified or not.
|
||||||
|
*
|
||||||
|
* If `GITHUB_TOKEN` was defined, this function assumes that you're trying to access all releases, including drafts (as draft releases don't show up in the response of an unauthenticated GET `List releases` request ).
|
||||||
|
* In this case, the returned value will be the `asset.url`.
|
||||||
|
*
|
||||||
|
* Otherwise, the returned value will be the `asset.browser_download_url`.
|
||||||
|
*
|
||||||
|
* @throws Error if:
|
||||||
|
* - 'List releases' request was unsuccessful, or
|
||||||
|
* - no release with the given tag was found, or
|
||||||
|
* - when a WooCommerce ZIP asset was not found.
|
||||||
|
*
|
||||||
|
*/
|
||||||
const getWCDownloadURL = async () => {
|
const getWCDownloadURL = async () => {
|
||||||
let woocommerceZipAsset;
|
const requestConfig = {
|
||||||
|
method: 'get',
|
||||||
|
url: 'https://api.github.com/repos/woocommerce/woocommerce/releases',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/vnd.github+json',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const response = await axios
|
if ( GITHUB_TOKEN ) {
|
||||||
.get(
|
requestConfig.headers.Authorization = `Bearer ${ GITHUB_TOKEN }`;
|
||||||
`https://api.github.com/repos/woocommerce/woocommerce/releases/tags/${ UPDATE_WC }`
|
|
||||||
)
|
|
||||||
.catch( ( error ) => {
|
|
||||||
console.log( error.toJSON() );
|
|
||||||
return error.response;
|
|
||||||
} );
|
|
||||||
|
|
||||||
if (
|
|
||||||
response.status === 200 &&
|
|
||||||
response.data.assets &&
|
|
||||||
response.data.assets.length > 0 &&
|
|
||||||
( woocommerceZipAsset = response.data.assets.find(
|
|
||||||
( { browser_download_url } ) =>
|
|
||||||
browser_download_url.match(
|
|
||||||
/woocommerce(-trunk-nightly)?\.zip$/
|
|
||||||
)
|
|
||||||
) )
|
|
||||||
) {
|
|
||||||
return woocommerceZipAsset.browser_download_url;
|
|
||||||
} else {
|
|
||||||
const error = `You're attempting to get the download URL of a WooCommerce release zip with tag "${ UPDATE_WC }". But "${ UPDATE_WC }" is an invalid WooCommerce release tag, or a tag without a WooCommerce release zip asset like "7.2.0-rc.2".`;
|
|
||||||
throw new Error( error );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const response = await axios( requestConfig ).catch( ( error ) => {
|
||||||
|
if ( error.response ) {
|
||||||
|
console.log( error.response.data );
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error( error.message );
|
||||||
|
} );
|
||||||
|
|
||||||
|
const releaseWithTagName = response.data.find(
|
||||||
|
( { tag_name } ) => tag_name === UPDATE_WC
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( ! releaseWithTagName ) {
|
||||||
|
throw new Error(
|
||||||
|
`No release with tag_name="${ UPDATE_WC }" found. If "${ UPDATE_WC }" is a draft release, make sure to specify a GITHUB_TOKEN environment variable.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wcZipAsset = releaseWithTagName.assets.find( ( { name } ) =>
|
||||||
|
name.match( /^woocommerce(-trunk-nightly)?\.zip$/ )
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( wcZipAsset ) {
|
||||||
|
return GITHUB_TOKEN ? wcZipAsset.url : wcZipAsset.browser_download_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`WooCommerce release with tag "${ UPDATE_WC }" found, but does not have a WooCommerce ZIP asset.`
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
skipTestIfUndefined();
|
skipTestIfUndefined();
|
||||||
|
@ -58,7 +91,13 @@ test.describe.serial( 'WooCommerce update', () => {
|
||||||
test.beforeAll( async () => {
|
test.beforeAll( async () => {
|
||||||
await test.step( 'Download WooCommerce zip from GitHub', async () => {
|
await test.step( 'Download WooCommerce zip from GitHub', async () => {
|
||||||
const url = await getWCDownloadURL();
|
const url = await getWCDownloadURL();
|
||||||
woocommerceZipPath = await downloadZip( { url } );
|
const params = { url };
|
||||||
|
|
||||||
|
if ( GITHUB_TOKEN ) {
|
||||||
|
params.authorizationToken = GITHUB_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
woocommerceZipPath = await downloadZip( params );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,9 @@ export const downloadZip = async ( {
|
||||||
};
|
};
|
||||||
|
|
||||||
response = await axios( options ).catch( ( error ) => {
|
response = await axios( options ).catch( ( error ) => {
|
||||||
|
if ( error.response ) {
|
||||||
|
console.error( error.response.data );
|
||||||
|
}
|
||||||
throw new Error( error.message );
|
throw new Error( error.message );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue