From 1633f90da24efe437128bb4fbd95c1e27932639b Mon Sep 17 00:00:00 2001 From: Miles Petrov Date: Tue, 30 Aug 2022 15:55:47 -0400 Subject: [PATCH] build: demo files deploy to GitHub pages --- .github/workflows/azure-blob-publish.yml | 34 ------------- .github/workflows/build.yml | 61 ++++++++++++++++++++++++ .github/workflows/main.yml | 25 ++++++++++ .github/workflows/pages-cleanup.yml | 24 ++++++++++ .github/workflows/pages.yml | 40 ++++++++++++++++ 5 files changed, 150 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/azure-blob-publish.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pages-cleanup.yml create mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/azure-blob-publish.yml b/.github/workflows/azure-blob-publish.yml deleted file mode 100644 index e4d1b1b968..0000000000 --- a/.github/workflows/azure-blob-publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -on: push -env: - NODE_VERSION: '14.15.4' -jobs: - build-and-deploy: - name: Build and Deploy - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-node@v1 - with: - node-version: ${{ env.NODE_VERSION }} - - - name: Extract branch or tag name - shell: bash - run: echo "##[set-output name=name;]$(echo ${GITHUB_REF#refs/*/})" - id: extract_ref - - - name: npm install, build - shell: bash - run: | - node common/scripts/install-run-rush.js install - node common/scripts/install-run-rush.js rebuild --verbose - ./common/scripts/deploy-to-azure.sh - env: - AZ_LOGIN_NAME: ${{ secrets.AZ_LOGIN_NAME }} - AZ_PASSWORD: ${{ secrets.AZ_PASSWORD }} - AZ_TENANT: ${{ secrets.AZ_TENANT }} - AZ_STORAGE_ACCOUNT: ${{ secrets.AZ_STORAGE_ACCOUNT }} - GITHUB_REPOSITORY: ${{ github.repository }} - IS_TAG: ${{ contains(github.ref, 'tags') }} - REF_NAME: ${{ steps.extract_ref.outputs.name }} - GITHUB_ACTOR: ${{ github.actor }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..f9d425dd39 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,61 @@ +name: NPM install and build + +on: + workflow_call: + inputs: + cache_sha: + type: string + required: true + +env: + NODE_VERSION: '14.15.4' + +jobs: + install-build: + name: Install and build + runs-on: ubuntu-latest + steps: + - name: Check if contributor is an org member + id: is_organization_member + if: github.event_name == 'pull_request_target' + uses: JamesSingleton/is-organization-member@1.0.1 + with: + organization: ramp4-pcar4 + username: ${{ github.event.pull_request.head.user.login }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Output comment and end build if not org member + if: github.event_name == 'pull_request_target' + run: | + result=${{ steps.is_organization_member.outputs.result }} + if [ $result == false ]; then + user=${{ github.event.pull_request.head.user.login }} + echo Either ${user} is not part of the ramp4-pcar4 organization + echo or ${user} has its Organization Visibility set to Private at + echo https://github.com/orgs/ramp4-pcar4/people?query=${user} + exit 1 + fi + + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref || github.ref_name }} + repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Persist build output for other workflows + uses: actions/cache@v3 + with: + path: packages/ramp-core/dist + key: dist-${{ inputs.cache_sha }} + + - name: Build the files! + shell: bash + run: | + node common/scripts/install-run-rush.js install + node common/scripts/install-run-rush.js rebuild --verbose + env: + NODE_OPTIONS: '--max-old-space-size=8192' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..bc39db4202 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +on: + pull_request_target: + types: [opened, synchronize] + + push: + branches: + - 'main' + - 'master' + - 'develop' + tags: + - v** + +jobs: + build: + name: Develop build for demo files + uses: ./.github/workflows/build.yml + with: + cache_sha: ${{ github.event.pull_request.head.sha || github.sha }} + + deploy-pages: + needs: [build] + name: Deploy the files + uses: ./.github/workflows/pages.yml + with: + cache_sha: ${{ github.event.pull_request.head.sha || github.sha }} diff --git a/.github/workflows/pages-cleanup.yml b/.github/workflows/pages-cleanup.yml new file mode 100644 index 0000000000..ae23a5ab67 --- /dev/null +++ b/.github/workflows/pages-cleanup.yml @@ -0,0 +1,24 @@ +name: Cleanup GitHub pages + +on: + pull_request_target: + types: [closed] + +jobs: + cleanup-pages: + name: Cleanup GitHub pages + runs-on: ubuntu-latest + steps: + ## Delete the PR demo from gh-pages when the PR is closed + - uses: actions/checkout@v3 + with: + ref: 'gh-pages' + + - name: Delete the files + shell: bash + run: | + git config --global user.email "miles.petrov@ec.gc.ca" + git config --global user.name "Miles Petrov" + git rm -r ${{ github.head_ref }}/* + git commit -a -m 'Delete PR demo ${{ github.head_ref }}' + git push origin HEAD:gh-pages diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000000..669c7bf0e6 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,40 @@ +name: Publish to GitHub pages + +on: + workflow_call: + inputs: + cache_sha: + type: string + required: true + +jobs: + deploy-to-pages: + name: Deploy to GitHub pages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Get dist files + uses: actions/cache@v3 + with: + path: dist + key: dist-${{ inputs.cache_sha }} + + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: dist + target-folder: ${{ github.head_ref || github.ref_name }} + + - uses: actions/github-script@v6 + name: Post link to demo for PR's + if: github.event_name == 'pull_request_target' && github.event.action == 'opened' + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Your demo site is ready! 🚀 Visit it here: https://${{github.repository_owner}}.github.io/fgpv-vpgf/${{github.head_ref}}/` + })