diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 75f77d1..bf753c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,8 @@ jobs: version: 0.${{ github.run_number }}.0 community: test # needs to be test for thunderstore.dev wrap: mods + website: "https://greenboi.me" + categories: "mods maps tools items" - run: echo ${{ steps.pub.outputs.url }} diff --git a/Dockerfile b/Dockerfile index 08cd788..a29ba19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu as setup +FROM denoland/deno as setup WORKDIR / RUN ["apt", "update", "-yy"] RUN ["apt", "install", "wget", "-yy"] @@ -6,5 +6,6 @@ RUN ["wget", "-O", "tcli.tar.gz", "https://github.com/thunderstore-io/thunderst RUN ["tar", "xvf", "tcli.tar.gz"] RUN ["mv", "-v", "tcli-0.1.4-linux-x64/tcli", "/bin/tcli"] COPY ./entrypoint.sh /entrypoint.sh +COPY ./cfg_edit.js /cfg_edit.js RUN ["chmod", "+x", "/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 2ce40af..5bb7f31 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,11 @@ jobs: community: Northstar ``` +## Getting a Thunderstore token + +Check the wiki [here](https://github.com/GreenTF/upload-thunderstore-package/wiki#where-to-get-your-thunderstore-token) + + ## Inputs | Input | Description | Required | |-------|-------------|----------| @@ -48,6 +53,9 @@ jobs: | `readme` | URL to download the readme from. Will try to fine `README.md` in the root of the repo if not provided. | `false` | | `dev` | Publish to https://thunderstore.dev if set, https://thunderstore.io if not set. | `false` | | `wrap` | Directory to wrap the contents of the repo in. By default the contents of the root of the repo will be in the root of the package. | `false` | +| `categories` | A list, separated by spaces of categories to give to the mod when published. These must be available in the community you're publishing to. | `false` | +| `deps` | A list, separated by spaces, of mods this mod depends on. Must be in `namespace-modname@1.2.3` format. The publish will fail if any of these aren't a real package. | `false` | +| `nsfw` | Set this to mark the mod as NSFW | `false` | ## Outputs | Output | Description | diff --git a/action.yml b/action.yml index a5c885a..ebe4a0c 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,14 @@ inputs: description: 'Push to thunderstore.dev rather then thunderstore.io' wrap: description: 'Directory to wrap the contents of the repo in' + website: + description: 'Homepage URL' + categories: + description: 'Categories the mod belongs to' + deps: + description: 'List of dependencies by name & version' + nsfw: + description: 'Is the mod NSFW' outputs: url: description: 'URL of uploaded mod' @@ -52,3 +60,7 @@ runs: TS_PATH: ${{ inputs.path }} TS_DEV: ${{ inputs.dev }} TS_WRAP: ${{ inputs.wrap }} + TS_WEBSITE: ${{ inputs.website }} + TS_CATEGORIES: ${{ inputs.categories }} + TS_DEPS: ${{ inputs.deps }} + TS_NSFW: ${{ inputs.nsfw }} diff --git a/cfg_edit.js b/cfg_edit.js new file mode 100644 index 0000000..930e012 --- /dev/null +++ b/cfg_edit.js @@ -0,0 +1,72 @@ +import * as TOML from "https://unpkg.com/@aduh95/toml@0.4.2/web/toml2js.js"; + +//init toml parser for some reason idk there was no Deno native module +await TOML.default(); + + + +//Read in thunderstore.toml +const tstore = TOML.parse(await Deno.readTextFile("./thunderstore.toml")); + +const name = Deno.env.get("TS_NAME"); +const version = Deno.env.get("TS_VERSION"); +const desc = Deno.env.get("TS_DESCRIPTION"); +const homepage = Deno.env.get("TS_WEBSITE"); +const categories = Deno.env.get("TS_CATEGORIES").replace(/\n/g, ''); +const deps = Deno.env.get("TS_DEPS").replace(/\n/g, ' '); +const community = Deno.env.get("TS_COMMUNITY"); +const nsfw = Deno.env.get("TS_NSFW"); +const wrap = Deno.env.get("TS_WRAP"); + +console.log(deps) + +//these should be set already but we're rewriting the whole file anyways +tstore.package.name = name; +tstore.package.versionNumber = version; +tstore.package.description = desc; + +tstore.publish.communities = [community]; +tstore.build.copy[0].target = wrap; +tstore.package.dependencies = {}; + +console.log(tstore.build); + +//check for optional inputs +if (homepage && homepage !== "") { + tstore.package.websiteUrl = homepage; +} + +if (nsfw && nsfw !== "" ) { + tstore.package.containsNsfwContent = true +} + +if (categories && categories !== "") { + //only keep truthy elements from the split + tstore.publish.categories = categories.split(' ').filter(e => e).map(e=> e.toLowerCase()); +} + +if (deps && deps !== "") { + const p = {}; + for (let d of deps.split(' ')) { + if(!d) + continue; + if (!d.includes('@')) { + console.log("Malformed dependency at ", d); + Deno.exit(-1); + } + + const parts = d.split('@'); + p[parts[0]] = parts[1]; + } + + console.log(p); + tstore.package.dependencies = p; +} + + + + + + +//write config file back to disk +Deno.writeTextFile("./thunderstore.toml", TOML.stringify(tstore)); diff --git a/entrypoint.sh b/entrypoint.sh index c494df2..b31b678 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -12,11 +12,11 @@ function setup() { p="." fi - mkdir -p "/dist/$TS_WRAP" + mkdir -p "/dist" # Move files to the dist directory for the tcli echo "Move files from $p to /dist" - mv $p/* /dist/$TS_WRAP + mv $p/* /dist # Move the README if it exists if [ -e "/dist/README.md" ]; then @@ -52,13 +52,15 @@ function configure(){ if [ -n "$TS_DEV" ]; then TS_COMMUNITY="test" fi - - echo "Set package community" - sed -i "s/communities = \[\]/communities = \[ \"$TS_COMMUNITY\" \]/g" thunderstore.toml - echo "Set package description" - sed -i "s/description = \"Example mod description\"/description = \"$TS_DESC\"/g" thunderstore.toml - echo "Remove example dependency" #TODO: Support dependencies - sed -i "s/Example-Dependency = \"1.0.0\"//g" thunderstore.toml + + echo $(deno run --allow-net --allow-env --allow-read --allow-write cfg_edit.js) + + # echo "Set package community" + # sed -i "s/communities = \[\]/communities = \[ \"$TS_COMMUNITY\" \]/g" thunderstore.toml + # echo "Set package description" + # sed -i "s/description = \"Example mod description\"/description = \"$TS_DESC\"/g" thunderstore.toml + # echo "Remove example dependency" #TODO: Support dependencies + # sed -i "s/Example-Dependency = \"1.0.0\"//g" thunderstore.toml echo "Done config edit" echo diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..63cb499 Binary files /dev/null and b/icon.png differ