Skip to content

Commit 464cdfa

Browse files
author
Pier Dolique
committed
refactor(ci): extract reusable workflow for deployment
- ♻️ Migrate deployment logic to reusable workflow from `.github` repo - 🗑️ Remove `vscodeintellicode` from recommended VS Code extensions - 🎯 Simplify `build-and-deploy.yml` by using shared workflow - 🔧 Pass Cloudflare secrets to reusable workflow
1 parent ed965a9 commit 464cdfa

2 files changed

Lines changed: 5 additions & 150 deletions

File tree

Lines changed: 5 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Build and Deploy
2-
description: Build the project and deploy to the appropriate environment.
32

43
permissions:
54
contents: read
@@ -16,156 +15,13 @@ on:
1615
branches:
1716
- master
1817

19-
env:
20-
ARTIFACT_NAME: deployment-artifact
21-
ARTIFACT_PATH: .output
22-
2318
concurrency:
2419
group: build-and-deploy-${{ github.ref }}
2520
cancel-in-progress: true
2621

2722
jobs:
28-
# Check Typescript types correctness
29-
test-typecheck:
30-
name: Typecheck
31-
runs-on: ubuntu-24.04
32-
steps:
33-
- name: Checkout repository
34-
uses: actions/checkout@v5
35-
- uses: ./.github/actions/setup-pnpm
36-
with:
37-
install-dependencies: true
38-
- name: Run typecheck
39-
run: |
40-
pnpm test:typecheck
41-
42-
# Build the project and upload artifact
43-
build:
44-
name: Build artifact
45-
runs-on: ubuntu-24.04
46-
steps:
47-
- name: Checkout repository
48-
uses: actions/checkout@v5
49-
- uses: ./.github/actions/setup-pnpm
50-
with:
51-
install-dependencies: true
52-
- name: Build project
53-
run: |
54-
pnpm run build
55-
- name: Upload build artifact
56-
id: upload-artifact
57-
uses: actions/upload-artifact@v5
58-
with:
59-
include-hidden-files: true
60-
if-no-files-found: error
61-
name: ${{ env.ARTIFACT_NAME }}
62-
path: ${{ env.ARTIFACT_PATH }}
63-
64-
deploy-to-staging:
65-
if: github.event_name == 'pull_request'
66-
name: Deploy to staging
67-
runs-on: ubuntu-24.04
68-
permissions:
69-
pull-requests: write
70-
outputs:
71-
wrangler-log: ${{ steps.set-wrangler-log.outputs.wrangler-log }}
72-
needs:
73-
- build
74-
steps:
75-
# Checkout repository
76-
- name: Checkout repository
77-
uses: actions/checkout@v5
78-
79-
# Setup, and download artifact
80-
- uses: ./.github/actions/pre-deploy
81-
with:
82-
artifact-name: ${{ env.ARTIFACT_NAME }}
83-
unpack-path: ${{ env.ARTIFACT_PATH }}
84-
85-
# Set wrangler log file path for capturing output
86-
- name: Set wrangler output file path
87-
id: set-wrangler-log
88-
run: |
89-
WRANGLER_LOG=/tmp/wrangler-$(date '+%s%N').log
90-
echo "wrangler-log=$WRANGLER_LOG" >> $GITHUB_OUTPUT
91-
92-
# Deploy to Cloudflare Workers
93-
- name: Deploy version to staging
94-
id: deploy-version
95-
continue-on-error: true
96-
env:
97-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
98-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
99-
run: |
100-
export WRANGLER_OUTPUT_FILE_PATH=${{ steps.set-wrangler-log.outputs.wrangler-log }}
101-
pnpm run deploy:versions:staging
102-
103-
# Extract deployment URL from wrangler log
104-
- name: Get deployment URL
105-
id: get-deployment-url
106-
continue-on-error: true
107-
run: |
108-
PREVIEW_URL=$(jq --raw-output --slurp 'first(.[] | select(.preview_url) | .preview_url)' ${{ steps.set-wrangler-log.outputs.wrangler-log }})
109-
110-
if [ -z "$PREVIEW_URL" ]; then
111-
echo "Error: No preview_url found in wrangler log"
112-
exit 1
113-
fi
114-
115-
echo "preview-url=$PREVIEW_URL" >> $GITHUB_OUTPUT
116-
117-
# Comment on the pull request with success status
118-
- name: Comment successful deployment URL
119-
if: ${{ steps.get-deployment-url.outcome == 'success' }}
120-
uses: marocchino/sticky-pull-request-comment@v2
121-
with:
122-
message: |
123-
## 🎉 Deployed to Cloudflare!
124-
125-
- Commit: `${{ github.sha }}`
126-
- Preview URL: ${{ steps.get-deployment-url.outputs.preview-url }}
127-
128-
# Comment on the pull request with failure status
129-
- name: Comment deployment failure
130-
if: ${{ steps.get-deployment-url.outcome == 'failure' }}
131-
uses: marocchino/sticky-pull-request-comment@v2
132-
with:
133-
message: |
134-
## ❌ Deployment to Cloudflare failed!
135-
136-
- Commit: `${{ github.sha }}`
137-
- Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.
138-
139-
# Fail the workflow if deployment failed
140-
- name: Fail workflow if deployment failed
141-
if: ${{ steps.get-deployment-url.outcome == 'failure' }}
142-
run: |
143-
echo "Deployment to staging failed."
144-
exit 1
145-
146-
deploy-to-production:
147-
if: github.event_name == 'push'
148-
name: Deploy to production
149-
runs-on: ubuntu-24.04
150-
needs:
151-
- build
152-
- test-typecheck
153-
steps:
154-
# Checkout repository
155-
- name: Checkout repository
156-
uses: actions/checkout@v5
157-
158-
# Setup, and download artifact
159-
- uses: ./.github/actions/pre-deploy
160-
with:
161-
artifact-name: ${{ env.ARTIFACT_NAME }}
162-
unpack-path: ${{ env.ARTIFACT_PATH }}
163-
164-
# Deploy to Cloudflare Workers
165-
- name: Deploy to production
166-
id: deploy-production
167-
env:
168-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
169-
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
170-
run: |
171-
pnpm run deploy:production
23+
deploy:
24+
uses: Perdolique/.github/.github/workflows/deploy.yml@master
25+
secrets:
26+
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
27+
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"oxc.oxc-vscode",
1717
"pflannery.vscode-versionlens",
1818
"ritwickdey.LiveServer",
19-
"VisualStudioExptTeam.vscodeintellicode",
2019
"vitest.explorer",
2120
"vscode-icons-team.vscode-icons",
2221
"vsls-contrib.gistfs",

0 commit comments

Comments
 (0)