This is probably the ideal solution for where to store the badges. Currently this is just handled as a documentation point
https://github.com/action-badges/core/blob/main/docs/github-action.md#storing-your-badges
I tried this naive approach:
async function createOrphanBranch(client, { owner, repo, branch }) {
const SHA1_EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
const res = await client.request("POST /repos/{owner}/{repo}/git/commits", {
owner,
repo,
message: "init orphan branch",
tree: SHA1_EMPTY_TREE,
parents: [],
});
await client.request("POST /repos/{owner}/{repo}/git/refs", {
owner,
repo,
ref: `refs/heads/${branch}`,
sha: res.data.sha,
});
}
async function initOrphanBranch(client, { owner, repo, branch }) {
try {
await client.rest.repos.getBranch({ owner, repo, branch });
} catch (e) {
await createOrphanBranch(client, { owner, repo, branch });
}
}
but it isn't concurrency-safe: If there are multiple workflows generating badges some of them will probably fail on the first run.
How can I do this in a concurrency-safe way?
This is probably the ideal solution for where to store the badges. Currently this is just handled as a documentation point
https://github.com/action-badges/core/blob/main/docs/github-action.md#storing-your-badges
I tried this naive approach:
but it isn't concurrency-safe: If there are multiple workflows generating badges some of them will probably fail on the first run.
How can I do this in a concurrency-safe way?