|
| 1 | +name: 'DNSLink Action' |
| 2 | +description: 'Updates the DNSLink DNS record for a given domain' |
| 3 | +branding: |
| 4 | + icon: 'box' |
| 5 | + color: 'blue' |
| 6 | + |
| 7 | +inputs: |
| 8 | + cid: |
| 9 | + description: 'CID to update the DNSLink value to' |
| 10 | + required: true |
| 11 | + dnslink_domain: |
| 12 | + description: 'Domain to update the DNSLink for e.g. if you set docs.ipfs.tech, the _dnslink.docs.ipfs.tech TXT record will be updated' |
| 13 | + required: true |
| 14 | + cf_record_id: |
| 15 | + description: 'Cloudflare Record ID' |
| 16 | + required: false |
| 17 | + cf_zone_id: |
| 18 | + description: 'Cloudflare Zone ID' |
| 19 | + required: false |
| 20 | + cf_auth_token: |
| 21 | + description: 'Cloudflare API token' |
| 22 | + required: false |
| 23 | + dnsimple_token: |
| 24 | + description: 'DNSimple API token' |
| 25 | + required: false |
| 26 | + dnsimple_account_id: |
| 27 | + description: 'DNSimple account ID' |
| 28 | + required: false |
| 29 | + set_github_status: |
| 30 | + description: 'Set the GitHub commit status with the DNSLink domain and CID' |
| 31 | + default: 'false' |
| 32 | + required: false |
| 33 | + github_token: |
| 34 | + description: 'GitHub token' |
| 35 | + required: false |
| 36 | + |
| 37 | +outputs: |
| 38 | + dnslink_domain: |
| 39 | + description: 'The domain that was updated' |
| 40 | + value: ${{ inputs.dnslink_domain }} |
| 41 | + dnslink_cid: |
| 42 | + description: 'The CID that was set' |
| 43 | + value: ${{ inputs.cid }} |
| 44 | + |
| 45 | +runs: |
| 46 | + using: 'composite' |
| 47 | + steps: |
| 48 | + - name: Validate action inputs |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + if [[ -z "${{ inputs.dnsimple_token }}" || -z "${{ inputs.dnsimple_account_id }}" ]] && [[ -z "${{ inputs.cf_auth_token }}" || -z "${{ inputs.cf_zone_id }}" || -z "${{ inputs.cf_record_id }}" ]]; then |
| 52 | + echo "::error::DNSimple credentials (`dnsimple_token` and `dnsimple_account_id`) or Cloudflare credentials (`cf_auth_token`, `cf_zone_id`, and `cf_record_id`) must be configured" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Set up Go |
| 57 | + if: inputs.dnsimple_token != '' |
| 58 | + uses: actions/setup-go@v4 |
| 59 | + with: |
| 60 | + go-version: '1.23' |
| 61 | + |
| 62 | + - name: Install dnslink-dnsimple |
| 63 | + if: inputs.dnsimple_token != '' |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + go install github.com/ipfs/dnslink-dnsimple@latest |
| 67 | +
|
| 68 | + - name: Update DNSLink in DNSimple |
| 69 | + if: inputs.dnsimple_token != '' |
| 70 | + shell: bash |
| 71 | + env: |
| 72 | + DNSIMPLE_TOKEN: ${{ inputs.dnsimple_token }} |
| 73 | + DNSIMPLE_ACCOUNT_ID: ${{ inputs.dnsimple_account_id }} |
| 74 | + DNSLINK_DOMAIN: ${{ inputs.dnslink_domain }} |
| 75 | + DNSLINK_CID: ${{ inputs.cid }} |
| 76 | + run: | |
| 77 | + if [ -z "${DNSLINK_DOMAIN}" ]; then |
| 78 | + echo "Error: dnslink_domain is empty. Skipping DNSLink update." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + if [ -z "${DNSLINK_CID}" ]; then |
| 82 | + echo "Error: CID is empty. Skipping DNSLink update." |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + echo "Updating DNSLink in DNSimple for: ${DNSLINK_DOMAIN}" |
| 87 | + dnslink-dnsimple \ |
| 88 | + -domain "${DNSLINK_DOMAIN}" \ |
| 89 | + -record "_dnslink" \ |
| 90 | + -link "/ipfs/${DNSLINK_CID}" \ |
| 91 | + -token "${DNSIMPLE_TOKEN}" \ |
| 92 | + -account "${DNSIMPLE_ACCOUNT_ID}" |
| 93 | +
|
| 94 | + - name: Update DNSLink in Cloudflare |
| 95 | + if: inputs.cf_auth_token != '' |
| 96 | + shell: bash |
| 97 | + env: |
| 98 | + DNSLINK_DOMAIN: ${{ inputs.dnslink_domain }} |
| 99 | + DNSLINK_CID: ${{ inputs.cid }} |
| 100 | + CF_ZONE_ID: ${{ inputs.cf_zone_id }} |
| 101 | + CF_RECORD_ID: ${{ inputs.cf_record_id }} |
| 102 | + CF_AUTH_TOKEN: ${{ inputs.cf_auth_token }} |
| 103 | + run: | |
| 104 | + if [ -z "${DNSLINK_DOMAIN}" ]; then |
| 105 | + echo "Error: dnslink_domain is empty. Skipping DNSLink update." |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | + if [ -z "${DNSLINK_CID}" ]; then |
| 109 | + echo "Error: CID is empty. Skipping DNSLink update." |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | +
|
| 113 | + echo "Updating DNSLink for: ${DNSLINK_DOMAIN}" |
| 114 | + curl --request PUT \ |
| 115 | + --header "Authorization: Bearer ${CF_AUTH_TOKEN}" \ |
| 116 | + --header 'Content-Type: application/json' \ |
| 117 | + --url "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/dns_records/${CF_RECORD_ID}" \ |
| 118 | + --data "{ |
| 119 | + \"type\": \"TXT\", |
| 120 | + \"name\": \"_dnslink.${DNSLINK_DOMAIN}\", |
| 121 | + \"content\": \"dnslink=/ipfs/${DNSLINK_CID}\", |
| 122 | + \"comment\": \"${{ github.repository }}/${{ github.sha }}\" |
| 123 | + }" |
| 124 | +
|
| 125 | + - name: Set GitHub commit status |
| 126 | + if: ${{ inputs.set_github_status }} |
| 127 | + uses: actions/github-script@v7 |
| 128 | + with: |
| 129 | + github-token: ${{ inputs.github_token }} |
| 130 | + script: | |
| 131 | + const cid = '${{ inputs.cid }}'; |
| 132 | +
|
| 133 | + // For PR events, we need to use the head SHA |
| 134 | + const sha = context.eventName === 'pull_request' |
| 135 | + ? context.payload.pull_request.head.sha |
| 136 | + : context.sha; |
| 137 | +
|
| 138 | + await github.rest.repos.createCommitStatus({ |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + sha: sha, |
| 142 | + state: 'success', |
| 143 | + description: `${{ inputs.dnslink_domain }} -> ${{ inputs.cid }}`, |
| 144 | + context: 'DNSLink' |
| 145 | + }); |
0 commit comments