Skip to content

Commit

Permalink
ci: run website azure deploy only from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Oct 31, 2024
1 parent c12d782 commit 0e734f7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 61 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/bundle-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,28 @@ jobs:
monosize-report.md
pr.txt
# ===================================
# NON PR (MASTER) WORKFLOW STEPS
# ===================================

- name: Build all packages & create reports (non-PR)
if: github.event_name != 'pull_request'
run: yarn nx run-many -t bundle-size --nxBail

- name: Login via Azure CLI (non-PR)
if: github.event_name != 'pull_request'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Upload a report (non-PR)
if: github.event_name != 'pull_request'
uses: azure/cli@v2
with:
azcliversion: latest
# TODO: how to set subcription? monosize has no flag for it and gha az cli doesn't support this parameter
# TODO: how to set subcription? monosize has no flag for it and gha az cli doesn't support this parameter
# azureSubscription: 'Bundlesize Testing'
inlineScript: |
yarn monosize upload-report --branch=${{ github.ref }} --commit-sha ${{ github.sha }}
Expand Down
78 changes: 59 additions & 19 deletions .github/workflows/pr-website-deploy-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,41 @@ on:
types:
- completed

concurrency:
# see https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow
group: ${{github.event.workflow_run.id }}-${{ github.ref }}
cancel-in-progress: true

env:
DEPLOY_HOST_URL: https://fluentuipr.z22.web.core.windows.net/

# GitHub Secrets for Azure access
# This service principal ("subscription" is a misleading name) only has access to the fluentuipr storage account
AZURE_SUBSCRIPTION: Azure PR deploy - NEW
AZURE_STORAGE: fluentuipr

jobs:
comment:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
permissions:
pull-requests: write
outputs:
pr_number: ${{ steps.pr_number.outputs.id }}
website_url: ${{ steps.website_url.outputs.id }}
steps:
- name: Download artifact
- name: Download WebSite artifacts
uses: actions/download-artifact@v4
with:
name: monosize-report
path: ./results
name: pr-website-artifacts
path: ./website
run_id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

# - name: 'Download artifact'
# uses: dawidd6/action-download-artifact@v2
# with:
# name: pr-website-deploy-url
# path: ./results
# run_id: ${{ github.event.workflow_run.id }}
# workflow: ${{ github.event.workflow.id }}
# workflow_conclusion: success
- uses: actions/download-artifact@v4
with:
name: pr-number
path: ./results
run_id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Load PR number
id: pr_number
Expand All @@ -36,21 +48,49 @@ jobs:

- name: Load URL
id: website_url
run: echo "::set-output name=id::$(cat website-deploy-url.txt)"
working-directory: ./results
run: echo "::set-output name=id::${{env.DEPLOY_HOST_URL}}pull/${{steps.pr_number.outputs.id}}"

- name: Login via Azure CLI
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Upload PR WebSite
uses: azure/cli@v2
env:
AZCOPY_AUTO_LOGIN_TYPE: 'AZCLI'
with:
azcliversion: latest
inlineScript: |
az storage blob upload-batch \
--destination '$web' \
--source ./website \
--account-name ${{ env.AZURE_STORAGE }} \
--destination-path pull/${{steps.pr_number.outputs.id}} \
--auth-mode login \
--overwrite
comment:
runs-on: ubuntu-latest
needs: deploy
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
permissions:
pull-requests: write
steps:
- name: 'Comment on PR'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.pr_number.outputs.id }}
number: ${{ needs.deploy.outputs.pr_number }}
message: |
Pull request demo site: [URL](${{steps.pr_number.outputs.id}})
Pull request demo site: [URL](${{needs.deploy.outputs.website_url}})
- name: Update PR deploy site GitHub status
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const run = require('./.github/deploy-pr-site-status');
const config = { websiteUrl: '${{steps.website_url.outputs.id}}', prId: '${{steps.pr_number.outputs.id}}'};
const config = { websiteUrl: '${{ needs.deploy.outputs.website_url }}', prId: '${{ needs.deploy.outputs.pr_number }}'};
await run({github,context,core,config});
43 changes: 2 additions & 41 deletions .github/workflows/pr-website-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,57 +63,18 @@ jobs:

- name: Generate PR Deploy Site
run: yarn nx run pr-deploy-site:generate:site

- name: Upload WebSite artifacts
uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v4
with:
name: pr-website-artifacts
if-no-files-found: error
path: |
apps/pr-deploy-site/dist/
deploy:
runs-on: ubuntu-latest
needs: ['bundle']
steps:
- name: Download WebSite artifacts
uses: actions/download-artifact@v4
with:
name: pr-website-artifacts
path: ./pr-deploy-site/

- name: 'Login via Azure CLI'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Upload PR WebSite
uses: azure/cli@v2
env:
AZCOPY_AUTO_LOGIN_TYPE: 'AZCLI'
with:
azcliversion: latest
inlineScript: |
az storage blob upload-batch \
--destination '$web' \
--source ./pr-deploy-site \
--account-name ${{ env.AZURE_STORAGE }} \
--destination-path ${{ env.DEPLOY_BASE_PATH }} \
--auth-mode login \
--overwrite
- name: Save WebSite DEPLOY url
run: echo https://${{ env.DEPLOY_HOST }}/${{ env.DEPLOY_BASE_PATH }} > website-deploy-url.txt

- name: Save PR number
run: echo ${{ github.event.number }} > pr.txt

- uses: actions/upload-artifact@v4
with:
name: pr-website-deploy-url
name: pr-number
if-no-files-found: error
path: |
website-deploy-url.txt
pr.txt

0 comments on commit 0e734f7

Please sign in to comment.