Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
7d678196
Unverified
Commit
7d678196
authored
May 26, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(release): Add an action to replace Vercel DNS records
parent
7b9b332c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
176 additions
and
2 deletions
+176
-2
.eslintrc.json
.eslintrc.json
+2
-1
release.yaml
.github/workflows/release.yaml
+8
-1
action.yml
actions/replace-vercel-dns-record/action.yml
+24
-0
index.js
actions/replace-vercel-dns-record/index.js
+14
-0
package.json
actions/replace-vercel-dns-record/package.json
+7
-0
replace-domain.js
actions/replace-vercel-dns-record/replace-domain.js
+108
-0
yarn.lock
actions/replace-vercel-dns-record/yarn.lock
+13
-0
No files found.
.eslintrc.json
View file @
7d678196
...
...
@@ -9,7 +9,8 @@
}
},
"ignorePatterns"
:
[
"node_modules/**/*"
"node_modules/**/*"
,
"actions/**/*"
],
"settings"
:
{
"react"
:
{
...
...
.github/workflows/release.yaml
View file @
7d678196
...
...
@@ -46,7 +46,14 @@ jobs:
-
name
:
Update DNS with new IPFS hash
id
:
update_dns
run
:
npx vercel --token ${{ secrets.VERCEL_TOKEN }} --scope uniswap dns add uniswap.org _dnslink.app TXT "dnslink=/ipfs/${{ steps.upload.outputs.hash }}"
uses
:
./actions/replace-vercel-dns-record
with
:
domain
:
'
uniswap.org'
subdomain
:
'
_dnslink.app'
record-type
:
'
TXT'
value
:
/ipfs/${{ steps.upload.outputs.hash }}
token
:
${{ secrets.VERCEL_TOKEN }}
team-name
:
'
uniswap'
-
name
:
Create GitHub Release
id
:
create_release
...
...
actions/replace-vercel-dns-record/action.yml
0 → 100644
View file @
7d678196
name
:
'
Replace
Vercel
DNS
Record'
description
:
'
Replace
a
Vercel
DNS
record
by
adding
one
record
and
deleting
all
others'
inputs
:
domain
:
description
:
'
The
vercel
domain'
required
:
true
subdomain
:
description
:
'
The
vercel
subdomain
to
replace
records
for'
required
:
true
record-type
:
description
:
'
The
record
type
to
replace'
required
:
true
value
:
description
:
'
The
new
value
for
the
subdomain/record
type
combo'
required
:
true
token
:
description
:
'
The
Vercel
authentication
token'
required
:
true
team-name
:
description
:
'
The
name
of
the
team
that
controls
the
domain,
e.g.
Uniswap'
required
:
true
runs
:
using
:
'
node12'
main
:
'
index.js'
\ No newline at end of file
actions/replace-vercel-dns-record/index.js
0 → 100644
View file @
7d678196
const
core
=
require
(
'
@actions/core
'
)
const
replaceDomain
=
require
(
'
./replace-domain
'
)
replaceDomain
({
teamName
:
core
.
getInput
(
'
team-name
'
),
token
:
core
.
getInput
(
'
token
'
),
recordType
:
core
.
getInput
(
'
record-type
'
),
domain
:
core
.
getInput
(
'
domain
'
),
subdomain
:
core
.
getInput
(
'
subdomain
'
),
value
:
core
.
getInput
(
'
value
'
),
})
.
catch
(
error
=>
{
core
.
setFailed
(
error
)
})
\ No newline at end of file
actions/replace-vercel-dns-record/package.json
0 → 100644
View file @
7d678196
{
"main"
:
"index.js"
,
"dependencies"
:
{
"@actions/core"
:
"^1.2.4"
,
"node-fetch"
:
"^2.6.0"
}
}
actions/replace-vercel-dns-record/replace-domain.js
0 → 100644
View file @
7d678196
const
fetch
=
require
(
'
node-fetch
'
)
function
checkStatusAndParseResponse
(
res
)
{
if
(
res
.
status
<
200
||
res
.
status
>=
300
)
{
return
res
.
json
()
.
then
(
({
error
:
{
code
,
message
}
})
=>
{
throw
new
Error
(
`Response error code
${
code
}
:
${
message
}
`
)
},
)
.
catch
(
error
=>
{
throw
new
Error
(
`Response status received without JSON error body:
${
res
.
status
}
;
${
error
.
message
}
`
)
})
}
if
(
res
.
status
===
204
)
return
''
return
res
.
text
()
.
then
(
text
=>
{
try
{
return
JSON
.
parse
(
text
)
}
catch
(
error
)
{
console
.
warn
(
`Invalid json response:
${
error
.
message
}
`
)
return
''
}
})
}
function
authorizedFetchAndParse
(
urlPath
,
token
,
options
)
{
return
fetch
(
`https://api.vercel.com
${
urlPath
}
`
,
{
...
options
,
headers
:
{
...(
options
&&
options
.
headers
),
Authorization
:
`Bearer
${
token
}
`
,
},
}).
then
(
checkStatusAndParseResponse
)
}
function
getTeamId
({
teamName
,
token
})
{
return
authorizedFetchAndParse
(
'
/v1/teams
'
,
token
)
.
then
(({
teams
})
=>
teams
.
filter
(({
name
,
slug
})
=>
slug
.
toLowerCase
()
===
teamName
||
name
.
toLowerCase
()
===
teamName
))
.
then
(
teams
=>
{
if
(
teams
.
length
===
1
)
return
teams
[
0
]
if
(
teams
.
length
>
1
)
{
throw
new
Error
(
'
team name matched more than 1 team
'
)
}
else
{
throw
new
Error
(
'
team name did not match any team
'
)
}
})
.
then
(
team
=>
team
.
id
)
}
function
getExistingRecords
({
domain
,
subdomain
,
recordType
,
teamId
,
token
})
{
// GET /v4/domains/:domain/records
return
authorizedFetchAndParse
(
`/v4/domains/
${
domain
}
/records?limit=10000&teamId=
${
teamId
}
`
,
token
)
.
then
(
({
records
})
=>
records
.
filter
(({
type
,
name
})
=>
type
.
toLowerCase
()
===
recordType
.
toLowerCase
()
&&
name
.
toLowerCase
()
===
subdomain
.
toLowerCase
()),
)
.
then
(
records
=>
records
.
map
(
record
=>
record
.
id
))
}
function
createRecord
({
domain
,
subdomain
,
recordType
,
value
,
teamId
,
token
})
{
return
authorizedFetchAndParse
(
`/v2/domains/
${
domain
}
/records?teamId=
${
teamId
}
`
,
token
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
({
name
:
subdomain
,
type
:
recordType
,
value
,
}),
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
})
.
then
(({
uid
})
=>
uid
)
}
function
deleteRecord
({
domain
,
recordId
,
teamId
,
token
})
{
return
authorizedFetchAndParse
(
`/v2/domains/
${
domain
}
/records/
${
recordId
}
?teamId=
${
teamId
}
`
,
token
,
{
method
:
'
DELETE
'
,
})
}
module
.
exports
=
async
function
replaceDomain
({
domain
,
subdomain
,
recordType
,
token
,
teamName
,
value
})
{
const
teamId
=
await
getTeamId
({
teamName
,
token
})
const
recordsToDelete
=
await
getExistingRecords
({
domain
,
subdomain
,
recordType
,
teamId
,
token
})
const
createdUid
=
await
createRecord
({
domain
,
subdomain
,
recordType
,
teamId
,
token
,
value
})
if
(
recordsToDelete
.
indexOf
(
createdUid
)
!==
-
1
)
{
console
.
log
(
'
Record already exists, create was idempotent
'
)
}
else
{
console
.
log
(
`Created record with uid
${
createdUid
}
, deleting others`
)
}
const
filteredToDelete
=
recordsToDelete
.
filter
(
recordId
=>
recordId
!==
createdUid
)
if
(
filteredToDelete
.
length
>
0
)
{
console
.
log
(
`Deleting records:
${
filteredToDelete
.
join
(
'
,
'
)}
`
)
await
Promise
.
all
(
filteredToDelete
.
map
(
recordId
=>
deleteRecord
({
domain
,
recordId
,
token
,
teamId
})),
)
console
.
log
(
'
Deleted records. Updated completed.
'
)
}
else
{
console
.
log
(
'
No records to delete. Update completed.
'
)
}
}
\ No newline at end of file
actions/replace-vercel-dns-record/yarn.lock
0 → 100644
View file @
7d678196
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@actions/core@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.4.tgz#96179dbf9f8d951dd74b40a0dbd5c22555d186ab"
integrity sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==
node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment