11name : Build and Deploy packages/example
2+
23env :
34 VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
45 VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
56
67on :
7- workflow_dispatch :
8- inputs :
9- pr_number :
10- description : " Pull Request Number"
11- required : true
12- type : string
138 push :
149 branches :
1510 - main
1813 - " packages/yak-swc/**"
1914 - " packages/next-yak/**"
2015 - " .github/workflows/example.yml"
21- pull_request :
22- branches :
23- - main
24- paths :
25- - " packages/example/**"
26- - " packages/yak-swc/**"
27- - " packages/next-yak/**"
28- - " .github/workflows/example.yml"
16+ workflow_dispatch :
17+ inputs :
18+ pr_number :
19+ description : " Pull Request Number"
20+ required : true
21+ type : string
22+
23+ permissions :
24+ contents : read
2925
3026jobs :
3127 build-and-deploy :
3228 runs-on : ubuntu-latest
29+ # Define whether this is a production deployment
30+ env :
31+ IS_PRODUCTION : ${{ github.event_name == 'push' }}
32+ PR_NUMBER : ${{ github.event.inputs.pr_number }}
33+
3334 steps :
3435 - name : Checkout
3536 uses : actions/checkout@v3
3637 with :
37- ref : ${{ github.event.pull_request.head.sha || github.ref }}
38+ ref : ${{ github.event.inputs.pr_number && format('refs/pull/{0}/head', github.event.inputs.pr_number) || github.ref }}
39+
3840 - uses : pnpm/action-setup@v4
3941 name : Install pnpm
4042 with :
4143 version : 10.15.0
4244 run_install : false
45+
4346 - name : Install Node.js
4447 uses : actions/setup-node@v3
4548 with :
4649 node-version : 22
4750 cache : " pnpm"
51+
4852 - name : Install node_modules
4953 run : pnpm install
5054
@@ -55,13 +59,10 @@ jobs:
5559 run : pnpm --filter next-yak-example lint
5660
5761 - name : Install Rust
58- uses : actions-rs/ toolchain@v1
62+ uses : dtolnay/rust- toolchain@stable
5963 with :
60- toolchain : stable
61- profile : minimal
62- override : true
63- - name : Add wasm32-wasip1 target
64- run : rustup target add wasm32-wasip1
64+ targets : wasm32-wasip1
65+
6566 - name : Enable caching
6667 uses : Swatinem/rust-cache@v2
6768 with :
@@ -72,53 +73,36 @@ jobs:
7273
7374 - name : Install Vercel CLI
7475 run : npm install -g vercel@35
76+
7577 - name : Link Vercel project
7678 run : vercel link --yes --token ${{ secrets.VERCEL_TOKEN }}
7779
78- # Preview deployment (for pull requests and non-main pushes )
80+ # Preview deployment (for workflow_dispatch )
7981 - name : Pull Vercel environment information (Preview)
80- if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
82+ if : env.IS_PRODUCTION == 'false'
8183 run : vercel pull --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }}
84+
8285 - name : Build project artifacts (Preview)
83- if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
86+ if : env.IS_PRODUCTION == 'false'
8487 run : vercel build --token ${{ secrets.VERCEL_TOKEN }}
88+
8589 - name : Deploy to Vercel (Preview)
8690 id : deploy-preview
87- if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref != 'refs/heads/main')
91+ if : env.IS_PRODUCTION == 'false'
8892 run : |
8993 DEPLOYMENT_URL=$(vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }})
9094 echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
91- - name : Find Documentation Comment
92- uses : peter-evans/find-comment@v3
93- id : find-comment
94- if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
95- with :
96- issue-number : ${{ github.event.number }}
97- comment-author : " github-actions[bot]"
98- body-includes : " 🧪 Example App Preview Deployed!"
99- - name : Create or Update Documentation Comment
100- if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
101- uses : peter-evans/create-or-update-comment@v4
102- with :
103- comment-id : ${{ steps.find-comment.outputs.comment-id }}
104- issue-number : ${{ github.event.number }}
105- body : |
106- ## 🧪 Example App Preview Deployed!
107-
108- A preview of the example app changes in this PR has been deployed to Vercel:
109-
110- 🔗 [View Example App Preview](${{ steps.deploy-preview.outputs.deployment_url }})
111-
112- This preview will update automatically with new commits to this PR.
113- edit-mode : replace
95+ echo "Preview deployment URL: $DEPLOYMENT_URL"
11496
11597 # Production deployment (for main branch pushes)
11698 - name : Pull Vercel environment information (Production)
117- if : github.event_name == 'push' && github.ref == 'refs/heads/main '
99+ if : env.IS_PRODUCTION == 'true '
118100 run : vercel pull --yes --environment=production --token ${{ secrets.VERCEL_TOKEN }}
101+
119102 - name : Build project artifacts (Production)
120- if : github.event_name == 'push' && github.ref == 'refs/heads/main '
103+ if : env.IS_PRODUCTION == 'true '
121104 run : vercel build --prod --token ${{ secrets.VERCEL_TOKEN }}
105+
122106 - name : Deploy to Vercel (Production)
123- if : github.event_name == 'push' && github.ref == 'refs/heads/main '
107+ if : env.IS_PRODUCTION == 'true '
124108 run : vercel deploy --prebuilt --prod --token ${{ secrets.VERCEL_TOKEN }}
0 commit comments