ci: fix DNSLink CID #60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy to IPFS | |
# Explicitly declare permissions | |
permissions: | |
contents: read | |
pull-requests: write | |
statuses: write | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true # Cancel in progress runs if a new run is started | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
outputs: | |
cid: ${{ steps.deploy.outputs.cid }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build project | |
run: npm run build | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-output | |
path: out | |
- uses: ipfs/[email protected] | |
name: Deploy to IPFS | |
id: deploy | |
with: | |
path-to-deploy: out | |
storacha-key: ${{ secrets.STORACHA_KEY }} | |
storacha-proof: ${{ secrets.STORACHA_PROOF }} | |
pinata-jwt-token: ${{ secrets.PINATA_JWT_TOKEN }} | |
github-token: ${{ github.token }} | |
update-dnslink: | |
runs-on: 'ubuntu-latest' | |
needs: build-and-deploy | |
if: github.ref == 'refs/heads/main' # only update DNSLink for main branch | |
steps: | |
- name: Update DNSLink | |
run: | | |
if [ -z "${{ env.DNSLINK_NAME }}" ]; then | |
echo "Error: DNSLINK_NAME is empty. Skipping DNSLink update." | |
exit 1 | |
fi | |
if [ -z "${{ env.DNSLINK_CID }}" ]; then | |
echo "Error: DNSLINK_CID is empty. Skipping DNSLink update." | |
exit 1 | |
fi | |
echo "Updating DNSLink for: ${{ env.DNSLINK_NAME }}" | |
curl --request PUT \ | |
--header "Authorization: Bearer ${AUTH_TOKEN}" \ | |
--header 'Content-Type: application/json' \ | |
--url "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \ | |
--data "{ | |
\"type\": \"TXT\", | |
\"name\": \"_dnslink.${{ env.DNSLINK_NAME }}\", | |
\"content\": \"dnslink=/ipfs/${{ env.DNSLINK_CID }}\", | |
\"comment\": \"${{ github.repository }}/${{ github.sha }}\" | |
}" | |
env: | |
DNSLINK_NAME: 'ipns.ipfs.network' | |
DNSLINK_CID: ${{ needs.build-and-deploy.outputs.cid }} | |
ZONE_ID: ${{ secrets.CF_IPNS_NETWORK_ZONE_ID }} | |
RECORD_ID: ${{ secrets.CF_IPNS_NETWORK_RECORD_ID }} | |
AUTH_TOKEN: ${{ secrets.CF_IPNS_NETWORK_AUTH_TOKEN }} |