Skip to content

Commit b83c0c4

Browse files
authored
Update update-mta-sts-record.yml
1 parent 2287117 commit b83c0c4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.github/workflows/update-mta-sts-record.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch: # Allows manual triggering of the workflow
88

99
jobs:
10-
update-dns:
10+
update-mta-sts:
1111
runs-on: ubuntu-latest
1212

1313
steps:
@@ -20,19 +20,34 @@ jobs:
2020
curl -s -X GET \
2121
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
2222
-H "Content-Type: application/json" \
23-
"https://api.cloudflare.com/client/v4/zones/${{ secrets.ZONE_ID }}/dns_records?type=TXT&name=_mta-sts.${{ secrets.DOMAIN }}" \ > dns_record.json
23+
"https://api.cloudflare.com/client/v4/zones/${{ secrets.ZONE_ID }}/dns_records?type=TXT&name=_mta-sts.${{ secrets.DOMAIN }}" \
24+
> dns_record.json
2425
cat dns_record.json
26+
if [ $(jq '.result | length' dns_record.json) -eq 0 ]; then
27+
echo "No DNS record found for _mta-sts.${{ secrets.DOMAIN }}. Exiting."
28+
exit 1
29+
fi
2530
26-
- name: Update DNS record with new id
31+
- name: Extract Record ID
32+
id: extract_id
33+
run: |
34+
RECORD_ID=$(jq -r '.result[0].id' dns_record.json)
35+
echo "Record ID: $RECORD_ID"
36+
echo "RECORD_ID=$RECORD_ID" >> $GITHUB_ENV
37+
38+
- name: Update DNS record
2739
run: |
2840
NEW_ID=$(date +'%Y%m%d%H%M%S') # Generate a unique ID
29-
RECORD_ID=$(jq -r '.result[0].id' dns_record.json) # Extract the record ID
3041
curl -s -X PUT \
3142
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
3243
-H "Content-Type: application/json" \
33-
"https://api.cloudflare.com/client/v4/zones/${{ vars.ZONE_ID }}/dns_records?type=TXT&name=_mta-sts.${{ vars.DOMAIN }}" \ --data '{
44+
"https://api.cloudflare.com/client/v4/zones/${{ secrets.ZONE_ID }}/dns_records/${{ env.RECORD_ID }}" \
45+
--data '{
3446
"type": "TXT",
35-
"name": "_mta-sts.${{ vars.DOMAIN }}",
47+
"name": "_mta-sts.${{ secrets.DOMAIN }}",
3648
"content": "v=STSv1; id='"$NEW_ID"'"
3749
}'
3850
echo "Updated _mta-sts record with id: $NEW_ID"
51+
52+
- name: Log success
53+
run: echo "DNS record updated successfully for _mta-sts.${{ secrets.DOMAIN }}"

0 commit comments

Comments
 (0)