antfu-collective/sponsorkit

Past GitHub sponsors are randomly generated

MichalLytek opened this issue · 10 comments

Describe the bug

I have a cron workflow which is supposed to refresh github sponsors every night.

However, I see that every night it's generating a new image and committing the changes, leading to polluting the master branch.
When I check the svg file diff, it's just about swapping the places of the past sponsors.

image

I think the sponsorkit should stable sort the fetched sponsors, so that the images are generated in the same way, so that the cron workflow will skip commit as no changes detected by git.

In local mode, cache.json plays the role of the moderator, detecting no changes in fetched data.
However, in a cron workflow it might be harder to achieve.
If I delete it, it's again randomizing order of past sponsors.

Reproduction

https://github.com/MichalLytek/type-graphql/blob/master/.github/workflows/sponsor.yml

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5700X 8-Core Processor
    Memory: 12.78 GB / 15.58 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 16.19.0 - ~/.nvm/versions/node/v16.19.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.19.0/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v16.19.0/bin/npm

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
antfu commented

We could do a sorting, PR welcome :)

Can we add a sort (or sortBy) to BadgePreset with default values. Examples:

sort: "ASC"

// or
sort: { name: "ASC" }
antfu commented

We could always sort (by priority of sponsor amount -> sponsor date -> name alphabet). And maybe accepting a custom sort function if one wants to have full control (I imagine most of the cases there is no need to use it)

Awesome. Agree on sponsor amount > sponsor date > name alphabet.
The sort function is the copy of the one from array implementation :)

@antfu Always sorting includes all the providers?

antfu commented

We could do that in the core instead of providers

antfu commented

Yeah I think so

Can we close this? @antfu

PS: My bad, I forgot to add Fix