Skip to content

Commit ce06804

Browse files
committed
Added ability to show dry-run plan in PR.
1 parent 12b2518 commit ce06804

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.github/workflows/domain-plan.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
on:
2+
pull_request_target:
3+
defaults:
4+
run:
5+
shell: bash
6+
jobs:
7+
test-and-comment:
8+
runs-on: ubuntu-20.04
9+
steps:
10+
- name: Checkout main
11+
uses: actions/checkout@v2
12+
- name: Checkout config files from PR
13+
id: prhead
14+
run: |
15+
# Set $_sha to the first 7 char of PR head SHA
16+
_sha="$(echo "${{ github.event.pull_request.head.sha }}" | cut -c 1-7)"
17+
# Fetch PR head commit
18+
git fetch origin refs/pull/${{ github.event.pull_request.number }}/head
19+
# List changed config files in PR head
20+
_files="$(git diff --name-only HEAD $_sha | grep "\.yaml$")"
21+
# Checkout config files from PR head commit
22+
if [ -n "$_files" ]; then git checkout "$_sha" -- $_files; fi
23+
# Set output 'sha' to $_sha
24+
echo "::set-output name=sha::${_sha}"
25+
- name: Test changes to DNS config
26+
id: octodns-sync
27+
uses: solvaholic/octodns-sync@main
28+
with:
29+
config_path: config.yaml
30+
- name: Get plan output
31+
id: plan
32+
run: |
33+
# Parse plan output into $_plan
34+
_plan="$(cat ${GITHUB_WORKSPACE}/octodns-sync.plan)"
35+
_plan="${_plan//'%'/'%25'}"
36+
_plan="${_plan//$'\n'/'%0A'}"
37+
_plan="${_plan//$'\r'/'%0D'}"
38+
# Set output 'plan' to $_plan
39+
echo "::set-output name=plan::${_plan}"
40+
- name: Find Comment
41+
uses: peter-evans/find-comment@v1
42+
id: find-comment
43+
with:
44+
issue-number: ${{ github.event.pull_request.number }}
45+
comment-author: 'github-actions[bot]'
46+
body-includes: Automatically generated by octodns-sync
47+
- name: Add or update PR comment
48+
if: ${{ github.event_name != 'workflow_dispatch' }}
49+
uses: peter-evans/create-or-update-comment@v1
50+
with:
51+
issue-number: ${{ github.event.pull_request.number }}
52+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
53+
body: |
54+
## OctoDNS Plan for `${{ steps.prhead.outputs.sha }}`
55+
${{ steps.plan.outputs.plan }}
56+
Automatically generated by octodns-sync
57+
edit-mode: replace

.github/workflows/domain-sync.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/checkout@v2
2222

2323
- name: Publish
24-
uses: solvaholic/octodns-sync@v2.1.2
24+
uses: solvaholic/octodns-sync@main
2525
with:
2626
config_path: config.yaml
2727
doit: '--doit'

0 commit comments

Comments
 (0)