feat: build car and pin it to cluster #46
Workflow file for this run
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: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- '**' | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- name: Save ./dist output for later | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist | ||
retention-days: 3 | ||
check: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present lint | ||
- run: npm run --if-present dep-check | ||
- run: npm run --if-present doc-check | ||
test-node: | ||
needs: build | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-latest, ubuntu-latest, macos-latest] | ||
node: [lts/*] | ||
fail-fast: true | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:node | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: node | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-chrome: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:chrome | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: chrome | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-chrome-webworker: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:chrome-webworker | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: chrome-webworker | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-firefox: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:firefox | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: firefox | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-firefox-webworker: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:firefox-webworker | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: firefox-webworker | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-webkit: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npm run --if-present test:webkit | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: webkit | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-electron-main: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npx xvfb-maybe npm run --if-present test:electron-main | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: electron-main | ||
files: .coverage/*,packages/*/.coverage/* | ||
test-electron-renderer: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- uses: ipfs/aegir/actions/cache-node-modules@master | ||
- run: npx xvfb-maybe npm run --if-present test:electron-renderer | ||
- uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # v3.1.5 | ||
with: | ||
flags: electron-renderer | ||
files: .coverage/*,packages/*/.coverage/* | ||
publish-to-ipfs: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: Deploy | ||
# TODO only if: release or main branch | ||
env: | ||
KUBO_VER: 'v0.26.0' # kubo daemon used for publishing to IPFS | ||
CLUSTER_CTL_VER: 'v1.0.8' # ipfs-cluster-ctl used for pinning | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Retrieve ./dist produced by build job | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: dist | ||
path: dist | ||
- uses: ipfs/download-ipfs-distribution-action@v1 | ||
with: | ||
name: kubo | ||
version: "${{ env.KUBO_VER }}" | ||
- uses: ipfs/download-ipfs-distribution-action@v1 | ||
with: | ||
name: ipfs-cluster-ctl | ||
version: "${{ env.CLUSTER_CTL_VER }}" | ||
- name: Init IPFS daemon | ||
run: | | ||
# fix resolv - DNS provided by Github is unreliable for DNSLik/dnsaddr | ||
sudo sed -i -e 's/nameserver 127.0.0.*/nameserver 1.1.1.1/g' /etc/resolv.conf | ||
ipfs init --profile flatfs,server,randomports,lowpower | ||
# make flatfs async for faster ci | ||
ipfs config --json 'Datastore.Spec.mounts' "$(ipfs config 'Datastore.Spec.mounts' | jq -c '.[0].child.sync=false')" | ||
shell: bash | ||
- uses: ipfs/start-ipfs-daemon-action@v1 | ||
with: | ||
args: --enable-gc=false | ||
- name: Preconnect to cluster peers | ||
run: | | ||
ipfs-cluster-ctl --enc=json \ | ||
--host "/dnsaddr/ipfs-websites.collab.ipfscluster.io" \ | ||
--basic-auth "$CLUSTER_USER:$CLUSTER_PASSWORD" \ | ||
peers ls | tee cluster-peers-ls | ||
for maddr in $(jq -r '.ipfs.addresses[]?' cluster-peers-ls); do | ||
ipfs swarm peering add $maddr | ||
ipfs swarm connect $maddr || true & | ||
done | ||
shell: bash | ||
env: | ||
CLUSTER_USER: ${{ secrets.CLUSTER_USER }} | ||
CLUSTER_PASSWORD: ${{ secrets.CLUSTER_PASSWORD }} | ||
- name: IPFS import of ./dist and generating CID | ||
id: ipfs-import | ||
run: | | ||
root_cid=$(ipfs add --cid-version 1 -Q -r --offline ./dist) | ||
echo "cid=$root_cid" >> $GITHUB_OUTPUT | ||
- name: Create CAR file | ||
run: ipfs dag export ${{ steps.ipfs-import.outputs.cid }} > swgw_${{ github.sha }}.car | ||
- name: Attach CAR to Github Action | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: swgw_${{ github.sha }}.car | ||
path: swgw_${{ github.sha }}.car | ||
if-no-files-found: error | ||
- name: Pin to ipfs-websites.collab.ipfscluster.io | ||
run: | | ||
ipfs-cluster-ctl --enc=json \ | ||
--host "/dnsaddr/ipfs-websites.collab.ipfscluster.io" \ | ||
--basic-auth "${CLUSTER_USER}:${CLUSTER_PASSWORD}" \ | ||
pin add \ | ||
--name "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" \ | ||
--replication-min 2 \ | ||
--replication-max 6 \ | ||
--wait \ | ||
"$PIN_CID" | ||
env: | ||
PIN_CID: ${{ steps.ipfs-import.outputs.cid }} | ||
CLUSTER_USER: ${{ secrets.CLUSTER_USER }} | ||
CLUSTER_PASSWORD: ${{ secrets.CLUSTER_PASSWORD }} | ||
timeout-minutes: 60 | ||
- name: Update DNSLink at inbrowser.dev | ||
# TODO .dev only if: github.ref == 'refs/heads/main' | ||
run: | | ||
curl --request PUT --header "Authorization: Bearer ${AUTH_TOKEN}" \ | ||
--url "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \ | ||
--header 'Content-Type: application/json' \ | ||
--data "{\"type\":\"TXT\",\"name\":\"${DNSLINK_NAME}\",\"content\":\"dnslink=/ipfs/${DNSLINK_CID}\",\"comment\":\"https://github.com/${{ github.repository }}/commit/${{ github.sha }}\"}" | ||
env: | ||
# TODO switch to real name, and update record_id | ||
DNSLINK_NAME: test.inbrowser.dev | ||
DNSLINK_CID: ${{ steps.ipfs-import.outputs.cid }} | ||
ZONE_ID: ${{ secrets.CF_INBROWSERDEV_ZONE_ID }} | ||
RECORD_ID: ${{ secrets.CF_INBROWSERDEV_RECORD_ID }} | ||
AUTH_TOKEN: ${{ secrets.CF_INBROWSERDEV_AUTH_TOKEN }} | ||
# TODO same for .link but only if release |