Skip to content

Commit 85149e3

Browse files
Setup GitHub actions
1 parent 9961e2f commit 85149e3

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Deploy
2+
on:
3+
push:
4+
branches: [main]
5+
jobs:
6+
build:
7+
name: Deploy DNS changes
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: Deploy
12+
run: |
13+
docker run --rm -v "$(pwd):/dns" --env CLOUDFLARE_ACCOUNT_ID --env CLOUDFLARE_API_TOKEN ghcr.io/stackexchange/dnscontrol:4.18.0 push
14+
env:
15+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
16+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_WRITE }}

.github/workflows/pr.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Preview
2+
on:
3+
pull_request_target:
4+
types: [opened, reopened, synchronize]
5+
jobs:
6+
build:
7+
name: Preview
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v4
11+
# SECURITY: We are checking out dnsconfig.js and creds.json from the PR.
12+
# These two files cannot perform I/O, and cannot thus be used to leak
13+
# the secret tokens. As a second layer of security, for this job we use
14+
# a Cloudflare API token with read-only permissions.
15+
- name: Checkout config from PR
16+
run: |
17+
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head
18+
git checkout FETCH_HEAD -- dnsconfig.js
19+
- name: Generate preview
20+
id: preview
21+
run: |
22+
{
23+
echo "dnscontrol<<DNS_CONTROL_PREVIEW_OUTPUT"
24+
docker run --rm -v "$(pwd):/dns" --env CLOUDFLARE_ACCOUNT_ID --env CLOUDFLARE_API_TOKEN ghcr.io/stackexchange/dnscontrol:4.18.0 preview
25+
echo "DNS_CONTROL_PREVIEW_OUTPUT"
26+
} | tee -a $GITHUB_OUTPUT
27+
env:
28+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
29+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_READ_ONLY }}
30+
- name: Create comment
31+
uses: babel/actions/create-comment@v2
32+
with:
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
issue: ${{ github.event.pull_request.number }}
35+
comment: |
36+
Preview output:
37+
```
38+
${{ steps.preview.outputs.dnscontrol }}
39+
```

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ This is only needed when upgrading DNSControl.
3535
docker run --rm -it -v "$(pwd):/dns" ghcr.io/stackexchange/dnscontrol:4.18.0 write-types
3636
```
3737

38+
## Contributing flow
39+
40+
All changes to this repository must be made through pull requests. When opening a pull request, GitHub Actions will generate a previw of the DNS changes and post is as a comment.
41+
42+
## Copying this repository for your organization
43+
44+
Feel free to fork this repository in your own organization! Here is the recommended setup:
45+
- Babel's DNS is managed through Cloudflare:
46+
- if you also use Cloudflare, you can copy the GitHub Actions workflows as-is. You will need to provide the following secrets: `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN_WRITE` (with the permissions described in the [DNSControl documentation](https://docs.dnscontrol.org/provider/cloudflareapi#api-tokens-recommended)), `CLOUDFLARE_API_TONEN_READ_ONLY` (same as `CLOUDFLARE_API_TOKEN_WRITE`, but will all permissions set to "Read").
47+
- if you use any other provider, check on the DNSControl documentation how to configure it and update the GitHub Actions workflow to pass the correct environment variables to the Docker container.
48+
- In the GitHub repository [settings for for branches](https://github.com/babel/dns/settings/branches), create a rule for the `main` branch with the following restrictions:
49+
- Require linear history
50+
- Require a pull request before merging
51+
- Require status checks to pass
52+
- Require branches to be up to date before merging
53+
- Select the "Preview" check as required

0 commit comments

Comments
 (0)