From 24d9108a912e60429ad2dc3b9ca95c5735faebe9 Mon Sep 17 00:00:00 2001 From: Jose Raupp Date: Sat, 14 Mar 2026 18:40:56 -0300 Subject: [PATCH 1/2] chore: publish packages via github packages --- .github/workflows/npm-publish-2.yml | 31 ----- .github/workflows/npm-publish.yml | 30 ----- .github/workflows/publish-github-packages.yml | 108 ++++++++++++++++ README.md | 120 +++++++++++++++++- package.json | 3 + 5 files changed, 230 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/npm-publish-2.yml delete mode 100644 .github/workflows/npm-publish.yml create mode 100644 .github/workflows/publish-github-packages.yml diff --git a/.github/workflows/npm-publish-2.yml b/.github/workflows/npm-publish-2.yml deleted file mode 100644 index cb4f5ad..0000000 --- a/.github/workflows/npm-publish-2.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Publish Beta Version - -on: - push: - tags: - - '*.*.*' - -jobs: - publish: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 22 - registry-url: https://registry.npmjs.org - scope: '@ozmap' - - - name: Install dependencies - run: npm ci - - - name: Build - run: npm run build - - - name: Publish to NPM - run: npm publish --tag beta --access public - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index 7b3adf8..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Publish package to NPM Registry - -on: - push: - branches: - - master - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Install dependencies - run: npm install - - - name: Build source code - run: npm run build - - - name: Publish package - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish-github-packages.yml b/.github/workflows/publish-github-packages.yml new file mode 100644 index 0000000..bfc49c2 --- /dev/null +++ b/.github/workflows/publish-github-packages.yml @@ -0,0 +1,108 @@ +name: Publish Package to GitHub Packages + +on: + push: + branches: + - master + - develop + - development + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + - labeled + - unlabeled + +permissions: + contents: read + packages: write + +jobs: + publish: + name: Publish tagged package + runs-on: ubuntu-latest + if: >- + github.event_name == 'push' || + ( + github.event.pull_request.head.repo.full_name == github.repository && + contains(github.event.pull_request.labels.*.name, 'deployToTest') + ) + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up pnpm + uses: pnpm/action-setup@v4 + with: + version: 8 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + registry-url: https://npm.pkg.github.com + scope: '@ozmap' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build package + run: pnpm build + + - name: Resolve publish channel and version + id: publish_meta + env: + EVENT_NAME: ${{ github.event_name }} + REF_NAME: ${{ github.ref_name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + RUN_NUMBER: ${{ github.run_number }} + RUN_ATTEMPT: ${{ github.run_attempt }} + run: | + BASE_VERSION=$(node -p "require('./package.json').version") + + if [ "$EVENT_NAME" = "pull_request" ]; then + DIST_TAG=test + PACKAGE_VERSION="${BASE_VERSION}-pr.${PR_NUMBER}.${RUN_NUMBER}.${RUN_ATTEMPT}" + elif [ "$REF_NAME" = "develop" ] || [ "$REF_NAME" = "development" ]; then + DIST_TAG=beta + PACKAGE_VERSION="${BASE_VERSION}-beta.${RUN_NUMBER}.${RUN_ATTEMPT}" + elif [ "$REF_NAME" = "master" ]; then + DIST_TAG=latest + PACKAGE_VERSION="$BASE_VERSION" + else + echo "Unsupported publish source: $EVENT_NAME / $REF_NAME" >&2 + exit 1 + fi + + echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" + echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" + + - name: Stamp package version for pre-release channels + if: steps.publish_meta.outputs.dist_tag != 'latest' + run: npm version "${{ steps.publish_meta.outputs.package_version }}" --no-git-tag-version + + - name: Check whether stable version already exists + if: steps.publish_meta.outputs.dist_tag == 'latest' + id: stable_check + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if npm view @ozmap/logger@"${{ steps.publish_meta.outputs.package_version }}" version --registry=https://npm.pkg.github.com >/dev/null 2>&1; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Publish package + if: steps.publish_meta.outputs.dist_tag != 'latest' || steps.stable_check.outputs.exists != 'true' + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npm publish --tag "${{ steps.publish_meta.outputs.dist_tag }}" + + - name: Skip duplicate stable publish + if: steps.publish_meta.outputs.dist_tag == 'latest' && steps.stable_check.outputs.exists == 'true' + run: echo "Version ${{ steps.publish_meta.outputs.package_version }} is already published in GitHub Packages. Bump package.json to release a new stable build." \ No newline at end of file diff --git a/README.md b/README.md index d63adf5..56b5e00 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # OZLogger -[![npm version](https://img.shields.io/npm/v/@ozmap/logger.svg)](https://www.npmjs.com/package/@ozmap/logger) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) Módulo de logging profissional para Node.js desenvolvido pela DevOZ. Projetado para ambientes de produção com suporte a OpenTelemetry, saída JSON estruturada, colorização de terminal, e controle dinâmico de níveis de log via HTTP. @@ -157,6 +156,19 @@ A saída JSON do OZLogger é compatível com: ## Instalação +O pacote é publicado no GitHub Packages, no escopo `@ozmap`. Mesmo quando o pacote está com visibilidade pública, o GitHub Packages exige autenticação para instalação via npm. + +Crie ou atualize seu `~/.npmrc` com: + +```ini +@ozmap:registry=https://npm.pkg.github.com +//npm.pkg.github.com/:_authToken=SEU_GITHUB_PAT_CLASSIC +``` + +O token precisa ter pelo menos o escopo `read:packages`. + +Depois disso, instale normalmente: + ```bash npm install @ozmap/logger ``` @@ -173,6 +185,112 @@ ou com pnpm: pnpm add @ozmap/logger ``` +Se esta for a primeira publicação do pacote no GitHub Packages, deixe a visibilidade do package como pública na página do pacote dentro da organização `ozmap`. + +--- + +## Publicação e Canais + +O repositório usa GitHub Actions para publicar automaticamente no GitHub Packages, sempre no pacote `@ozmap/logger`. + +### Canais publicados + +| Origem | Tag npm | Objetivo | +|--------|---------|----------| +| `master` | `latest` | Release de produção | +| `develop` | `beta` | Release contínua de desenvolvimento | +| Pull Request com label `deployToTest` | `test` | Release efêmera para validação | + +### Regras de publicação + +- Push em `develop` publica uma nova versão com tag `beta` +- Push em `master` publica a versão estável com tag `latest` +- Pull Request só publica com tag `test` quando o label `deployToTest` estiver presente +- PR sem o label `deployToTest` não gera publicação de pacote +- PRs vindas de fork não publicam pacote, por segurança do workflow + +### Como gerar novos deploys + +#### Deploy de teste (`test`) + +1. Abra ou atualize uma PR com origem no próprio repositório +2. Adicione o label `deployToTest` +3. Aguarde o workflow publicar a versão `test` +4. Para gerar um novo deploy de teste, faça novo push na PR + +Se quiser forçar nova execução sem alterar código, remova o label `deployToTest` e adicione novamente. + +#### Deploy beta (`beta`) + +1. Faça merge ou push direto em `develop` +2. O workflow publica automaticamente uma nova versão com tag `beta` + +#### Deploy de produção (`latest`) + +1. Atualize o campo `version` no `package.json` +2. Faça merge em `master` +3. O workflow publica essa versão com tag `latest` + +Se a mesma versão já existir no GitHub Packages, o workflow pula a publicação. Para um novo release de produção, a versão do `package.json` precisa ser incrementada. + +### Versionamento gerado pelo workflow + +- `latest` usa exatamente a versão definida no `package.json` +- `beta` usa a versão base com sufixo de build automático +- `test` usa a versão base com sufixo identificando PR e execução do workflow + +Exemplos: + +- `0.2.8` para `latest` +- `0.2.8-beta.145.1` para `beta` +- `0.2.8-pr.87.145.1` para `test` + +### Como testar nas máquinas de desenvolvimento + +Depois de configurar o `~/.npmrc`, os devs podem instalar qualquer canal explicitamente. + +#### Instalar produção (`latest`) + +```bash +npm install @ozmap/logger@latest +``` + +#### Instalar beta (`beta`) + +```bash +npm install @ozmap/logger@beta +``` + +#### Instalar teste (`test`) + +```bash +npm install @ozmap/logger@test +``` + +#### Verificar qual versão cada tag aponta + +```bash +npm view @ozmap/logger dist-tags --registry=https://npm.pkg.github.com +``` + +#### Testar uma alteração local sem publicar + +Para validar o pacote localmente antes de subir para o registry: + +```bash +pnpm install +pnpm build +npm pack +``` + +Isso gera um tarball `.tgz` que pode ser instalado em outro projeto de teste: + +```bash +npm install ../ozlogger/ozmap-logger-0.2.8.tgz +``` + +Esse fluxo é o mais rápido para validar build, tipagens e empacotamento sem depender do GitHub Actions. + --- ## Quick Start diff --git a/package.json b/package.json index 21bc821..12f1944 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,9 @@ "url": "https://github.com/ozmap/ozlogger/issues" }, "homepage": "https://github.com/ozmap/ozlogger#readme", + "publishConfig": { + "registry": "https://npm.pkg.github.com" + }, "devDependencies": { "@jest/globals": "^30.2.0", "@tsconfig/node20": "^20.1.2", From ea13e099d049900d419841abe091dbe801c933e1 Mon Sep 17 00:00:00 2001 From: Jose Raupp Date: Sat, 14 Mar 2026 18:53:15 -0300 Subject: [PATCH 2/2] OZLOGGER fix: #time 10m address PR review feedback --- .github/workflows/publish-github-packages.yml | 7 ++++--- tests/logger-core.test.ts | 6 ++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish-github-packages.yml b/.github/workflows/publish-github-packages.yml index bfc49c2..5d1d4d7 100644 --- a/.github/workflows/publish-github-packages.yml +++ b/.github/workflows/publish-github-packages.yml @@ -5,7 +5,6 @@ on: branches: - master - develop - - development pull_request: types: - opened @@ -63,11 +62,12 @@ jobs: RUN_ATTEMPT: ${{ github.run_attempt }} run: | BASE_VERSION=$(node -p "require('./package.json').version") + PACKAGE_NAME=$(node -p "require('./package.json').name") if [ "$EVENT_NAME" = "pull_request" ]; then DIST_TAG=test PACKAGE_VERSION="${BASE_VERSION}-pr.${PR_NUMBER}.${RUN_NUMBER}.${RUN_ATTEMPT}" - elif [ "$REF_NAME" = "develop" ] || [ "$REF_NAME" = "development" ]; then + elif [ "$REF_NAME" = "develop" ]; then DIST_TAG=beta PACKAGE_VERSION="${BASE_VERSION}-beta.${RUN_NUMBER}.${RUN_ATTEMPT}" elif [ "$REF_NAME" = "master" ]; then @@ -79,6 +79,7 @@ jobs: fi echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" + echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" - name: Stamp package version for pre-release channels @@ -91,7 +92,7 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - if npm view @ozmap/logger@"${{ steps.publish_meta.outputs.package_version }}" version --registry=https://npm.pkg.github.com >/dev/null 2>&1; then + if npm view "${{ steps.publish_meta.outputs.package_name }}@${{ steps.publish_meta.outputs.package_version }}" version --registry=https://npm.pkg.github.com >/dev/null 2>&1; then echo "exists=true" >> "$GITHUB_OUTPUT" else echo "exists=false" >> "$GITHUB_OUTPUT" diff --git a/tests/logger-core.test.ts b/tests/logger-core.test.ts index 6ca14dd..e258528 100644 --- a/tests/logger-core.test.ts +++ b/tests/logger-core.test.ts @@ -37,11 +37,9 @@ describe('Logger Core', () => { expect(logged[0]).toContain('ms'); }); - test('should throw when timer ID already exists', () => { + test('should overwrite existing timer ID without throwing', () => { logger.time('duplicate'); - expect(() => logger.time('duplicate')).toThrow( - 'Identifier duplicate is in use' - ); + expect(() => logger.time('duplicate')).not.toThrow(); }); test('should throw when timeEnd called with unknown ID', () => {