Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/scripts/count-reward.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $, YAML } from "npm:zx";

import { createDetachedCommit } from "./git.ts";
import { Reward } from "./type.ts";

$.verbose = true;
Expand Down Expand Up @@ -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 changes: 15 additions & 0 deletions .github/scripts/git.ts
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 5 additions & 1 deletion .github/scripts/share-reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`;
Expand Down
20 changes: 1 addition & 19 deletions .github/workflows/statistic-member-reward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading