Skip to content

Commit e74e558

Browse files
committed
feat: add GitHub Actions workflow for uploading files to Vercel Blob
- Implemented a comprehensive workflow to upload static files, build artifacts, and conditionally upload files based on user input. - Included error handling for uploads and created sample files for testing. - Enhanced the process with clear steps for checking file existence and handling upload results.
1 parent b4e57d2 commit e74e558

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Upload Files to Vercel Blob
2+
3+
on: [push]
4+
5+
jobs:
6+
upload-static-files:
7+
runs-on: ubuntu-latest
8+
name: Upload static files to Vercel Blob
9+
steps:
10+
- name: Checkout repository
11+
uses: actions/checkout@v4
12+
13+
- name: Create sample files
14+
run: |
15+
mkdir -p dist
16+
echo "Hello from GitHub Actions!" > dist/hello.txt
17+
echo "Build timestamp: $(date)" > dist/build-info.txt
18+
echo '{"version": "1.0.0", "build": "'$(date -u +%Y%m%d%H%M%S)'"}' > dist/metadata.json
19+
20+
- name: Upload hello.txt to Vercel Blob
21+
uses: ./
22+
with:
23+
source: "dist/hello.txt"
24+
destination: "uploads/hello.txt"
25+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
26+
27+
- name: Upload build info with timestamp
28+
uses: ./
29+
with:
30+
source: "dist/build-info.txt"
31+
destination: "builds/build-${{ github.sha }}.txt"
32+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
33+
34+
- name: Upload metadata JSON
35+
uses: ./
36+
with:
37+
source: "dist/metadata.json"
38+
destination: "metadata/build-${{ github.run_number }}.json"
39+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
40+
41+
upload-build-artifacts:
42+
runs-on: ubuntu-latest
43+
name: Build and upload artifacts
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: "20"
52+
cache: "npm"
53+
54+
- name: Install dependencies
55+
run: npm ci
56+
57+
- name: Build project
58+
run: |
59+
# Simulate a build process
60+
mkdir -p build
61+
npm run build || echo "No build script found, creating sample build files"
62+
echo "Built application at $(date)" > build/app.txt
63+
echo "Version: ${{ github.sha }}" >> build/app.txt
64+
65+
- name: Upload build artifact
66+
id: upload-build
67+
uses: ./
68+
with:
69+
source: "build/app.txt"
70+
destination: "releases/${{ github.ref_name }}/app-${{ github.sha }}.txt"
71+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
72+
73+
- name: Display upload result
74+
run: |
75+
echo "Build artifact uploaded successfully!"
76+
echo "URL: ${{ steps.upload-build.outputs.url }}"
77+
78+
conditional-upload:
79+
runs-on: ubuntu-latest
80+
name: Conditional file upload
81+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.file_to_upload != ''
82+
steps:
83+
- name: Checkout repository
84+
uses: actions/checkout@v4
85+
86+
- name: Check if file exists
87+
id: check-file
88+
run: |
89+
if [ -f "${{ github.event.inputs.file_to_upload }}" ]; then
90+
echo "file_exists=true" >> $GITHUB_OUTPUT
91+
echo "File exists: ${{ github.event.inputs.file_to_upload }}"
92+
else
93+
echo "file_exists=false" >> $GITHUB_OUTPUT
94+
echo "File not found: ${{ github.event.inputs.file_to_upload }}"
95+
fi
96+
97+
- name: Upload specified file
98+
if: steps.check-file.outputs.file_exists == 'true'
99+
uses: ./
100+
with:
101+
source: ${{ github.event.inputs.file_to_upload }}
102+
destination: "manual-uploads/${{ github.event.inputs.file_to_upload }}"
103+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
104+
105+
upload-with-error-handling:
106+
runs-on: ubuntu-latest
107+
name: Upload with error handling
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
112+
- name: Create test file
113+
run: |
114+
mkdir -p temp
115+
echo "Test file content" > temp/test.txt
116+
117+
- name: Upload with error handling
118+
id: upload-test
119+
continue-on-error: true
120+
uses: ./
121+
with:
122+
source: "temp/test.txt"
123+
destination: "tests/test-${{ github.run_id }}.txt"
124+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
125+
126+
- name: Handle upload result
127+
run: |
128+
if [ "${{ steps.upload-test.outcome }}" == "success" ]; then
129+
echo "✅ Upload successful!"
130+
echo "File URL: ${{ steps.upload-test.outputs.url }}"
131+
else
132+
echo "❌ Upload failed!"
133+
echo "Please check your BLOB_READ_WRITE_TOKEN secret"
134+
fi

0 commit comments

Comments
 (0)