Skip to content
Closed
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
31 changes: 0 additions & 31 deletions .github/workflows/npm-publish-2.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .github/workflows/npm-publish.yml

This file was deleted.

109 changes: 109 additions & 0 deletions .github/workflows/publish-github-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Publish Package to GitHub Packages

on:
push:
branches:
- master
- develop
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")
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" ]; 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_name=$PACKAGE_NAME" >> "$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 "${{ 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"
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."
120 changes: 119 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
```
Expand All @@ -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 |
Comment on lines +198 to +202

### 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
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions tests/logger-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading