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