Skip to content

Commit

Permalink
feat: fleek deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta authored Nov 20, 2023
2 parents 2a3febb + 69834e0 commit 0775864
Show file tree
Hide file tree
Showing 30 changed files with 779 additions and 444 deletions.
99 changes: 10 additions & 89 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,12 @@ defaults:
shell: bash

jobs:
# Pulls the output.json from the latest successful run of the gateway-conformance.yml workflow
# and stores these as an artifacts for the build job.
pull-outputs:
runs-on: "ubuntu-latest"
strategy:
matrix:
target: ["ipfs/kubo", "ipfs/boxo", "ipfs/bifrost-gateway"]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: get repo details
id: get-details
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER_AND_REPO: ${{ matrix.target }}
run: |
DETAILS=$(gh api repos/${OWNER_AND_REPO})
DEFAULT_BRANCH=$(echo $DETAILS | jq -r '.default_branch')
echo "default-branch=${DEFAULT_BRANCH}" >> $GITHUB_OUTPUT
NAME=$(echo $DETAILS | jq -r '.name')
echo "name=${NAME}" >> $GITHUB_OUTPUT
- name: Download json output
id: download-artifact
uses: dawidd6/action-download-artifact@v2 # TODO: pin
with:
workflow: gateway-conformance.yml
workflow_conclusion: "completed" # TODO: ideally we could request success|failure (https://github.com/dawidd6/action-download-artifact#usage)
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.get-details.outputs.default-branch }}
name: gateway-conformance.json
repo: ${{ matrix.target }}
if_no_artifact_found: fail
- name: Upload JSON output
if: (failure() || success())
uses: actions/upload-artifact@v3
with:
name: conformance-${{ steps.get-details.outputs.name }}.json
path: ./output.json
# https://github.com/actions/starter-workflows/blob/4a8f18e34dd13d2b6ee4d8da2ba72629eafe1609/pages/hugo.yml#L1
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.117.0
needs: [pull-outputs]
permissions:
contents: write
steps:
- name: Setup Hugo
uses: peaceiris/actions-hugo@16361eb4acea8698b220b76c0d4e84e1fd22c61d # v2.6.0
Expand All @@ -81,55 +39,18 @@ jobs:
- name: Setup Pages
id: pages
uses: actions/configure-pages@v1
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Generate Data Aggregates
working-directory: ./
- name: Build
run: |
npm ci
mkdir ./munged
# download-artifact downloads artifacts in a directory named after the artifact
# details: https://github.com/actions/download-artifact#download-all-artifacts
for folder in ./artifacts/conformance-*.json; do
file="${folder}/output.json"
new_file="./munged/${folder#.\/artifacts\/conformance-}" # drop the ./artifacts/conformance- prefix
cat "$file" | node ./munge.js > "${new_file}"
done
# generate the sqlite database from our munged files
node ./munge_sql.js ./aggregates.db ./munged/*.json
make website
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OUTPUT_BASE_URL: ${{ steps.pages.outputs.base_url }}
- name: Upload Data Aggregates
# will be very useful for local debugging
# Used for local debugging
if: (failure() || success())
uses: actions/upload-artifact@v3
with:
name: dashboard-aggregates
name: artifacts
path: |
./munged
./aggregates.db
- name: Generate Content
run: |
node ./munge_aggregates.js ./aggregates.db ./www
- name: Build with Hugo
run: |
hugo \
--minify \
--baseURL ${{ steps.pages.outputs.base_url }}
working-directory: www
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: ./www/public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
./artifacts
115 changes: 0 additions & 115 deletions .github/workflows/test-prod-e2e.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/artifacts
/aggregates.db
/output.html
/output.xml
/fixtures.car
Expand Down
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ clean-docker:
docker image rm gateway-conformance; \
fi

# dashboard
raw_artifacts:
cat REPOSITORIES | xargs ./munge_download.sh ./artifacts

artifacts: raw_artifacts
find ./artifacts -name '*.json' -exec sh -c 'cat "{}" | node ./munge.js > out && mv out "{}"' \;

aggregates.db: artifacts
rm -f ./aggregates.db
node ./munge_sql.js ./aggregates.db ./artifacts/*.json

website_content: aggregates.db
node ./munge_aggregates.js ./aggregates.db ./www

website: website_content
cd www && hugo --minify $(if ${OUTPUT_BASE_URL},--baseURL ${OUTPUT_BASE_URL})

.PHONY: gateway-conformance
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
- [Local Development](#local-development)
- [Examples](#examples)
- [APIs](#apis)
- [Dashboard](#dashboard)
- [Adding your gateway to the dashboard](#adding-your-gateway-to-the-dashboard)
- [Building the Dashboard](#building-the-dashboard)
- [FAQ](#faq)
- [In Development](#in-development)

Expand Down Expand Up @@ -301,6 +304,29 @@ This templating is used almost everywhere in the test sugar, for example in requ
Request().Path("ipfs/{{cid}}", myCid) // will use "ipfs/Qm...."
```

## Dashboard

The gateway conformance test suite includes a web dashboard. This dashboard aggregates results from many test runs and renders them on a static website. This'll give you more detailed insights and navigation options.

### Adding your gateway to the dashboard

The dashboard is hosted at [conformance.ipfs.tech](https://conformance.ipfs.tech/). It aggregates test outputs from various IPFS implementations and renders them on a static website.

To add your gateway to the dashboard, you need to:

- Ensure that your gateway's repository is public.
- Ensure your gateway generates generates the `output.json` file in a `gateway-conformance.yml` file. Check [kubo's workflow](https://github.com/ipfs/kubo/blob/master/.github/workflows/gateway-conformance.yml) for an example.
- Add your gateway to the list of repositories in the [REPOSITORIES](./REPOSITORIES) file.

Once you join the dashboard, your test results will be picked up automatically and your implementation will show up on the dashboard.

### Building the Dashboard

- Set up a GitHub Token: Ensure you have a GitHub Token with `repo:read` scope. This is required to download artifacts.
- Run the Build Command: `GH_TOKEN=your_github_token make website`

This command downloads the latest test artifacts from the repositories listed in the `./REPOSITORIES` file. Then it generates a static website with Hugo in the `www/public` directory.

## FAQ

### How to generate XML, HTML and Markdown reports when using the tool as a Docker container?
Expand Down
3 changes: 3 additions & 0 deletions REPOSITORIES
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ipfs/kubo
ipfs/boxo
ipfs/bifrost-gateway
59 changes: 59 additions & 0 deletions munge_download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# This script downloads the latest gateway-conformance.json artifacts from the
# given repos and saves them to the output folder.
# it requires GH_TOKEN to be set to a valid GitHub token with repo access.

if [ "$#" -lt 2 ]; then
echo "Usage: $0 output_folder repo1 [repo2 ...]"
exit 1
fi

# if GH_TOKEN is empty, show a message to the user
if [ -z "$GH_TOKEN" ]; then
echo "::warning::GH_TOKEN is required to download the build artifact."
exit 1
fi

if ! command -v jq &> /dev/null || ! command -v unzip &> /dev/null; then
echo "::error::Required command(s) 'jq' and/or 'unzip' not found."
exit 1
fi

output_folder=$1
mkdir -p "$output_folder"

shift
REPOS=("$@")

GH_TOKEN="${GH_TOKEN:-}"
GH_API_BASE_URL="https://api.github.com"

gh_api_request() {
local endpoint="${@: -1}"

if [[ $endpoint =~ ^https?:// ]]; then
local url="$endpoint"
else
local url="$GH_API_BASE_URL$endpoint"
fi

curl -H "Authorization: token $GH_TOKEN" "${@:1:$#-1}" "$url"
}

for repo in "${REPOS[@]}"; do
default_branch=$(gh_api_request "/repos/$repo" | jq -r '.default_branch')
[ -z "$default_branch" ] && echo "::warning::Failed to fetch default branch for $repo" && continue

run_id=$(gh_api_request "/repos/$repo/actions/workflows/gateway-conformance.yml/runs?branch=$default_branch&status=success&per_page=1" | jq -r '.workflow_runs[0].id')
[ -z "$run_id" ] && echo "::warning::Failed to fetch workflow run ID for $repo" && continue

artifact_url=$(gh_api_request "/repos/$repo/actions/runs/$run_id/artifacts" | jq -r '.artifacts[] | select(.name=="gateway-conformance.json") | .archive_download_url')
[ -z "$artifact_url" ] && echo "::warning::Failed to fetch artifact URL for $repo" && continue

temp_dir=$(mktemp -d)
zip_file="$temp_dir/${repo##*/}-artifact.zip"
gh_api_request -L -o "${zip_file}" "$artifact_url" || echo "::warning::Failed to download artifact for $repo"
unzip -j "$zip_file" "output.json" -d "$temp_dir" && mv "$temp_dir/output.json" "$output_folder/${repo##*/}.json" || echo "::warning::Failed to extract output.json for $repo" && continue

rm -rf "$temp_dir"
done
4 changes: 3 additions & 1 deletion munge_sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ const main = async () => {
const fileName = file.split("/").slice(-1)[0].split(".")[0];
const implemId = fileName;

console.log(`Processing ${file}...`);
const content = JSON.parse(fs.readFileSync(file));
const { TestMetadata, ...tests } = content;

const time = TestMetadata?.time;
const { version, job_url } = TestMetadata?.meta || {};
const version = TestMetadata?.meta?.version || 'unknown';
const job_url = TestMetadata?.meta?.job_url || null;

await run(`
INSERT INTO TestRun (implementation_id, version, time, job_url)
Expand Down
2 changes: 1 addition & 1 deletion www/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL: http://example.org/
baseURL: https://conformance.ipfs.tech/
languageCode: en-us
title: Gateway Conformance Dashboard

Expand Down
Loading

0 comments on commit 0775864

Please sign in to comment.