-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4769 from ampproject/add/create-release-zip-action
Add release-zip job and workflow
- Loading branch information
Showing
2 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
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 | ||
body: ${{ steps.get-comment-body.outputs.body }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters