diff --git a/.github/scripts/count-reward.ts b/.github/scripts/count-reward.ts index a6448cbc9..348e9c63b 100644 --- a/.github/scripts/count-reward.ts +++ b/.github/scripts/count-reward.ts @@ -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}`; diff --git a/.github/scripts/git.ts b/.github/scripts/git.ts new file mode 100644 index 000000000..aebbd463f --- /dev/null +++ b/.github/scripts/git.ts @@ -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(); +} diff --git a/.github/scripts/share-reward.ts b/.github/scripts/share-reward.ts index 018974482..da1ab20ff 100644 --- a/.github/scripts/share-reward.ts +++ b/.github/scripts/share-reward.ts @@ -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`; diff --git a/.github/workflows/statistic-member-reward.yml b/.github/workflows/statistic-member-reward.yml index 09e5b88fc..2b9bc8837 100644 --- a/.github/workflows/statistic-member-reward.yml +++ b/.github/workflows/statistic-member-reward.yml @@ -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