Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit ec182e5

Browse files
committed
Initial commit
0 parents  commit ec182e5

4 files changed

Lines changed: 133 additions & 0 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2020-present Kriasoft
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Create DNS Record Action for GitHub
2+
3+
Creates a new CloudFlare DNS record.
4+
5+
## Usage
6+
7+
```yaml
8+
name: example
9+
on:
10+
pull_request:
11+
type: [opened, reopened]
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: kriasoft/create-dns-record@v1
17+
with:
18+
type: "CNAME"
19+
name: "{PR}-review.example.com"
20+
content: "example.com"
21+
ttl: 1
22+
proxied: true
23+
token: ${{ secrets.CLOUDFLARE_TOKEN }}
24+
zone: ${{ secrets.CLOUDFLARE_ZONE }}
25+
```
26+
27+
## License
28+
29+
The scripts and documentation in this project are released under the [MIT License](LICENSE).

action.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Create DNS Record"
2+
description: "Creates a new CloudFlare DNS record"
3+
author: "Kriasoft"
4+
5+
inputs:
6+
type:
7+
description: 'DNS record type, e.g. "A", "CNAME", etc.'
8+
required: true
9+
name:
10+
description: 'DNS record name, e.g. "{PR_NUMBER}.example.com"'
11+
required: true
12+
content:
13+
description: 'DNS record content, e.g. "127.0.0.1"'
14+
ttl:
15+
description: "Time to live for DNS record. Value of 1 is 'automatic'"
16+
default: 1
17+
proxied:
18+
description: "Whether the record is receiving the performance and security benefits of Cloudflare"
19+
default: true
20+
token:
21+
description: "CloudFlare API token"
22+
default: ${{ secrets.CLOUDFLARE_TOKEN }}
23+
required: true
24+
zone:
25+
default: "CloudFlare zone"
26+
default: ${{ secrets.CLOUDFLARE_ZONE }}
27+
required: true
28+
29+
outputs:
30+
id:
31+
name:
32+
33+
runs:
34+
using: "node12"
35+
main: "main.js"
36+
37+
branding:
38+
icon: "at-sign"
39+
color: "orange"

main.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Create DNS Record Action for GitHub
3+
* https://github.com/marketplace/actions/create-dns-record
4+
*/
5+
6+
const path = require("path");
7+
const cp = require("child_process");
8+
9+
const event = require(process.env.GITHUB_EVENT_PATH);
10+
const pr = event.pull_request ? event.pull_request.number : "?";
11+
12+
// https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
13+
const result = cp.spawnSync("curl", [
14+
...["--request", "POST"],
15+
...["--header", `Authorization: Bearer ${process.env.INPUT_TOKEN}`],
16+
...["--header", "Content-Type: application/json"],
17+
...["--silent", "--data"],
18+
JSON.stringify({
19+
type: process.env.INPUT_TYPE,
20+
name: process.env.INPUT_NAME.replace(/\{pr\}/gi, pr)
21+
.replace(/\{pr_number\}/gi, pr)
22+
.replace(/\{head_ref\}/gi, process.env.GITHUB_HEAD_REF),
23+
content: process.env.INPUT_CONTENT,
24+
ttl: Number(process.env.INPUT_TTL),
25+
proxied: Boolean(process.env.INPUT_PROXIED),
26+
}),
27+
`https://api.cloudflare.com/client/v4/zones/${process.env.INPUT_ZONE}/dns_records`,
28+
]);
29+
30+
if (result.status !== 0) {
31+
process.exit(result.status);
32+
}
33+
34+
const { success, result, errors } = JSON.parse(result.stdout.toString());
35+
36+
if (!success) {
37+
console.dir(errors[0]);
38+
console.log(`::error ::${errors[0].message}`);
39+
process.exit(1);
40+
}
41+
42+
console.dir(result);
43+
console.log(`::set-output name=id::${result.id}`);
44+
console.log(`::set-output name=name::${result.name}`);

0 commit comments

Comments
 (0)