Skip to content

Commit

Permalink
more mods & supported mods page
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Aug 15, 2024
1 parent 6788ab6 commit 310dea7
Show file tree
Hide file tree
Showing 41 changed files with 442 additions and 143 deletions.
191 changes: 96 additions & 95 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,114 @@
name: Build Website
on:
workflow_dispatch:
inputs:
skipCache:
description: 'skip the cached icons?'
default: false
type: boolean
push:
paths:
- .gitmodules
- pack/index.toml
workflow_dispatch:
inputs:
skipCache:
description: "skip the cached icons?"
default: false
type: boolean
push:
paths:
- .gitmodules
- pack/index.toml

env:
REGISTRY: ghcr.io
GITHUB_REPO: ${{ github.repository }}
REGISTRY: ghcr.io
GITHUB_REPO: ${{ github.repository }}

jobs:
datagen:
runs-on: windows-2022
permissions:
contents: read
packages: read
datagen:
runs-on: windows-2022
permissions:
contents: read
packages: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: "pnpm"

- name: Install dependencies
run: pnpm install --frozen-lockfile --strict-peer-dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --strict-peer-dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/cache@v4
name: Setup icons cache
id: cache
with:
path: web/public/icons
lookup-only: ${{ inputs.skipCache }}
key: icons-${{ hashFiles('.gitmodules', 'pack/index.toml') }}
restore-keys: |
icons-
- uses: actions/cache@v4
name: Setup icons cache
id: cache
with:
path: web/public/icons
lookup-only: ${{ inputs.skipCache }}
key: icons-${{ hashFiles('.gitmodules', 'pack/index.toml') }}
restore-keys: |
icons-
- name: Generate Data
if: inputs.skipCache || steps.cache.outputs.cache-hit != 'true'
run: pnpm run gen
env:
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
- name: Generate Data
if: inputs.skipCache || steps.cache.outputs.cache-hit != 'true'
run: pnpm run gen
env:
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}

- name: Upload generated data as artifact
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: generated-data
path: web/public/icons
- name: Upload generated data as artifact
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: generated-data
path: web/public/icons

docker:
runs-on: ubuntu-latest
needs: datagen
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
docker:
runs-on: ubuntu-latest
needs: datagen
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false

- name: Download generated data from artifact
uses: actions/download-artifact@v4
with:
name: generated-data
path: web/public/icons
- name: Download generated data from artifact
uses: actions/download-artifact@v4
with:
name: generated-data
path: web/public/icons

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.GITHUB_REPO }}
tags: |
type=raw,value=latest
type=raw,value=stable,enable=${{ github.event_name == 'release' }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=sha,priority=250,enable=${{ github.event_name != 'release' }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.GITHUB_REPO }}
tags: |
type=raw,value=latest
type=raw,value=stable,enable=${{ github.event_name == 'release' }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
type=sha,priority=250,enable=${{ github.event_name != 'release' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: web/Dockerfile
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: web/Dockerfile
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
101 changes: 84 additions & 17 deletions generator/src/install.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHash } from 'crypto'
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, statSync } from 'fs'
import { dirname, join } from 'path'
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
import { basename, dirname, join } from 'path'
import { Readable } from 'stream'
import { parse } from 'toml'

Expand All @@ -22,29 +22,50 @@ function verifySha(name, content, checksum) {
}
}

const sharedHeaders = {
accept: 'application/json',
'User-Agent': 'voidshake/icons',
}

async function fetchFromModrinth(endpoint) {
const token = process.env.MODRINTH_TOKEN

if (!token) throw new Error(`Unable to download from modrinth without passing a token`)

const response = await fetch(`https://api.modrinth.com/v2/${endpoint}`, {
headers: {
...sharedHeaders,
authorization: token,
},
})
if (!response.ok) throw new Error(response.statusText)

return await response.json()
}

async function fetchFromCurseforge(endpoint) {
const token = process.env.CURSEFORGE_TOKEN

if (!token) throw new Error(`Unable to download from curseforge without passing a token`)

const response = await fetch(`https://api.curseforge.com/${endpoint}`, {
headers: {
...sharedHeaders,
'x-api-key': token,
},
})
if (!response.ok) throw new Error(response.statusText)

return response
const { data } = await response.json()
return data
}

async function getUrlFrom({ download, name, update }) {
if (download.url) return download.url
if (download.mode === 'metadata:curseforge' && update.curseforge) {
const response = await fetchFromCurseforge(
return fetchFromCurseforge(
`v1/mods/${update.curseforge['project-id']}/files/${update.curseforge['file-id']}/download-url`
)
const { data } = await response.json()
return data
}

throw new Error(`unable to find url for ${name}`)
Expand All @@ -67,6 +88,62 @@ async function downloadFile(definition, outPath) {
})
}

async function downloadMod(definition, dir) {
console.log(` downloading ${definition.filename}...`)

const outPath = join(to, dir, definition.filename)

if (!existsSync(outPath) || options.includes('--overwrite')) {
await downloadFile(definition, outPath)
} else {
console.log(` using cached file for ${outPath}`)
}

verifyFileSha(outPath, definition.download.hash)
}

async function getModInfo(definition) {
if ('curseforge' in definition.update) {
const data = await fetchFromCurseforge(`v1/mods/${definition.update.curseforge['project-id']}`)
const url = `https://www.curseforge.com/minecraft/mc-mods/${data.slug}`
const icon = data.logo?.thumbnailUrl
return { url, icon }
}

if ('modrinth' in definition.update) {
const data = await fetchFromModrinth(`project/${definition.update.modrinth['mod-id']}`)
const url = `https://modrinth.com/mod/${data.slug}`
const icon = data.icon_url
return { url, icon }
}

return null
}

async function gatherInfo(definition, file) {
const outDir = join('..', 'web', dirname(file))

if (!existsSync(outDir)) {
mkdirSync(outDir, { recursive: true })
}

const base = basename(file)
const name = base.substring(0, base.length - '.pw.toml'.length) + '.json'
const out = join(outDir, name)

writeFileSync(
out,
JSON.stringify(
{
name: definition.name,
...(await getModInfo(definition)),
},
null,
2
)
)
}

async function installPack(from, to, options) {
if (!from) throw new Error('input argument missing')
if (!to) throw new Error('output argument missing')
Expand All @@ -90,17 +167,7 @@ async function installPack(from, to, options) {
index.files.map(async ({ file }) => {
const definition = readToml(join(packDir, file))

console.log(` downloading ${definition.filename}...`)

const outPath = join(to, dirname(file), definition.filename)

if (!existsSync(outPath) || options.includes('--overwrite')) {
await downloadFile(definition, outPath)
} else {
console.log(` using cached file for ${outPath}`)
}

verifyFileSha(outPath, definition.download.hash)
await Promise.all([downloadMod(definition, dirname(file)), gatherInfo(definition, file)])
})
)

Expand Down
19 changes: 0 additions & 19 deletions index.html

This file was deleted.

5 changes: 5 additions & 0 deletions web/mods/ad-astra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Ad Astra",
"url": "https://modrinth.com/mod/ad-astra",
"icon": "https://cdn.modrinth.com/data/3ufwT9JF/2a15f23b7ffa2d50fc6ae1c42029a728ce3e2847.jpeg"
}
5 changes: 5 additions & 0 deletions web/mods/aether.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "The Aether",
"url": "https://modrinth.com/mod/aether",
"icon": "https://cdn.modrinth.com/data/YhmgMVyu/0505092d2d3336722f12b1deca268f9fdeebd8f4.png"
}
5 changes: 5 additions & 0 deletions web/mods/alexs-caves.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Alex's Caves",
"url": "https://modrinth.com/mod/alexs-caves",
"icon": "https://cdn.modrinth.com/data/U6GY0xp0/4165eef78a7efa0f5acda964dd094c08ee0e5680.png"
}
Loading

0 comments on commit 310dea7

Please sign in to comment.