Skip to content

Commit

Permalink
feat(ci): update inbrowser.link on release publish
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Mar 15, 2024
1 parent 8ec199c commit c39622b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 34 deletions.
89 changes: 57 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
pull_request:
branches:
- '**'
release:
types: [ published ]
workflow_dispatch:

env:
Expand Down Expand Up @@ -167,11 +169,11 @@ jobs:
files: .coverage/*,packages/*/.coverage/*

publish-to-ipfs:
# TODO: make this run also on release
if: github.ref == 'refs/heads/main'
# NOTE: workflow_dispatch here allows maintainer to manually run against any branch, and it will produce a CAR with CID that is pinned
# TODO: if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'release' && github.event.action == 'published')
needs: build
runs-on: ubuntu-latest
environment: Deploy # CF and Clusteer secrets
environment: Deploy # Clusteer secrets
concurrency:
# only one job runs at a time == DNSLinks are updated in-order
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -193,17 +195,7 @@ jobs:
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 \
Expand Down Expand Up @@ -249,8 +241,8 @@ jobs:
CLUSTER_USER: ${{ secrets.CLUSTER_USER }}
CLUSTER_PASSWORD: ${{ secrets.CLUSTER_PASSWORD }}
timeout-minutes: 60
- name: Update DNSLink at inbrowser.dev (Dev Testing)
if: github.ref == 'refs/heads/main'
- name: Update DNSLink at inbrowser.dev (Staging for Dev Testing) if main branch was updated
if: (github.event_name == 'workflow_dispatch' || github.event_name == 'push') && github.ref == 'refs/heads/main'
run: |
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}" \
Expand All @@ -261,9 +253,8 @@ jobs:
ZONE_ID: ${{ secrets.CF_INBROWSERDEV_ZONE_ID }}
RECORD_ID: ${{ secrets.CF_INBROWSERDEV_RECORD_ID }}
AUTH_TOKEN: ${{ secrets.CF_INBROWSERDEV_AUTH_TOKEN }}
- name: Update DNSLink at inbrowser.link (Stable Production)
# TODO: make this run only on release
if: github.ref == 'refs/heads/main'
- name: Update DNSLink at inbrowser.link (Stable Production) if new release was published
if: github.event_name == 'release' && github.event.action == 'published'
run: |
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}" \
Expand All @@ -276,7 +267,7 @@ jobs:
AUTH_TOKEN: ${{ secrets.CF_INBROWSERLINK_AUTH_TOKEN }}

pin-to-w3: # ported from ipfs/ipfs-webui
if: ${{ success() && needs.publish-to-ipfs.outputs.cid }}
if: needs.publish-to-ipfs.outputs.cid
needs: publish-to-ipfs
runs-on: ubuntu-latest
environment: web3.storage
Expand Down Expand Up @@ -313,7 +304,7 @@ jobs:
W3CLI_SPACE_DELEGATION_PROOF_BASE64_STRING: ${{ secrets.W3CLI_SPACE_DELEGATION_PROOF_BASE64_STRING }}

pin-to-scaleway:
if: ${{ success() && needs.publish-to-ipfs.outputs.cid }}
if: needs.publish-to-ipfs.outputs.cid
needs: publish-to-ipfs
runs-on: ubuntu-latest
environment: Scaleway
Expand All @@ -326,14 +317,12 @@ jobs:
- name: Init IPFS daemon
run: ipfs init --profile flatfs,server,randomports,lowpower
- uses: ipfs/start-ipfs-daemon-action@v1
with:
args: --enable-gc=false
- name: Retrieve CAR produced by publish-to-ipfs job
uses: actions/download-artifact@v4
with:
name: dist_${{ github.sha }}.car
- name: Import CAR to local Kubo
run: ipfs dag import --offline dist_${{ github.sha }}.car
run: ipfs dag import --offline --pin-roots=true dist_${{ github.sha }}.car
- name: Set up and check Scaleway
id: scaleway
run: |
Expand All @@ -349,15 +338,51 @@ jobs:
env:
CID: ${{ needs.publish-to-ipfs.outputs.cid }}

smoke-test-http: # basic smoke test that lets us know when eother caching or content routing does not work
if: ${{ success() && needs.publish-to-ipfs.outputs.cid }}
needs: [ publish-to-ipfs, pin-to-scaleway, pin-to-w3 ]
smoke-test-cached-http: # basic smoke test that lets us know when stale-while-revalidate caching does not work on either env
if: needs.publish-to-ipfs.outputs.cid
needs: publish-to-ipfs
runs-on: ubuntu-latest
strategy:
matrix:
dnslink:
- inbrowser.link
- inbrowser.dev
steps:
- name: Smoke-test instant (cached, stale-while-revalidate) /ipfs-sw-main.js at ${{ matrix.dnslink }}
run: curl --retry 3 --retry-delay 61 --retry-all-errors -v https://${{ matrix.dnslink }}/ipfs-sw-main.js > /dev/null

smoke-test-fresh-http: # basic smoke test for getting new DAG over HTTP gateways
if: needs.publish-to-ipfs.outputs.cid
needs: publish-to-ipfs
runs-on: ubuntu-latest
strategy:
matrix:
gateway:
- trustless-gateway.link
- cloudflare-ipfs.com
- w3s.link
steps:
- name: Smoke-test instant (cached, stale-while-revalidate) /ipfs-sw-main.js at inbrowser.link
run: curl --retry 3 --retry-delay 61 --retry-all-errors -v https://inbrowser.link/ipfs-sw-main.js > /dev/null
- name: Smoke-test instant (cached, stale-while-revalidate) /ipfs-sw-main.js at inbrowser.dev
run: curl --retry 3 --retry-delay 61 --retry-all-errors -v https://inbrowser.dev/ipfs-sw-main.js > /dev/null
- name: Smoke-test fetching the new CID as CAR from trustless-gateway.link
run: curl --retry 3 --retry-delay 61 --retry-all-errors -v "https://trustless-gateway.link/ipfs/${{ needs.publish-to-ipfs.outputs.cid }}?format=car" > /dev/null
- name: Smoke-test fetching the new CID as CAR from ${{ matrix.gateway }}
run: curl --retry 6 --retry-delay 61 --retry-all-errors -v "https://${{ matrix.gateway }}/ipfs/${{ needs.publish-to-ipfs.outputs.cid }}?format=car" > /dev/null

smoke-test-fresh-p2p: # basic smoke test for getting new DAG over P2P with Kubo
if: needs.publish-to-ipfs.outputs.cid
needs: publish-to-ipfs
runs-on: ubuntu-latest
strategy:
matrix:
routing-type:
- dhtclient
- autoclient
steps:
- uses: ipfs/download-ipfs-distribution-action@v1
with:
name: kubo
version: "${{ env.KUBO_VER }}"
- name: Init IPFS daemon
run: |
ipfs init --profile server
ipfs config Routing.Type ${{ matrix.routing-type }}
- uses: ipfs/start-ipfs-daemon-action@v1
- name: Confirm Kubo can fetch with Routing.Type=${{ matrix.routing-type }}
run: ipfs dag stat ${{ needs.publish-to-ipfs.outputs.cid }}
15 changes: 13 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readdirSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { execSync } from 'child_process'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
Expand Down Expand Up @@ -141,7 +142,7 @@ const dev = {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET'
},
allowedHosts: ['helia-sw-gateway.localhost', 'localhost']
allowedHosts: ['swig.localhost', 'helia-sw-gateway.localhost', 'localhost']
},

plugins: [
Expand Down Expand Up @@ -172,6 +173,16 @@ const test = {
}
}

/**
* Retrieves the Git branch and short SHA of the current commit.
* @returns {string} A string representing the Git branch and short SHA.
*/
const gitRevision = () => {
const ref = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
const sha = execSync('git rev-parse --short HEAD').toString().trim()
return `${ref}@${sha}`
}

/**
* @type {import('webpack').Configuration}
*/
Expand Down Expand Up @@ -202,7 +213,7 @@ const common = {
// Generates deprecation warning: https://github.com/jantimon/html-webpack-plugin/issues/1501
new HtmlWebpackPlugin({
excludeChunks: ['sw'],
title: 'IPFS Service Worker Gateway',
title: `IPFS Service Worker Gateway ${gitRevision()}`,
favicon: paths.public + '/favicon.ico',
template: paths.public + '/index.html', // template file
filename: 'index.html', // output file,
Expand Down

0 comments on commit c39622b

Please sign in to comment.