commit a027d922b1543cc25c06a513efc2ac9a3b52f4d3
parent 7c39a7f62098339dc4383f23bee1f1dc815c8a12
Author: Suzanne Soy <jsmaniac.github@suzanne.soy>
Date: Tue, 18 Apr 2023 02:03:53 +0100
auto-deploy to IPFS
Diffstat:
3 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/.github/github_install_ipfs.sh b/.github/github_install_ipfs.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+set -euET -o pipefail
+
+cd /tmp
+wget https://dist.ipfs.tech/kubo/v0.19.1/kubo_v0.19.1_linux-amd64.tar.gz
+tar -zxf kubo_v0.19.1_linux-amd64.tar.gz
+PATH="/tmp/kubo:$PATH" ipfs init --profile=lowpower
diff --git a/.github/github_update_homepage.sh b/.github/github_update_homepage.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+set -euET -o pipefail
+
+echo "Hashing repository contents with IPFS..."
+
+h="$(ipfs cid base32 "$(ipfs add --recursive --progress --hidden --ignore-rules-path=.ipfsignore --quieter .)")"
+
+echo "After pinning, the new homepage URL will be: https://$h.ipfs.dweb.link/"
+
+# Wait for IPFS daemon to be ready
+echo 'Starting IPFS daemon...'
+tail -F /tmp/ipfs-daemon.logs -n +1 & pid=$!
+ipfs daemon >/tmp/ipfs-daemon.logs 2>&1 &
+while ! grep 'Daemon is ready' /tmp/ipfs-daemon.logs; do sleep 1; date; done
+echo 'IPFS daemon started, killing log tail...'
+kill "$pid"
+echo 'log tail killed'
+
+# Pin this hash
+echo "Adding remote pinning service..."
+(
+ ipfs pin remote service add my-remote-pin "$IPFS_REMOTE_API_ENDPOINT" "$IPFS_REMOTE_TOKEN"
+) > /dev/null 2>&1
+
+echo "Connecting to some IPFS node..."
+(
+ ipfs swarm connect "$IPFS_SWARM_CONNECT_TO"
+) > /dev/null 2>&1
+
+echo "Pinning $h on the remote service..."
+(
+ ipfs pin remote add --service=my-remote-pin --name='site-suzanne.soy-'"$GITHUB_SHA" "$h"
+) > /dev/null 2>&1
+echo "Finished pinning $h on the remote service"
+
+# Update Homepage URL on GitHub
+curl -L \
+ -X PATCH \
+ -H "Accept: application/vnd.github+json" \
+ -H "Authorization: Bearer $API_TOKEN_FOR_UPDATE_HOMEPAGE"\
+ -H "X-GitHub-Api-Version: 2022-11-28" \
+ https://api.github.com/repos/SuzanneSoy/SuzanneSoy.github.io \
+ -d '{"name":"SuzanneSoy.github.io", "homepage":"https://dweb.link/ipfs/'"$h"'"}' > /dev/null
diff --git a/.github/workflows/update-homepage-ipfs.yml b/.github/workflows/update-homepage-ipfs.yml
@@ -0,0 +1,44 @@
+# Simple workflow for deploying static content to GitHub Pages
+name: Update repo's Homepage field to the latest IPFS CID
+
+on:
+ # Runs on pushes targeting the default branch
+ push:
+ branches: ["main"]
+
+ # Allows you to run this workflow manually from the Actions tab
+ workflow_dispatch:
+
+# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
+permissions:
+ contents: read
+# pages: write
+ id-token: write
+
+# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
+# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
+concurrency:
+ group: "pages"
+ cancel-in-progress: false
+
+jobs:
+ # Single deploy job since we're just deploying
+ deploy:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ submodules: 'recursive'
+ - name: Download IPFS
+ run: ./.github/github_install_ipfs.sh
+ - name: Update homepage URL
+ run: PATH="/tmp/kubo:$PATH" ./.github/github_update_homepage.sh
+ env:
+ API_TOKEN_FOR_UPDATE_HOMEPAGE: ${{ secrets.API_TOKEN_FOR_UPDATE_HOMEPAGE }}
+ IPFS_SWARM_CONNECT_TO: ${{ secrets.IPFS_SWARM_CONNECT_TO }}
+ IPFS_REMOTE_API_ENDPOINT: ${{ secrets.IPFS_REMOTE_API_ENDPOINT }}
+ IPFS_REMOTE_TOKEN: ${{ secrets.IPFS_REMOTE_TOKEN }}