Skip to content

Commit

Permalink
ci: improve deploy preview speed (#29)
Browse files Browse the repository at this point in the history
* ci: improve deploy preview speed

* sync eslint rules

* fix issues

* fix deploy

* fix deploy-preview

* fix url issue
  • Loading branch information
juliodialpad authored Nov 30, 2023
1 parent bb5dd16 commit bb288a8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 105 deletions.
130 changes: 27 additions & 103 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,6 @@ concurrency:
cancel-in-progress: true

jobs:
cache-and-install:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

filter-actions:
runs-on: ubuntu-latest
permissions:
Expand All @@ -73,16 +39,17 @@ jobs:
- 'packages/**'
dialtone:
needs: [cache-and-install, filter-actions]
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
deploy:
needs: filter-actions
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
env:
VUEPRESS_BASE_URL: /deploy-previews/pr-${{github.event.pull_request.number}}/
DIALTONE_BUCKET_DIRECTORY: dialtone.dialpad.com/deploy-previews/pr-${{ github.event.pull_request.number }}/
DIALTONE_VUE_3_BUCKET_DIRECTORY: dialtone.dialpad.com/vue3/deploy-previews/pr-${{ github.event.pull_request.number }}/
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -116,8 +83,13 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Build Dialtone library and documentation site
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
run: pnpm nx run --verbose dialtone-documentation:build

- name: Build Dialtone-vue 3 library and documentation site
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
run: pnpm nx run --verbose dialtone-vue3-documentation:build

- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
Expand All @@ -128,100 +100,52 @@ jobs:
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Clean up bucket ${{ env.VUEPRESS_BASE_URL }} directory
- name: Clean up bucket Dialtone
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
continue-on-error: true
run: gcloud storage rm --recursive ${{ format('gs://{0}', env.DIALTONE_BUCKET_DIRECTORY) }}

- name: Clean up bucket Dialtone Vue 3
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
continue-on-error: true
run: gcloud storage rm --recursive ${{ format('gs://dialtone.dialpad.com{0}', env.VUEPRESS_BASE_URL) }}
run: gcloud storage rm --recursive ${{ format('gs://{0}', env.DIALTONE_VUE_3_BUCKET_DIRECTORY) }}

- name: Upload Dialtone to GCP
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
uses: google-github-actions/upload-cloud-storage@v1
with:
path: apps/dialtone-documentation/docs/.vuepress/dist
destination: ${{ format('dialtone.dialpad.com{0}', env.VUEPRESS_BASE_URL) }}
destination: ${{ env.DIALTONE_BUCKET_DIRECTORY }}
parent: false

- name: Add Message
- name: Add Dialtone ready message
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
uses: mshick/add-pr-comment@v1
env:
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
✔️ Dialtone Deploy Preview ready!
😎 Browse the preview: https://dialtone.dialpad.com/deploy-previews/pr-${{ github.event.pull_request.number }}
😎 Browse the preview: https://${{ env.DIALTONE_BUCKET_DIRECTORY }}
allow-repeats: true
dialtone-vue-3:
needs: [cache-and-install, filter-actions]
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
env:
BASE_DIRECTORY: /vue3/deploy-previews/pr-${{github.event.pull_request.number}}/
steps:
- uses: actions/checkout@v4
with:
ref: "refs/pull/${{ github.event.pull_request.number }}/merge"

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build Dialtone library and documentation site
run: pnpm nx run --verbose dialtone-vue3-documentation:build

- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
workload_identity_provider: ${{ secrets.DIALTONE_GCP_WIP }}
service_account: ${{ secrets.DIALTONE_GCP_SA }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Clean up bucket ${{ env.BASE_DIRECTORY }} directory
continue-on-error: true
run: gcloud storage rm --recursive ${{ format('gs://dialtone.dialpad.com{0}', env.BASE_DIRECTORY) }}

- name: Upload Dialtone-vue 3 to GCP
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
uses: google-github-actions/upload-cloud-storage@v1
with:
path: apps/dialtone-vue3-documentation/storybook-static
destination: ${{ format('dialtone.dialpad.com{0}', env.BASE_DIRECTORY) }}
destination: ${{ env.DIALTONE_VUE_3_BUCKET_DIRECTORY }}
parent: false

- name: Add Message
- name: Add Dialtone Vue 3 ready message
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
uses: mshick/add-pr-comment@v1
env:
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
message: |
✔️ Dialtone-vue 3 Deploy Preview ready!
😎 Browse the preview: https://dialtone.dialpad.com/vue3/deploy-previews/pr-${{ github.event.pull_request.number }}
😎 Browse the preview: https://${{ env.DIALTONE_VUE_3_BUCKET_DIRECTORY }}
allow-repeats: true
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ jobs:

deploy-dialtone:
needs: [cache-and-install, check-dialpad-member, get-branch-name, filter-actions]
if: ${{ needs.filter-actions.outputs.dialtone == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: 'read'
Expand Down Expand Up @@ -180,7 +179,6 @@ jobs:

deploy-dialtone-vue-3:
needs: [cache-and-install, check-dialpad-member, get-branch-name, filter-actions]
if: ${{ needs.filter-actions.outputs.dialtone-vue-3 == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: 'read'
Expand Down
3 changes: 3 additions & 0 deletions apps/dialtone-vue3-documentation/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module.exports = {
'max-len': ['error', {
code: 120,
tabWidth: 2,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'prefer-promise-reject-errors': ['error', {
allowEmptyReject: true,
Expand Down

0 comments on commit bb288a8

Please sign in to comment.