Automatic mod uploading by mod authors possible?

A place to talk about the official Factorio mod portal (https://mods.factorio.com)
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Automatic mod uploading by mod authors possible?

Post by eradicator »

I was wondering if anyone has (recently?) tried or succeeded in uploading mods to the portal via the API. In the factorian spirit of "automate everything" i would like to integerate an automatic update function into my build script. But as i'm entirely unfamilar with the portal API and have vague memories of ancient rumors that it's not possible *cough*... i figured i'd try asking. Dev comments are also very welcome ;).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

shanemadden
Fast Inserter
Fast Inserter
Posts: 128
Joined: Thu Feb 08, 2018 8:25 am
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by shanemadden »

Yup, got something working. It's what I'd consider brittle - the mod API doesn't have upload endpoints that are designed for programmatic access as far as I know, so the automation has a few hoops to jump through to act like a proper web browser .. and some of those hoops involve grepping the body of HTML responses for CSRF tokens. (I saw this post because I came here to ask about a programmatic endpoint for it where we could auth with a user's account token instead of their password and upload directly instead of emulating the upload form, which would be fantastic)

At the moment there's some outstanding issues that I need to fix like slightly messing up whitespace on the changelog when echoing it back to the upload form, but overall it seems to work.

It's implemented using GitHub Actions to automatically build and release tagged versions, which is a beta feature on GitHub's end; to use it directly you would first need to get the feature turned on for your GitHub account - but the actual automation is just a bash script (see entrypoint.sh) so you should be able to adapt it to your needs.

https://github.com/shanemadden/factorio ... al-publish

The web request process it's taking to complete an upload:
  • Load the login URL, store the CSRF token and session cookie
  • Login using the user, password, and CSRF token, getting a properly authenticated session
  • Load the mod info from the mod API, verifying that it's not trying to release a version that exists
  • Load the mod download edit form, store the CSRF token for the file upload
  • Upload the zip file using the CSRF token
  • Post the edit to the downloads to finish the release

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 222
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by mrudat »

It's awesome you've figured out how to do that, but I think it would be niftier to be able to post a notification on release, and have the mod portal pull the zip from github.

Roang
Inserter
Inserter
Posts: 27
Joined: Tue Aug 22, 2017 12:38 pm
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by Roang »

I've also been working on creating CI scripts for my mods and have some success with the browser mocking, but the error detection leaves a lot to be desired (e.g. login error detection).
Therefore I would also like to request an API endpoint to upload a mod to the portal one can sue with the tokens from the web authentication API.

Especially with a proper JSON response one can parse to trigger corresponding actions (e.g. version already exists)

mkaito
Inserter
Inserter
Posts: 29
Joined: Tue Sep 26, 2017 2:09 am
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by mkaito »

This would be amazing. We clearly need more automation here :D

Roang
Inserter
Inserter
Posts: 27
Joined: Tue Aug 22, 2017 12:38 pm
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by Roang »

I am in the process of updating my GitHub Action for uploading mods (https://github.com/Roang-zero1/factorio-mod-actions) and this feature would still improve the workflow quite a bit.
So I am giving it a push ;)

Roang
Inserter
Inserter
Posts: 27
Joined: Tue Aug 22, 2017 12:38 pm
Contact:

Re: Automatic mod uploading by mod authors possible?

Post by Roang »

Is there any chance of this getting implemented? Currently my GitHub action is broken due to captcha.
I would rather replace it with a robust upload API.

Post Reply

Return to “Mod portal Discussion”