Check if the `snap` binary is already available through the store?

I need to check if a .snap binary files was already released to snapstore. To do this I’d like to calculate the .snap hashsum, and check it against snap store to get that name of snap and its version, or a message that it doesn’t exists. Ideally a link to download it.

I am using a monorepo, and I don’t want to refresh snaps for every commit, because most commits are irrelevant to the snap. I tried to set CI filters to regenerate the snap only when relevant files are touched, but CI filters got really really complicated, because the release process is different depending on if the branch is PR or not. The diff that is used for calculating changed files also drifts in time. The PR is made against a specific commit, but when it is merged, there could be more commits in repository.

Instead of dealing with all these branching and diffing details, I decided to simplify the process by unconditionally building the snap as a reproducible build, and when just checking if the built binary is already released on each commit in master. And for that I need an API for this check from snap store. Ideally without the need for personal tokens, so that it could be run in PRs if needed.

You could try looking at the JSON from this kind of curl call to the store API:

curl -s -H 'Snap-Device-Series: 16' "https://api.snapcraft.io/v2/snaps/info/core?architecture=amd64&fields=architectures,revision,download" | jq