This commit is contained in:
FenjuFu 2026-10-15 10:01:18 +08:00 • committed by GitHub
commit 2ddaa8b5ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 22 deletions

View file

@ -1,5 +1,6 @@
import { $, YAML } from "npm:zx";
import { createDetachedCommit } from "./git.ts";
import { Reward } from "./type.ts";
$.verbose = true;
@ -57,10 +58,12 @@ const tagName = `statistic-${new Date().toJSON().slice(0, 7)}`;
await $`git config user.name "github-actions[bot]"`;
await $`git config user.email "github-actions[bot]@users.noreply.github.com"`;
await $`git tag -a ${tagName} $(git rev-parse HEAD) -m ${summaryText}`;
const tagTarget = await createDetachedCommit(tagName);
await $`git tag -a ${tagName} ${tagTarget} -m ${summaryText}`;
await $`git push origin --tags --no-verify`;
await $`git config unset user.name`;
await $`git config unset user.email`;
await $`gh release create ${tagName} --notes ${summaryText}`;
// Keep "Latest" pointing at the newest product release
await $`gh release create ${tagName} --latest=false --notes ${summaryText}`;

15
.github/scripts/git.ts vendored Normal file
View file

@ -0,0 +1,15 @@
import { $ } from "npm:zx";
/**
* Create a parentless commit with an empty tree to carry reward/statistic tags.
*
* Tags pointing at product commits become the nearest tag in `git describe`,
* so downstream builds would report versions like `reward-42-3-gabc1234`
* instead of the latest release tag. Tags on a detached commit are never
* reachable from any branch and keep release tags authoritative.
*/
export async function createDetachedCommit(message: string) {
const emptyTree = (await $`git hash-object -w -t tree /dev/null`).stdout.trim();
return (await $`git commit-tree ${emptyTree} -m ${message}`).stdout.trim();
}

View file

@ -3,6 +3,7 @@ import "npm:array-unique-proposal";
import { components } from "npm:@octokit/openapi-types";
import { $, argv, YAML } from "npm:zx";
import { createDetachedCommit } from "./git.ts";
import { Reward } from "./type.ts";
$.verbose = true;
@ -110,7 +111,10 @@ console.log(listText);
await $`git config user.name "github-actions[bot]"`;
await $`git config user.email "github-actions[bot]@users.noreply.github.com"`;
await $`git tag -a "reward-${issueNumber}" ${mergeCommitSha} -m ${listText}`;
const tagTarget = await createDetachedCommit(
`reward-${issueNumber}: merged in ${mergeCommitSha}`,
);
await $`git tag -a "reward-${issueNumber}" ${tagTarget} -m ${listText}`;
await $`git push origin --tags --no-verify`;
await $`git config unset user.name`;

View file

@ -14,30 +14,12 @@ jobs:
fetch-depth: 0
fetch-tags: true
- name: Check for new commits since last statistic
run: |
last_tag=$(git describe --tags --abbrev=0 --match "statistic-*" || echo "")
if [ -z "$last_tag" ]; then
echo "No previous statistic tags found."
echo "NEW_COMMITS=true" >> $GITHUB_ENV
else
new_commits=$(git log $last_tag..HEAD --oneline)
if [ -z "$new_commits" ]; then
echo "No new commits since last statistic tag."
echo "NEW_COMMITS=false" >> $GITHUB_ENV
else
echo "New commits found."
echo "NEW_COMMITS=true" >> $GITHUB_ENV
fi
fi
# count-reward.ts exits early when no reward tags were created last month
- uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
if: env.NEW_COMMITS == 'true'
with:
deno-version: v2.x
- name: Statistic rewards
if: env.NEW_COMMITS == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: deno --allow-run --allow-sys --allow-env --allow-read --allow-net=api.github.com .github/scripts/count-reward.ts