|
| 1 | +name: Build and publish the ZIP build file |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, ready_for_review] |
| 6 | + branches-ignore: |
| 7 | + - 'update_dependencies' |
| 8 | +jobs: |
| 9 | + dev-zip: |
| 10 | + name: Build ZIP and upload to s3 |
| 11 | + if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + branch-name: ${{ steps.retrieve-branch-name.outputs.branch_name }} |
| 15 | + git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }} |
| 16 | + steps: |
| 17 | + - name: Check out source files |
| 18 | + uses: actions/checkout@v2 |
| 19 | + - name: Get Composer Cache Directory |
| 20 | + id: composer-cache |
| 21 | + run: | |
| 22 | + echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 23 | + - name: Configure Composer cache |
| 24 | + uses: actions/cache@v1 |
| 25 | + with: |
| 26 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 27 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 28 | + restore-keys: | |
| 29 | + ${{ runner.os }}-composer- |
| 30 | + - name: Install composer deps |
| 31 | + run: composer install --no-dev --prefer-dist --no-progress --no-suggest |
| 32 | + - name: Install npm deps |
| 33 | + run: npm ci |
| 34 | + - name: Build files |
| 35 | + run: npm run build |
| 36 | + - name: Create zip |
| 37 | + run: npm run dist |
| 38 | + - name: Retrieve branch name |
| 39 | + id: retrieve-branch-name |
| 40 | + run: echo "::set-output name=branch_name::$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')" |
| 41 | + - name: Retrieve git SHA-8 string |
| 42 | + id: retrieve-git-sha-8 |
| 43 | + run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)" |
| 44 | + - name: Upload Latest Version to S3 |
| 45 | + uses: jakejarvis/s3-sync-action@master |
| 46 | + with: |
| 47 | + args: --acl public-read --follow-symlinks --delete |
| 48 | + env: |
| 49 | + AWS_S3_BUCKET: ${{ secrets.AWS_DEV_BUCKET }} |
| 50 | + AWS_ACCESS_KEY_ID: ${{ secrets.S3_AWS_KEY_ARTIFACTS }} |
| 51 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_AWS_SECRET_ARTIFACTS }} |
| 52 | + SOURCE_DIR: artifact/ |
| 53 | + DEST_DIR: ${{ github.event.pull_request.base.repo.name }}-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}/ |
| 54 | + |
| 55 | + comment-on-pr: |
| 56 | + name: Comment on PR with links to plugin ZIPs |
| 57 | + if: ${{ github.head_ref && github.head_ref != null }} |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: dev-zip |
| 60 | + env: |
| 61 | + CI: true |
| 62 | + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} |
| 63 | + outputs: |
| 64 | + pr_number: ${{ steps.get-pr-number.outputs.num }} |
| 65 | + comment_body: ${{ steps.get-comment-body.outputs.body }} |
| 66 | + steps: |
| 67 | + - name: Get PR number |
| 68 | + id: get-pr-number |
| 69 | + run: echo "::set-output name=num::$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" |
| 70 | + |
| 71 | + - name: Check if a comment was already made |
| 72 | + id: find-comment |
| 73 | + uses: peter-evans/find-comment@v2 |
| 74 | + with: |
| 75 | + issue-number: ${{ steps.get-pr-number.outputs.num }} |
| 76 | + comment-author: github-actions[bot] |
| 77 | + body-includes: Download Plugin - [Download] |
| 78 | + |
| 79 | + - name: Get comment body |
| 80 | + id: get-comment-body |
| 81 | + run: | |
| 82 | + body="Plugin build for ${{ github.event.pull_request.head.sha }} is ready :bellhop_bell:! |
| 83 | + - Download Plugin - [Download](https://verti-artifacts.s3.amazonaws.com/${{ github.event.pull_request.base.repo.name }}-${{ needs.dev-zip.outputs.branch-name }}-${{ needs.dev-zip.outputs.git-sha-8 }}/hyve-lite.zip)" |
| 84 | + body="${body//$'\n'/'%0A'}" |
| 85 | + echo "::set-output name=body::$body" |
| 86 | +
|
| 87 | + - name: Create comment on PR with links to plugin builds |
| 88 | + if: ${{ steps.find-comment.outputs.comment-id == '' }} |
| 89 | + uses: peter-evans/create-or-update-comment@v2 |
| 90 | + with: |
| 91 | + issue-number: ${{ steps.get-pr-number.outputs.num }} |
| 92 | + body: ${{ steps.get-comment-body.outputs.body }} |
| 93 | + |
| 94 | + - name: Update comment on PR with links to plugin builds |
| 95 | + if: ${{ steps.find-comment.outputs.comment-id != '' }} |
| 96 | + uses: peter-evans/create-or-update-comment@v2 |
| 97 | + with: |
| 98 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 99 | + edit-mode: replace |
| 100 | + body: ${{ steps.get-comment-body.outputs.body }} |
0 commit comments