Skip to content

Commit

Permalink
build: demo files deploy to GitHub pages
Browse files Browse the repository at this point in the history
  • Loading branch information
milespetrov committed Aug 30, 2022
1 parent 088f985 commit 1633f90
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 34 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/azure-blob-publish.yml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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'
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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 }}
24 changes: 24 additions & 0 deletions .github/workflows/pages-cleanup.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
40 changes: 40 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -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}}/`
})

0 comments on commit 1633f90

Please sign in to comment.