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