diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml index 688d037..33822d9 100644 --- a/.github/workflows/cli-release.yml +++ b/.github/workflows/cli-release.yml @@ -10,6 +10,7 @@ on: type: string permissions: contents: write + id-token: write jobs: cli: runs-on: ubuntu-latest @@ -39,9 +40,19 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: gh release upload "$TAG" cli/sourcegraph-cli.tgz --clobber + # NPM_TOKEN publishes the first version; once npm lists this workflow as + # a trusted publisher of @c4a/sourcegraph, the token can be removed and + # PUBLISH_WITH_OIDC set to true. - name: Publish to npm env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - if: env.NODE_AUTH_TOKEN != '' + OIDC: ${{ vars.PUBLISH_WITH_OIDC }} + if: env.NODE_AUTH_TOKEN != '' || env.OIDC == 'true' working-directory: cli - run: npm publish --access public + run: | + npm install -g npm@11 + if npm view "@c4a/sourcegraph@$(node -p "require('./package.json').version")" version >/dev/null 2>&1; then + echo "This version is already on npm." + else + npm publish --access public --provenance + fi diff --git a/internal/service/metrics_store_test.go b/internal/service/metrics_store_test.go index 51e1568..ce6af2b 100644 --- a/internal/service/metrics_store_test.go +++ b/internal/service/metrics_store_test.go @@ -82,7 +82,12 @@ func TestMinuteLinesWrittenAfterMidnightAreCounted(t *testing.T) { if err != nil { t.Fatal(err) } - yesterday := time.Now().UTC().Truncate(24*time.Hour).Unix() - 60 // 23:59 UTC yesterday + now := time.Now().UTC() + if now.Sub(now.Truncate(24*time.Hour)) > 23*time.Hour+55*time.Minute { + // The last minute of yesterday would be older than the 24-hour window. + t.Skip("too close to midnight UTC") + } + yesterday := now.Truncate(24*time.Hour).Unix() - 60 // 23:59 UTC yesterday s := &Service{Root: root, boot: "pod-a/1", metrics: Metrics{queue: make(chan observation, 1)}} s.UseLogFiles(w) s.metrics.buckets = map[int64]*Bucket{yesterday: {Minute: yesterday, ByOperation: map[string]Metric{"search": {Requests: 5}}, ByRepo: map[string]Metric{}}}