Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release-zip job and workflow #4769

Merged
merged 26 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dc2b3c1
Add release-zip job and workflow
schlessera May 25, 2020
457705c
Build production and developer versions of plugin
pierlon May 25, 2020
b6e1d2e
Upload PR artifacts to wiki; prune them when PR is closed
pierlon May 25, 2020
d8fde6e
Update job name
pierlon May 25, 2020
7e5f913
Get branch name from GITHUB_HEAD_REF if it's a PR
pierlon May 25, 2020
f892028
Fix typo
pierlon May 25, 2020
1c40816
Add job to comment on PR with link to plugin builds
pierlon May 25, 2020
f451fe9
Remove 'prune' workflow
pierlon Jun 2, 2020
c4d37d1
Store builds on Google Storage
pierlon Jun 2, 2020
cf7e566
Fix job ID
pierlon Jun 2, 2020
f811451
Prefix object name with git ref
pierlon Jun 2, 2020
15c37e6
Put plugins builds in separate directories
pierlon Jun 3, 2020
8447bab
Only copy files in `builds` folder
pierlon Jun 3, 2020
ecb269e
Include commit hash in comment
pierlon Jun 3, 2020
63af560
Update the comment if it already exists
pierlon Jun 3, 2020
3b24315
Do not run on draft PRs
pierlon Jun 3, 2020
5371573
Separate 'create' and 'update' comment jobs
pierlon Jun 3, 2020
3a476d6
Replace body on update
pierlon Jun 3, 2020
f93a954
Rename jobs and add their respective descriptions
pierlon Jun 8, 2020
22d0485
Make comment body DRY
pierlon Jun 8, 2020
f62750c
Fix job name
pierlon Jun 8, 2020
58960b3
Fix typo
pierlon Jun 9, 2020
9b2db09
Close parenthesis on separate line
pierlon Jun 9, 2020
8c46356
Escape line-feeds
pierlon Jun 9, 2020
9874777
Update comment body
pierlon Jun 9, 2020
42e945e
Update emoji in comment
pierlon Jun 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: Build, test & measure

on:
push:
branches:
- develop
- master
pull_request:
# Run workflow whenever a PR is opened, updated (synchronized), or marked ready for review.
types: [opened, synchronize, ready_for_review]

jobs:
release-zip:
name: Build plugin ZIPs and upload them 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/{dev,prod}

- name: Build develop version
run: |
npm run build:dev
mv amp.zip builds/dev/amp.zip

- name: Build production version
run: |
npm run build:prod
mv amp.zip builds/prod/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 artifacts
uses: actions/upload-artifact@v2
with:
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}
path: builds

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

- 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 }}

comment-on-pr:
pierlon marked this conversation as resolved.
Show resolved Hide resolved
name: Comment on PR with links to plugin ZIPs
# Only run this job if it's a PR. One way to check for that is if `github.head_ref` is not empty.
if: ${{ github.head_ref && github.head_ref != null }}
runs-on: ubuntu-latest
needs: upload-to-gcs

outputs:
pr_number: ${{ steps.get-pr-number.outputs.num }}
comment_body: ${{ steps.get-comment-body.outputs.body }}

steps:
- name: Get PR number
id: get-pr-number
run: echo "::set-output name=num::$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')"

- name: Check if a comment was already made
id: find-comment
uses: peter-evans/find-comment@v1
with:
issue-number: ${{ steps.get-pr-number.outputs.num }}
comment-author: github-actions[bot]
body-includes: Download [development build]

- name: Get comment body
id: get-comment-body
# Setting a multi-line output requires escaping line-feeds. See <https://github.community/t/set-output-truncates-multiline-strings/16852/3>.
run: |
body="Plugin builds for ${{ github.sha }} are ready :bellhop_bell:!
- Download [development build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/dev/amp.zip)
- Download [production build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/prod/amp.zip)"
body="${body//$'\n'/'%0A'}"
echo "::set-output name=body::$body"

- name: Create comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.get-pr-number.outputs.num }}
body: ${{ steps.get-comment-body.outputs.body }}

- name: Update comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
westonruter marked this conversation as resolved.
Show resolved Hide resolved
body: ${{ steps.get-comment-body.outputs.body }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
"webpackbar": "4.0.0"
},
"scripts": {
"build": "npm-run-all build:*",
"build:dev": "cross-env NODE_ENV=development npm-run-all 'build:!(dev|prod)'",
"build:prod": "cross-env NODE_ENV=production npm-run-all 'build:!(dev|prod)'",
"build:prepare": "grunt clean",
"build:css": "npm-run-all build:css:*",
"build:css:copy": "cp -R assets/css/src/* assets/css",
Expand Down