Skip to content

Commit

Permalink
Merge pull request #22 from repository/fix-preview-action
Browse files Browse the repository at this point in the history
fix workflow permissions
  • Loading branch information
skyrina authored Oct 14, 2023
2 parents 7a78f77 + c125e49 commit 8f59bd4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 36 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Pull Request

on:
pull_request:
branches: ["main"]
types: [opened, reopened, synchronize]

concurrency: preview-${{ github.ref }}

jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "npm"

- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build
env:
BASE_URL_OVERRIDE: /pr-preview/pr-${{ github.event.number }}/

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: build
path: ./build/
retention-days: 1
21 changes: 21 additions & 0 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy Pull Request Preview

on:
pull_request_target:
types: [closed]

concurrency: preview-${{ github.event.workflow_run.pull_requests[0].number }}

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cleanup Preview
uses: rossjrw/pr-preview-action@v1.4.4
with:
token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
source-dir: ./build/
action: remove
47 changes: 12 additions & 35 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
name: Deploy Preview for Pull Request
name: Deploy Pull Request Preview

on:
pull_request:
branches: ["main"]
types: [opened, reopened, synchronize, closed]
workflow_run:
workflows: ["Build Pull Request"]
types:
- completed

concurrency: preview-${{ github.ref }}
concurrency: preview-${{ github.event.workflow_run.pull_requests[0].number }}

jobs:
preview:
runs-on: ubuntu-latest
if: github.event.action != 'closed' && !github.event.pull_request.merged

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

- name: Setup Node.js
uses: actions/setup-node@v3
- name: Download Artifact
uses: dawidd6/action-download-artifact@v2
with:
node-version: 18.x
cache: "npm"

- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build
env:
BASE_URL_OVERRIDE: /pr-preview/pr-${{ github.event.number }}/
run_id: ${{ github.event.workflow_run.id }}
name: build
path: ./build/

- name: Deploy Preview
uses: rossjrw/pr-preview-action@v1.4.4
with:
token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
source-dir: ./build/

cleanup:
runs-on: ubuntu-latest
if: github.event.action == 'closed' || github.event.pull_request.merged

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

- name: Cleanup Preview
uses: rossjrw/pr-preview-action@v1.4.4
with:
token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
source-dir: ./build/
action: remove
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
Expand Down

0 comments on commit 8f59bd4

Please sign in to comment.