Skip to content

Commit

Permalink
Implement vercel rest API
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasgrastein committed Jan 15, 2025
1 parent 0d6e962 commit 4b60889
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 77 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ jobs:
id: test-action
uses: ./
with:
milliseconds: 2000

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
env-vars: |
ENV1=VALUE1
ENV2=VALUE2
7 changes: 0 additions & 7 deletions CODEOWNERS

This file was deleted.

33 changes: 18 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
name: The name of your action here
description: Provide a description here
author: Your name or organization here
name: Vercel Env Upsert
description: Upsert env vars to Vercel
author: thomasgrastein

# Add your action's branding here. This will appear on the GitHub Marketplace.
branding:
icon: heart
color: red
icon: anchor
color: gray-dark

# Define your inputs here.
inputs:
milliseconds:
description: Your input description here
VARS:
required: true
default: '1000'

# Define your outputs here.
outputs:
time:
description: Your output description here
description: Supports several
VERCEL_TOKEN:
required: true
VERCEL_ORG_ID:
required: true
VERCEL_PROJECT_ID:
required: true
TYPE:
default: 'plain'
TARGET:
default: 'preview'
GIT_BRANCH:

runs:
using: node20
Expand Down
65 changes: 42 additions & 23 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

62 changes: 49 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
import * as core from '@actions/core'
import { wait } from './wait.js'

/**
* The main function for the action.
*
* @returns Resolves when the action is complete.
*/

// await fetch("https://api.vercel.com/v10/projects/prj_XLKmu1DyR1eY7zq8UgeRKbA7yVLA/env?slug=SOME_STRING_VALUE&teamId=SOME_STRING_VALUE&upsert=true", {
// "body": {
// "key": "API_URL",
// "value": "https://api.vercel.com",
// "type": "plain",
// "target": [
// "preview"
// ],
// "gitBranch": "feature-1",
// "comment": "database connection string for production"
// },
// "headers": {
// "Authorization": "Bearer <TOKEN>"
// },
// "method": "post"
// })
export async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')

// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
core.debug(`Waiting ${ms} milliseconds ...`)

// Log the current timestamp, wait, then log the new timestamp
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())

// Set outputs for other workflow steps to use
core.setOutput('time', new Date().toTimeString())
const envVars = core.getMultilineInput('VARS', {
required: true
})
const type = core.getInput('TYPE')
const target = core.getInput('TARGET').split(',')
const gitBranch = core.getInput('GIT_BRANCH')
const body = [
envVars.map((envVar) => ({
key: envVar.split('=')[0],
value: envVar.split('=')[1],
type,
target,
...(gitBranch ? { gitBranch } : {})
}))
]
await fetch(
`https://api.vercel.com/v10/projects/${core.getInput(
'VERCEL_PROJECT_ID',
{
required: true
}
)}/env?teamId=${core.getInput('VERCEL_ORG_ID', { required: true })}&upsert=true`,
{
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${core.getInput('VERCEL_TOKEN', { required: true })}`,
'Content-Type': 'application/json'
},
method: 'post'
}
)
core.info('Environment variables upserted successfully')
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down
13 changes: 0 additions & 13 deletions src/wait.ts

This file was deleted.

0 comments on commit 4b60889

Please sign in to comment.