Skip to content

Commit

Permalink
Merge branch 'develop' into add/4569-frontend-performance-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera committed Jun 10, 2020
2 parents e3d0794 + eaf48bd commit b55eb14
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 25 deletions.
101 changes: 89 additions & 12 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:

jobs:

release-zip:
name: Build plugin ZIPs and upload them as GHA artifact
dev-zip:
name: Build dev build ZIP and upload as GHA artifact
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -59,13 +59,79 @@ jobs:
run: npm install --ignore-scripts

- name: Create destination directories
run: mkdir -p builds/{dev,prod}
run: mkdir -p builds/dev

- name: Build develop version
run: |
npm run build:dev
mv amp.zip builds/dev/amp.zip
- name: Retrieve branch name
id: retrieve-branch-name
run: echo "::set-output name=branch_name::$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')"

- name: Retrieve git SHA-8 string
id: retrieve-git-sha-8
run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"

- name: Upload build as artifact
uses: actions/upload-artifact@v2
with:
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}-dev
path: builds/dev

#-----------------------------------------------------------------------------------------------------------------------

prod-zip:
name: Build prod build ZIP and upload as GHA artifact
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
outputs:
branch-name: ${{ steps.retrieve-branch-name.outputs.branch_name }}
git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }}

steps:
- name: Check out source files
uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Configure Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer dependencies
# Scripts are not ignored as they are needed to apply patches for the
# `sabberworm/php-css-parser` dependency.
run: composer install --prefer-dist --optimize-autoloader

- name: Get npm cache directory
id: npm-cache
run: |
echo "::set-output name=dir::$(npm config get cache)"
- name: Configure npm cache
uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node dependencies
# Prevent malicious scripts from being run with `--ignore-scripts`
run: npm install --ignore-scripts

- name: Create destination directories
run: mkdir -p builds/prod

- name: Build production version
run: |
npm run build:prod
Expand All @@ -79,33 +145,44 @@ jobs:
id: retrieve-git-sha-8
run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"

- name: Upload artifacts
- name: Upload build as artifact
uses: actions/upload-artifact@v2
with:
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}
path: builds
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}-prod
path: builds/prod

#-----------------------------------------------------------------------------------------------------------------------

upload-to-gcs:
name: Upload plugin ZIPs to Google Cloud Storage
runs-on: ubuntu-latest
needs: release-zip
needs:
- dev-zip
- prod-zip
steps:
- name: Download artifacts
- name: Download dev build
uses: actions/download-artifact@v2
with:
name: amp-${{ needs.release-zip.outputs.branch-name }}-${{ needs.release-zip.outputs.git-sha-8 }}
path: builds
name: amp-${{ needs.dev-zip.outputs.branch-name }}-${{ needs.dev-zip.outputs.git-sha-8 }}-dev
path: builds/dev

- name: Download prod build
uses: actions/download-artifact@v2
with:
name: amp-${{ needs.prod-zip.outputs.branch-name }}-${{ needs.prod-zip.outputs.git-sha-8 }}-prod
path: builds/prod

- name: Setup Google Cloud SDK
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
project_id: ${{ secrets.GCS_PROJECT_ID }}
service_account_key: ${{ secrets.GCS_APPLICATION_CREDENTIALS }}

- name: Upload artifacts to bucket
run: gsutil cp -r builds/* gs://ampwp_github_artifacts/${{ github.ref }}
- name: Upload dev build to bucket
run: gsutil cp -r builds/dev/amp.zip gs://ampwp_github_artifacts/${{ github.ref }}/dev/amp.zip

- name: Upload prod build to bucket
run: gsutil cp -r builds/prod/amp.zip gs://ampwp_github_artifacts/${{ github.ref }}/prod/amp.zip

#-----------------------------------------------------------------------------------------------------------------------

Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"eslint": "7.2.0",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.21.2",
"eslint-plugin-jest": "23.13.1",
"eslint-plugin-jest": "23.13.2",
"eslint-plugin-react": "7.20.0",
"grunt": "1.1.0",
"grunt-contrib-clean": "2.0.0",
Expand Down

0 comments on commit b55eb14

Please sign in to comment.