123 lines
3.7 KiB
YAML
123 lines
3.7 KiB
YAML
name: Build zip for PR
|
|
on:
|
|
pull_request
|
|
jobs:
|
|
build:
|
|
name: Build zip for PR
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Build
|
|
id: build
|
|
uses: woocommerce/action-build@v2
|
|
|
|
- name: Upload PR zip
|
|
uses: actions/upload-artifact@v2
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
name: woocommerce
|
|
path: ${{ steps.build.outputs.zip_path }}
|
|
retention-days: 7
|
|
|
|
- name: Add comment
|
|
uses: actions/github-script@v3
|
|
if: github.repository_owner == 'woocommerce'
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
github.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: ':package: Artifacts ready for [download](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})!'
|
|
})
|
|
|
|
e2e-tests-cache:
|
|
name: Set e2e caches for running tests
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code.
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Load Node.js.
|
|
uses: actions/setup-node@v2
|
|
with:
|
|
node-version: '12'
|
|
|
|
# From https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#using-the-cache-action
|
|
- name: Cache node modules
|
|
uses: actions/cache@v2
|
|
id: cache_node_modules
|
|
env:
|
|
cache-name: cache-node-modules
|
|
with:
|
|
path: ./node_modules
|
|
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
|
|
|
- name: Run npm install, and cache if they aren't.
|
|
run: npm install
|
|
|
|
e2e-tests-run:
|
|
name: Runs E2E tests.
|
|
runs-on: ubuntu-latest
|
|
needs: [ build, e2e-tests-cache ]
|
|
steps:
|
|
|
|
- name: Create dirs.
|
|
run: |
|
|
mkdir -p code/woocommerce
|
|
mkdir -p package/woocommerce
|
|
mkdir -p tmp/woocommerce
|
|
mkdir -p node_modules
|
|
|
|
- name: Checkout code.
|
|
uses: actions/checkout@v2
|
|
with:
|
|
path: package/woocommerce
|
|
|
|
# From https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#using-the-cache-action
|
|
- name: Cache node modules
|
|
uses: actions/cache@v2
|
|
id: cache_node_modules
|
|
env:
|
|
cache-name: cache-node-modules
|
|
with:
|
|
path: ./node_modules
|
|
key: ${{ runner.os }}-build-${{ hashFiles('package-lock.json') }}
|
|
restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}-
|
|
|
|
- name: Restore node modules from cache, if available.
|
|
run: mv ./node_modules package/woocommerce/node_modules
|
|
|
|
- name: Run npm install.
|
|
working-directory: package/woocommerce
|
|
run: npm install
|
|
|
|
- name: Load docker images and start containers.
|
|
working-directory: package/woocommerce
|
|
run: npx wc-e2e docker:up
|
|
|
|
- name: Move current directory to code. We will install zip file in this dir later.
|
|
run: mv ./package/woocommerce/* ./code/woocommerce
|
|
|
|
- name: Download WooCommerce ZIP.
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: woocommerce
|
|
path: tmp
|
|
|
|
- name: Extract and replace WooCommerce zip.
|
|
working-directory: tmp
|
|
run: |
|
|
unzip woocommerce.zip -d woocommerce
|
|
mv woocommerce/woocommerce/* ../package/woocommerce/
|
|
|
|
- name: Run tests command.
|
|
working-directory: code/woocommerce
|
|
run: npx wc-e2e test:e2e
|