Skip to content

Commit

Permalink
Dev (#9)
Browse files Browse the repository at this point in the history
* move config editing to deno

* fix readme and icon not being moved properly

* Update README with new inputs

* Update README.md
  • Loading branch information
AnActualEmerald authored Aug 4, 2022
1 parent 24b69ce commit 47dd0d6
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}


Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM ubuntu as setup
FROM denoland/deno as setup
WORKDIR /
RUN ["apt", "update", "-yy"]
RUN ["apt", "install", "wget", "-yy"]
RUN ["wget", "-O", "tcli.tar.gz", "https://github.com/thunderstore-io/thunderstore-cli/releases/download/0.1.4/tcli-0.1.4-linux-x64.tar.gz"]
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"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|-------|-------------|----------|
Expand All @@ -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 |
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }}
72 changes: 72 additions & 0 deletions cfg_edit.js
Original file line number Diff line number Diff line change
@@ -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));
20 changes: 11 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 47dd0d6

Please sign in to comment.