7
7
workflow_dispatch : # Allows manual triggering of the workflow
8
8
9
9
jobs :
10
- update-dns :
10
+ update-mta-sts :
11
11
runs-on : ubuntu-latest
12
12
13
13
steps :
@@ -20,19 +20,34 @@ jobs:
20
20
curl -s -X GET \
21
21
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
22
22
-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
24
25
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
25
30
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
27
39
run : |
28
40
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
30
41
curl -s -X PUT \
31
42
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \
32
43
-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 '{
34
46
"type": "TXT",
35
- "name": "_mta-sts.${{ vars .DOMAIN }}",
47
+ "name": "_mta-sts.${{ secrets .DOMAIN }}",
36
48
"content": "v=STSv1; id='"$NEW_ID"'"
37
49
}'
38
50
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