Skip to content

Commit b4e57d2

Browse files
committed
chore: update action.yml, README, and package.json for improved clarity and functionality
- Added .gitignore to exclude .cursor files. - Updated action.yml to include a new input for read-write token and improved descriptions for inputs and outputs. - Modified README to clarify usage instructions and added a section for setting up the Vercel Blob token. - Enhanced package.json with a new dependency for @vercel/blob and updated the description for better accuracy.
1 parent b06bf91 commit b4e57d2

5 files changed

Lines changed: 114 additions & 34 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.cursor

README.md

Lines changed: 79 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
# Vercel Blob Action
22

3-
This GitHub Action allows you to interact with the Vercel Blob API by specifying a source and destination path. It is designed to facilitate the management of blobs in your Vercel projects.
3+
This GitHub Action allows you to upload files to Vercel Blob storage by specifying a source file and destination path. It provides an easy way to manage blob storage in your Vercel projects through GitHub Actions workflows.
44

55
## Inputs
66

7-
- `source`: The source path of the blob you want to manage.
8-
- `destination`: The destination path where the blob should be moved or copied.
7+
### `source`
8+
9+
**Required** The source path of the file you want to upload to Vercel Blob storage.
10+
11+
### `destination`
12+
13+
**Required** The destination path where the file should be stored in Vercel Blob storage.
14+
15+
### `read-write-token`
16+
17+
**Required** Your Vercel Blob read-write token (`BLOB_READ_WRITE_TOKEN`). This should be stored as a GitHub secret for security.
18+
19+
## Outputs
20+
21+
### `url`
22+
23+
The URL of the uploaded blob file.
24+
25+
## Environment Variables
26+
27+
This action requires a Vercel Blob read-write token. The action will automatically set the `BLOB_READ_WRITE_TOKEN` environment variable for the Vercel Blob SDK to use. You can obtain this token from your Vercel dashboard:
28+
29+
1. Go to your Vercel dashboard
30+
2. Navigate to Storage → Blob
31+
3. Create or copy your `BLOB_READ_WRITE_TOKEN`
32+
4. Add it as a GitHub secret in your repository
933

1034
## Usage
1135

12-
To use this action in your workflow, you can include it as follows:
36+
To use this action in your workflow, add it as a step in your GitHub Actions workflow file:
1337

1438
```yaml
15-
name: Example Workflow
39+
name: Upload to Vercel Blob
1640

1741
on: [push]
1842

@@ -21,27 +45,65 @@ jobs:
2145
runs-on: ubuntu-latest
2246
steps:
2347
- name: Checkout code
24-
uses: actions/checkout@v2
48+
uses: actions/checkout@v4
2549

26-
- name: Upload Blob
27-
uses: your-username/vercel-blob-action@v1.0.0
50+
- name: Upload file to Vercel Blob
51+
uses: your-username/vercel-blob-action@v1
2852
with:
29-
source: 'path/to/source'
30-
destination: 'path/to/destination'
53+
source: "path/to/your/file.txt"
54+
destination: "uploads/file.txt"
55+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
3156
```
3257
3358
## Example
3459
35-
Here is an example of how to specify the source and destination paths:
60+
Here's a complete example that uploads a build artifact to Vercel Blob storage:
3661
3762
```yaml
38-
- name: Upload Blob
39-
uses: your-username/vercel-blob-action@v1.0.0
40-
with:
41-
source: 'src/myBlob.txt'
42-
destination: 'dest/myBlob.txt'
63+
name: Build and Upload
64+
65+
on:
66+
push:
67+
branches: [main]
68+
69+
jobs:
70+
build-and-upload:
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Checkout code
74+
uses: actions/checkout@v4
75+
76+
- name: Build project
77+
run: |
78+
# Your build commands here
79+
echo "Built file" > dist/output.txt
80+
81+
- name: Upload to Vercel Blob
82+
uses: your-username/vercel-blob-action@v1
83+
with:
84+
source: "dist/output.txt"
85+
destination: "builds/output-${{ github.sha }}.txt"
86+
read-write-token: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
87+
88+
- name: Display blob URL
89+
run: echo "File uploaded to ${{ steps.upload.outputs.url }}"
4390
```
4491
92+
## Setting up the Token
93+
94+
1. **Get your Vercel Blob token:**
95+
96+
- Visit your [Vercel dashboard](https://vercel.com/dashboard)
97+
- Go to Storage → Blob
98+
- Create or copy your `BLOB_READ_WRITE_TOKEN`
99+
100+
2. **Add the token to GitHub Secrets:**
101+
- Go to your GitHub repository
102+
- Navigate to Settings → Secrets and variables → Actions
103+
- Click "New repository secret"
104+
- Name: `BLOB_READ_WRITE_TOKEN`
105+
- Value: Your Vercel Blob token
106+
45107
## License
46108

47-
This project is licensed under the ISC License.
109+
This project is licensed under the ISC License.

action.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
name: 'Vercel Blob Action'
2-
description: 'A GitHub Action to interact with Vercel Blob'
1+
name: "Vercel Blob Action"
2+
description: "A GitHub Action to interact with Vercel Blob storage"
33
inputs:
44
source:
5-
description: 'The source path for the blob'
5+
description: "The source path for the blob file"
66
required: true
77
destination:
8-
description: 'The destination path for the blob'
8+
description: "The destination path for the blob in Vercel Blob storage"
99
required: true
10+
read-write-token:
11+
description: "Vercel Blob read-write token (BLOB_READ_WRITE_TOKEN)"
12+
required: true
13+
outputs:
14+
url:
15+
description: "The URL of the uploaded blob"
1016
runs:
11-
using: 'node12'
12-
main: 'src/index.js'
17+
using: "node20"
18+
main: "src/index.js"
1319
branding:
14-
icon: 'cloud-upload'
15-
color: 'blue'
20+
icon: "cloud-upload"
21+
color: "blue"

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
22
"name": "vercel-blob-action",
33
"version": "1.0.0",
4-
"description": "A GitHub Action for interacting with Vercel Blob storage.",
4+
"description": "A GitHub Action for uploading files to Vercel Blob storage",
55
"main": "src/index.js",
6+
"type": "module",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},
910
"keywords": [
1011
"github-action",
1112
"vercel",
12-
"blob"
13+
"blob",
14+
"storage",
15+
"upload"
1316
],
1417
"author": "",
1518
"license": "ISC",
1619
"dependencies": {
1720
"@actions/core": "^1.10.0",
18-
"@actions/github": "^5.0.0"
21+
"@actions/github": "^5.0.0",
22+
"@vercel/blob": "^0.23.4"
1923
}
2024
}

src/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ async function run() {
66
try {
77
const sourcePath = core.getInput('source', { required: true });
88
const destinationPath = core.getInput('destination', { required: true });
9-
const token = core.getInput('vercelToken', { required: true });
9+
const token = core.getInput('read-write-token', { required: true });
10+
11+
if (!token) {
12+
throw new Error('Vercel Blob read-write token is required. Please set the read-write-token input with your BLOB_READ_WRITE_TOKEN.');
13+
}
1014

1115
if (!fs.existsSync(sourcePath)) {
1216
throw new Error(`Source file does not exist: ${sourcePath}`);
1317
}
1418

19+
core.info(`Uploading file from ${sourcePath} to ${destinationPath}`);
20+
1521
const fileStream = fs.createReadStream(sourcePath);
1622

17-
const result = await put(destinationPath, fileStream, {
18-
token,
19-
});
23+
// Set the token as an environment variable for the Vercel Blob SDK
24+
process.env.BLOB_READ_WRITE_TOKEN = token;
25+
26+
const result = await put(destinationPath, fileStream);
2027

21-
core.info(`File uploaded to ${result.url}`);
28+
core.info(`File uploaded successfully to ${result.url}`);
2229
core.setOutput('url', result.url);
2330
} catch (error) {
24-
core.setFailed(error.message);
31+
core.setFailed(`Action failed: ${error.message}`);
2532
}
2633
}
2734

0 commit comments

Comments
 (0)