Skip to content

Conversation

aplaice
Copy link
Collaborator

@aplaice aplaice commented Apr 6, 2025

This was originally designed for the automatic uploading of files to the unofficial "everfresh" release in my personal fork, and still keeps the parts of the code relevant only to that purpose.

I'm not at all sure whether this needs to be included in the main repo (I'm happy to keep it in my personal files), but I thought it might be worth it as simple, but useful maintenance code.

(If we are to include it, it might be preferable to move it into some subfolder or to remove the old github-CI-specific parts of the code. (OTOH if we do figure out a way to run attaching files to releases in GitHub actions in a safe way, this code might turn out to be useful in the main repo, as well.))

@axelboc
Copy link
Collaborator

axelboc commented Apr 6, 2025

I had written a script like this for Node a long while back (code below for reference). The only difference I think is that it was reading language codes directly from the names of the generated deck folders in the build directory.

anki-archiver
const path = require('path');
const fs = require('fs');
const { zip } = require('@papb/zip');

const ROOT = path.normalize('/.../ultimate-geography');
const BUILD = path.join(ROOT, 'build');

const descPath = path.join(ROOT, 'src/headers/desc.html');
const desc = fs.readFileSync(descPath, { encoding: 'utf-8' });
const [, version] = desc.match(/Ultimate Geography (v[0-9]+\.[0-9]+)/) || [];

const buildEntries = fs.readdirSync(BUILD, { withFileTypes: true });
const deckFolders = buildEntries.filter(entry => entry.isDirectory()).map(entry => entry.name);

(async () => {
  for (let name of deckFolders) {
    const target = name
      .replace(/ /g, '_')
      .replace(/\[([A-Z]{2})\]/, '$1')
      .replace('[Extended]', 'EXTENDED')
      .replace(/^(Ultimate_Geography)_(.*)$/, (_, ug, rest) => (
        `${ug}_${version}_${rest}.zip`
      ));

    await zip(path.join(BUILD, name), path.join(BUILD, target));
  }
})();

I think it's definitely worth having a script like this in the repo!

It'd be great to make it a first-class citizen, though - i.e. to write it in Python (for cross-platform support) and integrate it with Pipenv (dependency for zipping in Pipfile + pipenv run zip script).

@axelboc axelboc added the chore Documentation, licenses, repository structure, dependency upgrades, etc. label Apr 6, 2025
@aplaice aplaice force-pushed the zip_decks branch 3 times, most recently from 20ffd5f to efdf156 Compare April 6, 2025 16:47
Copy link
Collaborator

@axelboc axelboc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm it works beautifully on my end! 🥇

@axelboc
Copy link
Collaborator

axelboc commented Apr 6, 2025

Oh can you please just add running this script as a step in the maintainer's guide?

@axelboc axelboc merged commit a66cb9c into anki-geo:master Apr 12, 2025
1 check passed
@aplaice aplaice deleted the zip_decks branch April 13, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Documentation, licenses, repository structure, dependency upgrades, etc.
Development

Successfully merging this pull request may close these issues.

2 participants