Skip to content

Commit

Permalink
ci: add pr preview
Browse files Browse the repository at this point in the history
  • Loading branch information
moecasts committed Jun 14, 2024
1 parent 4089129 commit 805031a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 18 deletions.
18 changes: 18 additions & 0 deletions .github/actions/build-site/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build site

description: build site artifacts

runs:
using: 'composite'
steps:
- name: restore build artifacts
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
path: |
packages/*/dist
key: ${{ runner.os }}-build-artifacts-${{ hashfiles('packages/*/src', 'packages/*/package.json', '!packages/casts-theme/src/tokens/ts') }}

- name: build site
run: pnpm --filter 'site' build && cp ./site/dist/index.html ./site/dist/404.html
shell: bash
2 changes: 1 addition & 1 deletion .github/actions/setup-environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ runs:
packages/casts-common/dist
packages/casts-config-provider/dist
packages/casts-locale/dist
key: ${{ runner.os }}-build-icons-artifacts-${{ hashfiles('packages/casts-standard/dist, packages/casts-standard/package.json, packages/casts-cli/dist, packages/casts-cli/package.json, packages/casts-theme/dist, packages/casts-theme/styles, packages/casts-theme/package.json, packages/casts-common/dist, packages/casts-common/package.json, packages/casts-config-provider/dist, packages/casts-config-provider/package.json, packages/casts-locale/dist, packages/casts-locale/package.json') }}
key: ${{ runner.os }}-build-base-artifacts-${{ hashfiles('packages/casts-standard/src', 'packages/casts-standard/package.json', 'packages/casts-cli/src', 'packages/casts-cli/package.json', 'packages/casts-theme/src', 'packages/casts-theme/styles', '!packages/casts-theme/src/tokens/ts', 'packages/casts-theme/package.json', 'packages/casts-common/src', 'packages/casts-common/package.json', 'packages/casts-config-provider/src', 'packages/casts-config-provider/package.json', 'packages/casts-locale/src', 'packages/casts-locale/package.json') }}

- name: build base packages
if: ${{ steps.cache-build-base-artifacts.outputs.cache-hit != 'true' }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simple workflow for deploying static content to GitHub Pages
name: packages build
name: build-packages

on:
workflow_call:
Expand All @@ -17,15 +17,13 @@ jobs:
uses: ./.github/actions/setup-environment

# The icons package is too large, so it will be built separately and optimized with caching.
- name: cache build icon artifacts
- name: cache build icons artifacts
id: cache-build-icons-artifacts
uses: actions/cache@v4
with:
path: |
packages/casts-icons/dist
key: ${{ runner.os }}-build-icons-artifacts-${{ hashfiles('packages/casts-icons/src,packages/casts-icons/package.json') }}
restore-keys: |
${{ runner.os }}-build-icons-artifacts-
key: ${{ runner.os }}-build-icons-artifacts-${{ hashfiles('packages/casts-icons/src', 'packages/casts-icons/package.json') }}

- name: build icons package
if: steps.cache-build-icons-artifacts.outputs.cache-hit != 'true'
Expand All @@ -38,7 +36,7 @@ jobs:
with:
path: |
packages/*/dist
key: ${{ runner.os }}-build-icons-artifacts-${{ hashfiles('packages/*/src/**/*,packages/*/package.json') }}
key: ${{ runner.os }}-build-artifacts-${{ hashfiles('packages/*/src', 'packages/*/package.json', '!packages/casts-theme/src/tokens/ts') }}

- name: build all packages (expect built packages)
if: ${{ steps.cache-build-artifacts.outputs.cache-hit != 'true' }}
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/preview-pr-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Simple workflow for deploying static content to GitHub Pages
name: preview pr publish

on:
pull_request:
types: [opened, reopened, synchronize]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
pull-requests: write

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
build-artifacts:
uses: ./.github/workflows/build-packages.yaml

deploy:
needs: build-artifacts
runs-on: ubuntu-latest
outputs:
url: ${{ steps.surge.outputs.url }}
steps:
- name: checkout
uses: actions/checkout@v4

- name: setup-environment
uses: ./.github/actions/setup-environment

- name: build site
uses: ./.github/actions/build-site

- name: find-pr
uses: jwalton/gh-find-current-pr@master
id: find-pr

- name: deploy to surge
id: surge
run: |
repository=${{github.repository}}
project_name=${repository#*/}
export DEPLOY_DOMAIN=https://preview-pr-${{ steps.find-pr.outputs.number }}-$project_name.surge.sh
npx surge --project ./site/dist --domain $DEPLOY_DOMAIN --token ${{ secrets.CASTS_DESIGN_SURGE_TOKEN }}
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
pr-comment-preview-prepare:
runs-on: ubuntu-latest
steps:
- name: preview parepare
uses: thollander/actions-comment-pull-request@v2
with:
message: |
![preview-is-preparing](https://github.com/moecasts/casts-design/assets/37169906/25e18e7c-4d9a-404b-ac7a-1d035b24d9d6)
comment_tag: preview

pr-comment-preview-ready:
runs-on: ubuntu-latest
needs: [deploy, pr-comment-preview-prepare]
steps:
- name: preview built
uses: thollander/actions-comment-pull-request@v2
with:
message: |
[![preview-is-ready](https://github.com/moecasts/casts-design/assets/37169906/e35faa8b-d60b-4d86-af41-389734a4d61a)](${{ needs.deploy.outputs.url }})
comment_tag: preview
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simple workflow for deploying static content to GitHub Pages
name: deploy static content to pages
name: preview release publish

on:
# Runs on pushes targeting the default branch
Expand All @@ -22,7 +22,7 @@ concurrency:

jobs:
build-artifacts:
uses: ./.github/workflows/packages-build.yaml
uses: ./.github/workflows/build-packages.yaml

deploy:
environment:
Expand All @@ -37,23 +37,15 @@ jobs:
- name: setup-environment
uses: ./.github/actions/setup-environment

- name: restore build artifacts
uses: actions/cache/restore@v4
with:
path: |
packages/*/dist
key: ${{ runner.os }}-build-icons-artifacts-${{ hashfiles('packages/*/src/**/*,packages/*/package.json') }}

- name: build site
run: pnpm --filter 'site' build && cp ./site/dist/index.html ./site/dist/404.html
uses: ./.github/actions/build-site

- name: setup pages
uses: actions/configure-pages@v5

- name: upload artifact
uses: actions/upload-pages-artifact@v3
with:
# upload dist repository
path: './site/dist'

- name: deploy to github pages
Expand Down

0 comments on commit 805031a

Please sign in to comment.