Skip to content

Commit

Permalink
feat(actions): Add netlify preview (#229)
Browse files Browse the repository at this point in the history
* feat(actions): Add netlify preview

* feat(actions): Add preview
  • Loading branch information
1ilsang authored Jun 2, 2024
1 parent a9fc5ca commit b4b3d45
Show file tree
Hide file tree
Showing 6 changed files with 7,590 additions and 65 deletions.
63 changes: 63 additions & 0 deletions .github/actions/netlify-preview/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: netlify-preview

inputs:
NETLIFY_SITE_ID:
required: true
NETLIFY_API_TOKEN:
required: true
HEAD_COMMIT:
required: true

runs:
using: composite

steps:
# https://cli.netlify.com/
- name: Netlify deploy
id: netlify-deploy
shell: bash
run: |
pnpm nf deploy \
--dir out \
--site ${{ inputs.NETLIFY_SITE_ID }} \
--auth ${{ inputs.NETLIFY_API_TOKEN }} \
--json \
> deploy_output.json
- name: Generate URL Preview
id: url-preview
shell: bash
# pnpm 샌드박스 로그가 json 파일에 상단에 추가되는 버그가 있음.
# 로그 삭제후 5번째 라인부터 JSON 파일 재생성
run: |
tail -n +5 deploy_output.json > parsed_output.json
echo $(cat parsed_output.json)
NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' parsed_output.json)
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT"
- name: Comment URL Preview on PR
uses: actions/github-script@v7
env:
NETLIFY_PREVIEW_URL: ${{ steps.url-preview.outputs.NETLIFY_PREVIEW_URL }}
HEAD_COMMIT: ${{ inputs.HEAD_COMMIT }}
with:
script: |
async function comment(){
const result = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: process.env.HEAD_COMMIT,
});
const issueNumber = result.data[0]?.number;
if (issueNumber) {
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview URL: ${process.env.NETLIFY_PREVIEW_URL}`
});
} else {
console.log('No PR found for commit ' + process.env.HEAD_COMMIT);
}
}
comment();
21 changes: 21 additions & 0 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [main]
pull_request:
branches: [main]
permissions:
pull-requests: write

jobs:
lint:
Expand All @@ -28,3 +30,22 @@ jobs:

- name: 🏗 Build and Export
uses: ./.github/actions/nextjs-build-export

preview:
runs-on: macos-latest
needs: build-export
steps:
- uses: actions/checkout@v4

# 캐싱 된 값을 사용
- name: 🌱 Install pnpm
uses: ./.github/actions/pnpm-install
- name: 🏗 Build and Export
uses: ./.github/actions/nextjs-build-export

- name: 🌈 Netlify preview
uses: ./.github/actions/netlify-preview
with:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_API_TOKEN: ${{ secrets.NETLIFY_API_TOKEN }}
HEAD_COMMIT: ${{ github.event.pull_request.head.sha }}
2 changes: 1 addition & 1 deletion e2e/__snapshots__/about.spec.ts/desktop/about.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e/__snapshots__/about.spec.ts/mobile/about.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"e2e": "pnpm playwright test",
"clean": "rm -rf .next out node_modules",
"knip": "knip",
"nf": "netlify",
"prepare": "husky",
"preinstall": "npx only-allow pnpm"
},
Expand Down Expand Up @@ -62,6 +63,7 @@
"knip": "^5.9.4",
"markdownlint": "0.34.0",
"markdownlint-cli": "0.41.0",
"netlify-cli": "^17.25.0",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"stylelint": "^16.3.1",
Expand Down
Loading

0 comments on commit b4b3d45

Please sign in to comment.