Skip to content

Commit 47dd0d6

Browse files
Dev (#9)
* move config editing to deno * fix readme and icon not being moved properly * Update README with new inputs * Update README.md
1 parent 24b69ce commit 47dd0d6

File tree

7 files changed

+107
-10
lines changed

7 files changed

+107
-10
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
version: 0.${{ github.run_number }}.0
3030
community: test # needs to be test for thunderstore.dev
3131
wrap: mods
32+
website: "https://greenboi.me"
33+
categories: "mods maps tools items"
3234
- run: echo ${{ steps.pub.outputs.url }}
3335

3436

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
FROM ubuntu as setup
1+
FROM denoland/deno as setup
22
WORKDIR /
33
RUN ["apt", "update", "-yy"]
44
RUN ["apt", "install", "wget", "-yy"]
55
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"]
66
RUN ["tar", "xvf", "tcli.tar.gz"]
77
RUN ["mv", "-v", "tcli-0.1.4-linux-x64/tcli", "/bin/tcli"]
88
COPY ./entrypoint.sh /entrypoint.sh
9+
COPY ./cfg_edit.js /cfg_edit.js
910
RUN ["chmod", "+x", "/entrypoint.sh"]
1011
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
community: Northstar
3535
```
3636
37+
## Getting a Thunderstore token
38+
39+
Check the wiki [here](https://github.com/GreenTF/upload-thunderstore-package/wiki#where-to-get-your-thunderstore-token)
40+
41+
3742
## Inputs
3843
| Input | Description | Required |
3944
|-------|-------------|----------|
@@ -48,6 +53,9 @@ jobs:
4853
| `readme` | URL to download the readme from. Will try to fine `README.md` in the root of the repo if not provided. | `false` |
4954
| `dev` | Publish to https://thunderstore.dev if set, https://thunderstore.io if not set. | `false` |
5055
| `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` |
56+
| `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` |
57+
| `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` |
58+
| `nsfw` | Set this to mark the mod as NSFW | `false` |
5159

5260
## Outputs
5361
| Output | Description |

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ inputs:
3434
description: 'Push to thunderstore.dev rather then thunderstore.io'
3535
wrap:
3636
description: 'Directory to wrap the contents of the repo in'
37+
website:
38+
description: 'Homepage URL'
39+
categories:
40+
description: 'Categories the mod belongs to'
41+
deps:
42+
description: 'List of dependencies by name & version'
43+
nsfw:
44+
description: 'Is the mod NSFW'
3745
outputs:
3846
url:
3947
description: 'URL of uploaded mod'
@@ -52,3 +60,7 @@ runs:
5260
TS_PATH: ${{ inputs.path }}
5361
TS_DEV: ${{ inputs.dev }}
5462
TS_WRAP: ${{ inputs.wrap }}
63+
TS_WEBSITE: ${{ inputs.website }}
64+
TS_CATEGORIES: ${{ inputs.categories }}
65+
TS_DEPS: ${{ inputs.deps }}
66+
TS_NSFW: ${{ inputs.nsfw }}

cfg_edit.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as TOML from "https://unpkg.com/@aduh95/toml@0.4.2/web/toml2js.js";
2+
3+
//init toml parser for some reason idk there was no Deno native module
4+
await TOML.default();
5+
6+
7+
8+
//Read in thunderstore.toml
9+
const tstore = TOML.parse(await Deno.readTextFile("./thunderstore.toml"));
10+
11+
const name = Deno.env.get("TS_NAME");
12+
const version = Deno.env.get("TS_VERSION");
13+
const desc = Deno.env.get("TS_DESCRIPTION");
14+
const homepage = Deno.env.get("TS_WEBSITE");
15+
const categories = Deno.env.get("TS_CATEGORIES").replace(/\n/g, '');
16+
const deps = Deno.env.get("TS_DEPS").replace(/\n/g, ' ');
17+
const community = Deno.env.get("TS_COMMUNITY");
18+
const nsfw = Deno.env.get("TS_NSFW");
19+
const wrap = Deno.env.get("TS_WRAP");
20+
21+
console.log(deps)
22+
23+
//these should be set already but we're rewriting the whole file anyways
24+
tstore.package.name = name;
25+
tstore.package.versionNumber = version;
26+
tstore.package.description = desc;
27+
28+
tstore.publish.communities = [community];
29+
tstore.build.copy[0].target = wrap;
30+
tstore.package.dependencies = {};
31+
32+
console.log(tstore.build);
33+
34+
//check for optional inputs
35+
if (homepage && homepage !== "") {
36+
tstore.package.websiteUrl = homepage;
37+
}
38+
39+
if (nsfw && nsfw !== "" ) {
40+
tstore.package.containsNsfwContent = true
41+
}
42+
43+
if (categories && categories !== "") {
44+
//only keep truthy elements from the split
45+
tstore.publish.categories = categories.split(' ').filter(e => e).map(e=> e.toLowerCase());
46+
}
47+
48+
if (deps && deps !== "") {
49+
const p = {};
50+
for (let d of deps.split(' ')) {
51+
if(!d)
52+
continue;
53+
if (!d.includes('@')) {
54+
console.log("Malformed dependency at ", d);
55+
Deno.exit(-1);
56+
}
57+
58+
const parts = d.split('@');
59+
p[parts[0]] = parts[1];
60+
}
61+
62+
console.log(p);
63+
tstore.package.dependencies = p;
64+
}
65+
66+
67+
68+
69+
70+
71+
//write config file back to disk
72+
Deno.writeTextFile("./thunderstore.toml", TOML.stringify(tstore));

entrypoint.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ function setup() {
1212
p="."
1313
fi
1414

15-
mkdir -p "/dist/$TS_WRAP"
15+
mkdir -p "/dist"
1616

1717
# Move files to the dist directory for the tcli
1818
echo "Move files from $p to /dist"
19-
mv $p/* /dist/$TS_WRAP
19+
mv $p/* /dist
2020

2121
# Move the README if it exists
2222
if [ -e "/dist/README.md" ]; then
@@ -52,13 +52,15 @@ function configure(){
5252
if [ -n "$TS_DEV" ]; then
5353
TS_COMMUNITY="test"
5454
fi
55-
56-
echo "Set package community"
57-
sed -i "s/communities = \[\]/communities = \[ \"$TS_COMMUNITY\" \]/g" thunderstore.toml
58-
echo "Set package description"
59-
sed -i "s/description = \"Example mod description\"/description = \"$TS_DESC\"/g" thunderstore.toml
60-
echo "Remove example dependency" #TODO: Support dependencies
61-
sed -i "s/Example-Dependency = \"1.0.0\"//g" thunderstore.toml
55+
56+
echo $(deno run --allow-net --allow-env --allow-read --allow-write cfg_edit.js)
57+
58+
# echo "Set package community"
59+
# sed -i "s/communities = \[\]/communities = \[ \"$TS_COMMUNITY\" \]/g" thunderstore.toml
60+
# echo "Set package description"
61+
# sed -i "s/description = \"Example mod description\"/description = \"$TS_DESC\"/g" thunderstore.toml
62+
# echo "Remove example dependency" #TODO: Support dependencies
63+
# sed -i "s/Example-Dependency = \"1.0.0\"//g" thunderstore.toml
6264

6365
echo "Done config edit"
6466
echo

icon.png

18.9 KB
Loading

0 commit comments

Comments
 (0)