bot-mwsm 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,188 +1,249 @@
1
- name: 🔄 Mwsm Version & Badge Sync
1
+ name: 🔄 Mwsm Version Sync
2
2
 
3
- # 🔐 Permite push com token pessoal
4
3
  permissions:
5
4
  contents: write
5
+ id-token: write # Necessário para publicação via Trusted Publisher (OIDC)
6
6
 
7
7
  on:
8
+ push:
9
+ branches: [ main ]
10
+ paths:
11
+ - "fonts/**"
12
+ - "icon.png"
13
+ - "index.html"
14
+ - "jquery.js"
15
+ - "mwsm.db"
16
+ - "mwsm.js"
17
+ - "mwsm.json"
18
+ - "nodemon.json"
19
+ - "package.json"
20
+ - "script.js"
21
+ - "socket.io.js"
22
+ - "style.css"
23
+ - "version.json"
24
+ - "mwsm.py"
8
25
  release:
9
- types: [published, edited] # também dispara se a release for editada
26
+ types: [published, edited]
10
27
  workflow_dispatch:
11
28
 
29
+ concurrency:
30
+ group: mwsm-version-sync
31
+ cancel-in-progress: false
32
+
12
33
  jobs:
13
34
  sync:
14
35
  runs-on: ubuntu-latest
36
+ # evita loops criados pelo próprio bot
37
+ if: ${{ !startsWith(github.event.head_commit.message, '🔄 Bot-Mwsm') }}
15
38
 
16
39
  steps:
17
- - name: 📥 Clonar repositório
40
+ - name: 🧩 Checkout do repositório
18
41
  uses: actions/checkout@v4
19
42
  with:
20
43
  fetch-depth: 0
21
- persist-credentials: false # desativa o token padrão
44
+ persist-credentials: false
22
45
  ref: main
23
46
 
24
- - name: 📦 Instalar dependências
25
- run: sudo apt-get install -y jq
47
+ - name: ⚙️ Instalar utilitários
48
+ run: sudo apt-get update && sudo apt-get install -y jq curl gh
26
49
 
27
- - name: 🔍 Detectar e atualizar versões
50
+ - name: 📂 Verificar arquivos modificados
28
51
  id: detect
52
+ run: |
53
+ set -euo pipefail
54
+ echo "📂 Verificando arquivos modificados..."
55
+ git fetch origin main --no-tags
56
+
57
+ # lidar com repositório com apenas 1 commit ou em runners onde HEAD^ pode não existir
58
+ if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
59
+ CHANGED_FILES=$(git diff --name-only HEAD^ HEAD || echo "")
60
+ else
61
+ # fallback: usa a lista de arquivos do último commit
62
+ CHANGED_FILES=$(git diff --name-only HEAD || git ls-files)
63
+ fi
64
+
65
+ echo "$CHANGED_FILES"
66
+ if echo "$CHANGED_FILES" | grep -q "mwsm.db"; then
67
+ echo "DB_CHANGED=true" >> "$GITHUB_OUTPUT"
68
+ else
69
+ echo "DB_CHANGED=false" >> "$GITHUB_OUTPUT"
70
+ fi
71
+
72
+ - name: 🔢 Atualizar version.json e package.json (sincroniza com último release e calcula incremento)
73
+ id: version
29
74
  env:
30
- GITHUB_API_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
75
+ GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
31
76
  run: |
32
77
  set -euo pipefail
78
+ PATCH=$(TZ="America/Sao_Paulo" date +"%Y-%m-%d %H:%M:%S")
33
79
 
34
- # 1) Tenta extrair tag do event JSON (robusto tanto em release event quanto em workflow_dispatch)
35
- EVENT_FILE="${GITHUB_EVENT_PATH:-/dev/null}"
36
- TAG_RELEASE=$(jq -r '.release.tag_name // ""' "$EVENT_FILE" 2>/dev/null || echo "")
37
- TAG_RELEASE="${TAG_RELEASE##v}" # remove "v" no início (ex: v2.0.55 2.0.55)
38
-
39
- # 2) Se estiver vazio, busca a última release via API (autenticada)
40
- if [ -z "$TAG_RELEASE" ]; then
41
- echo "🔎 Nenhuma tag presente no evento — buscando última release publicada via API..."
42
- if [ -z "${GITHUB_API_TOKEN:-}" ]; then
43
- echo "⚠️ PERSONAL_TOKEN não encontrado — fazendo chamada não autenticada (pode rate-limit)."
44
- TAG_RELEASE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name // empty')
45
- else
46
- TAG_RELEASE=$(curl -s -H "Authorization: Bearer ${GITHUB_API_TOKEN}" -H "Accept: application/vnd.github+json" \
47
- "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name // empty')
48
- fi
49
- TAG_RELEASE="${TAG_RELEASE##v}"
80
+ if [ "${GITHUB_EVENT_NAME}" = "release" ]; then
81
+ LATEST_TAG="${GITHUB_REF_NAME:-$(jq -r '.release.tag_name' "$GITHUB_EVENT_PATH" 2>/dev/null || true)}"
82
+ else
83
+ LATEST_TAG=$(gh release list --limit 1 --json tagName -q '.[0].tagName' 2>/dev/null || true)
50
84
  fi
51
85
 
52
- if [ -z "$TAG_RELEASE" ] || [ "$TAG_RELEASE" = "null" ]; then
53
- echo "❌ Nenhuma release encontrada. Abortando atualização para evitar sobrescrita de versões."
54
- echo "updated=false" >> "$GITHUB_OUTPUT"
55
- exit 0
86
+ LATEST_TAG=$(echo "$LATEST_TAG" | sed 's/^v//' || true)
87
+ FILE_VER=$(jq -r '.version[0].release // .version // empty' version.json 2>/dev/null || echo "")
88
+
89
+ if [ -n "$LATEST_TAG" ]; then
90
+ BASE="$LATEST_TAG"
91
+ elif [ -n "$FILE_VER" ]; then
92
+ BASE="$FILE_VER"
93
+ else
94
+ BASE="3.0.0"
56
95
  fi
57
96
 
58
- echo "🔎 Release detectada: $TAG_RELEASE"
97
+ BASE="$(echo "$BASE" | tr -d '[:space:]')"
98
+ IFS='.' read -r MAJ MIN PAT <<< "$(echo "$BASE")"
99
+ MAJ=${MAJ:-0}; MIN=${MIN:-0}; PAT=${PAT:-0}
59
100
 
60
- # valores atuais
61
- PKG_VER=$(jq -r '.version' package.json)
62
- JSON_REL=$(jq -r '.version[0].release' version.json)
63
- JSON_PATCH=$(jq -r '.version[0].patch' version.json || true)
101
+ echo "🔍 Base de versão: ${MAJ}.${MIN}.${PAT}"
64
102
 
65
- echo "📦 package.json.version = $PKG_VER"
66
- echo "🧩 version.json.release = $JSON_REL"
67
- echo "🕒 version.json.patch = $JSON_PATCH"
103
+ if [ "${{ steps.detect.outputs.DB_CHANGED }}" = "true" ]; then
104
+ echo "🔼 mwsm.db mudou — incrementando versão."
105
+ if [ "$PAT" -lt 99 ]; then
106
+ PAT=$((PAT + 1))
107
+ else
108
+ PAT=0
109
+ if [ "$MIN" -lt 99 ]; then
110
+ MIN=$((MIN + 1))
111
+ else
112
+ MIN=0
113
+ MAJ=$((MAJ + 1))
114
+ fi
115
+ fi
116
+ fi
68
117
 
69
- PATCH=$(TZ="America/Sao_Paulo" date +"%Y-%m-%d %H:%M:%S")
118
+ NEW_VER="${MAJ}.${MIN}.${PAT}"
70
119
 
71
- # 4) Atualiza somente se houver tag válida (não grava vazios)
72
- jq --arg v "$TAG_RELEASE" --arg d "$PATCH" \
120
+ jq --arg v "$NEW_VER" --arg d "$PATCH" \
73
121
  '.version[0].release=$v | .version[0].patch=$d' version.json > version.tmp && mv version.tmp version.json
74
122
 
75
- jq --arg v "$TAG_RELEASE" '.version=$v' package.json > package.tmp && mv package.tmp package.json
123
+ # normaliza o package.json: força name para 'bot-mwsm' (resolverá o 403 do npm por case)
124
+ jq --arg v "$NEW_VER" --arg name "bot-mwsm" \
125
+ '.version=$v | .name=$name' package.json > package.tmp && mv package.tmp package.json
76
126
 
77
- echo "release=$TAG_RELEASE" >> "$GITHUB_OUTPUT"
127
+ echo "version=$NEW_VER" >> "$GITHUB_OUTPUT"
78
128
  echo "patch=$PATCH" >> "$GITHUB_OUTPUT"
79
- echo "updated=true" >> "$GITHUB_OUTPUT"
80
129
 
81
- - name: 🕒 Converter patch (americano → brasileiro)
82
- id: datefmt
130
+ - name: 🪶 Atualizar badges no README.md
83
131
  run: |
84
- PATCH="${{ steps.detect.outputs.patch }}"
85
- if [ -n "$PATCH" ]; then
86
- DATE_BR=$(date -d "$PATCH" +"%d/%m/%Y %H:%M")
87
- echo "formatted=$DATE_BR" >> $GITHUB_OUTPUT
88
- else
89
- echo "formatted=" >> $GITHUB_OUTPUT
90
- fi
91
-
92
- - name: 📝 Atualizar badges no README.md
93
- if: steps.detect.outputs.updated == 'true'
94
- run: |
95
- # -------------------------------
96
- # 🔹 Carrega versão e data formatada
97
- # -------------------------------
98
- RELEASE="${{ steps.detect.outputs.release }}"
99
- [ -z "$RELEASE" ] && RELEASE=$(jq -r '.version' package.json)
100
-
101
- DATE_BR="${{ steps.datefmt.outputs.formatted }}"
132
+ VERSION="${{ steps.version.outputs.version }}"
133
+ PATCH="${{ steps.version.outputs.patch }}"
134
+ DATE_BR=$(date -d "$PATCH" +"%d/%m/%Y %H:%M")
102
135
  DATE_URL=${DATE_BR//\//%2F}
103
136
  DATE_URL=${DATE_URL// /%20}
104
137
 
105
- echo "🪶 Atualizando badges -> BUILD-${RELEASE} / UPDATE-${DATE_BR}"
106
-
107
- # -------------------------------
108
- # 🔹 Atualiza badges de BUILD e UPDATE
109
- # -------------------------------
110
- sed -i -E "s|https://img.shields.io/badge/[Bb][Uu][Ii][Ll][Dd]-[^\" >]*|https://img.shields.io/badge/Build-${RELEASE}-blue|gI" README.md
111
- sed -i -E "s|https://img.shields.io/badge/[Uu][Pp][Dd][Aa][Tt][Ee]-[^\" >]*|https://img.shields.io/badge/Update-${DATE_URL}-green|gI" README.md
112
-
113
- # -------------------------------
114
- # 🔧 Corrige apenas src de badges (mantendo HTML e indentação)
115
- # -------------------------------
116
- # -------------------------------
117
- # 🔧 Corrige badges mantendo HTML, espaçamento e evita duplicações
118
- # -------------------------------
119
- awk '
120
- match($0, /src="([^"]*img\.shields\.io[^"]*)"/, m) {
121
- url = m[1]
122
-
123
- # Normaliza o URL (remove duplicações, erros, etc.)
124
- gsub(/\?style=for-the-badge/, "", url)
125
- gsub(/&style=for-the-badge/, "", url)
126
-
127
- # Corrige escapes comuns
128
- gsub(/\\\?/, "?", url)
129
- gsub(/\\&/, "&", url)
130
- gsub(/\\%2F/, "%2F", url)
131
- gsub(/\\%20/, "%20", url)
132
-
133
- # Se o style não existe, adiciona corretamente
134
- if (url !~ /\?/) {
135
- url = url "?style=for-the-badge"
136
- } else if (url !~ /[?&]style=for-the-badge/) {
137
- url = url "&style=for-the-badge"
138
- }
139
-
140
- # Garante que não repita
141
- gsub(/\?style=for-the-badge\?style=for-the-badge/, "?style=for-the-badge", url)
142
- gsub(/&style=for-the-badge&style=for-the-badge/, "&style=for-the-badge", url)
143
-
144
- # Reconstrói a linha preservando indentação (10 espaços fixos)
145
- prefix = substr($0, 1, match($0, /<img/) - 1)
146
- printf "%10s<img src=\"%s\" alt=\"%s\">\n", "", url, "Badge"
147
- next
148
- }
149
- { print }
150
- ' README.md > README.tmp && mv README.tmp README.md
151
-
152
- - name: ⏱️ Delay de segurança
153
- if: steps.detect.outputs.updated == 'true'
154
- run: |
155
- echo "⏳ Aguardando 10 segundos antes do commit/push..."
156
- sleep 10
157
-
158
- - name: 🔍 Verificar resultado final
159
- run: |
160
- echo "🧾 Trecho atualizado do README:"
161
- grep "img.shields.io" README.md | head -n 10
138
+ sed -i -E "s|https://img.shields.io/badge/Build-[^\" >]*|https://img.shields.io/badge/Build-${VERSION}-blue?style=for-the-badge|gI" README.md
139
+ sed -i -E "s|https://img.shields.io/badge/Update-[^\" >]*|https://img.shields.io/badge/Update-${DATE_URL}-green?style=for-the-badge|gI" README.md
162
140
 
163
141
  - name: 💾 Commit e push das alterações
164
- if: steps.detect.outputs.updated == 'true'
165
142
  env:
166
143
  PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
167
144
  run: |
168
145
  set -e
169
- echo "💾 Preparando commit..."
170
146
  git config --global user.name "Bot-Mwsm 🤖"
171
147
  git config --global user.email "143403919+MKCodec@users.noreply.github.com"
172
148
  git config --global commit.gpgsign false
173
149
 
174
- # Evita erro de rebase (unstaged changes)
175
- git stash --include-untracked || true
176
- git pull --rebase origin main || true
177
- git stash pop || true
178
-
179
- git add README.md package.json version.json
150
+ git add README.md package.json version.json || true
180
151
 
181
152
  if git diff --cached --quiet; then
182
- echo "✅ Nenhuma alteração detectada — encerrando."
153
+ echo "✅ Nenhuma alteração detectada — nada a commitar."
183
154
  else
184
- echo "🔄 Commitando e enviando alterações..."
185
155
  git commit -m "🔄 Bot-Mwsm"
186
156
  git push https://x-access-token:${PERSONAL_TOKEN}@github.com/${{ github.repository }}.git main
187
157
  fi
188
158
 
159
+ - name: 🚀 Criar release/tag automática (se banco mudou)
160
+ if: steps.detect.outputs.DB_CHANGED == 'true'
161
+ env:
162
+ GH_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
163
+ run: |
164
+ TAG="v${{ steps.version.outputs.version }}"
165
+ gh release create "$TAG" --title "$TAG" --notes "Release automático do Bot-Mwsm" || echo "⚠️ Release já existente — ignorando."
166
+
167
+ - name: 🔄 Garantir sincronismo antes do publish
168
+ run: |
169
+ git pull origin main --rebase || true
170
+ echo "Versão package.json:" $(jq -r .version package.json)
171
+ echo "Versão version.json:" $(jq -r '.version[0].release // .version' version.json)
172
+
173
+ - name: 🧩 Verificar autenticação NPM (OIDC ping)
174
+ run: |
175
+ set -e
176
+ echo "🔍 Verificando conectividade com registry (OIDC test via npm ping)..."
177
+ if npm ping >/dev/null 2>&1; then
178
+ echo "✅ npm ping ok (pode usar OIDC se configurado)."
179
+ else
180
+ echo "⚠️ npm ping falhou — verifique Trusted Publisher no npmjs.com."
181
+ # não falha aqui; deixamos o publish tentar e fallback por token cuidar do resto
182
+ fi
183
+
184
+ - name: ⚙️ Setup Node (garante npm atualizado e registry)
185
+ uses: actions/setup-node@v4
186
+ with:
187
+ node-version: '20'
188
+ registry-url: 'https://registry.npmjs.org'
189
+
190
+ - name: 🔍 Mostrar versões antes do publish
191
+ run: |
192
+ node --version
193
+ npm --version
194
+ echo "package.json version:" $(jq -r .version package.json)
195
+ echo "version.json release:" $(jq -r '.version[0].release // .version' version.json)
196
+
197
+ - name: 📦 Publicar no NPM (Trusted Publisher - OIDC)
198
+ id: publish_oidc
199
+ continue-on-error: true
200
+ run: |
201
+ set -e
202
+ echo "📦 Tentando publicar via OIDC (Trusted Publisher)..."
203
+ VERSION=$(jq -r '.version[0].release // .version' version.json)
204
+ # já normalizamos name e version no passo anterior
205
+ jq --arg v "$VERSION" '.version=$v' package.json > package.tmp && mv package.tmp package.json
206
+
207
+ # instalar dependências caso necessário para build (não deve afetar publish)
208
+ npm ci --no-audit --no-fund || true
209
+
210
+ PUBLISHED=$(npm view bot-mwsm version 2>/dev/null || echo "")
211
+ if [ "$PUBLISHED" = "$VERSION" ]; then
212
+ echo "⚠️ Versão $VERSION já está publicada no npm — pulando publish."
213
+ exit 0
214
+ fi
215
+
216
+ # publish: se trusted publisher estiver configurado no npm, o runner usará OIDC
217
+ npm publish --provenance --access public
218
+
219
+ - name: 📦 Fallback publish via NPM_TOKEN (se OIDC falhar)
220
+ if: ${{ steps.publish_oidc.outcome == 'failure' }}
221
+ env:
222
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
223
+ run: |
224
+ set -e
225
+ echo "⚠️ Publicação via OIDC falhou — tentando fallback com NPM_TOKEN..."
226
+ VERSION=$(jq -r '.version[0].release // .version' version.json)
227
+
228
+ if [ -z "${NPM_TOKEN:-}" ]; then
229
+ echo "❌ NPM_TOKEN não encontrado nas secrets. Aborting."
230
+ exit 1
231
+ fi
232
+
233
+ # configura token para registry
234
+ npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
235
+
236
+ # re-check published just in case
237
+ PUBLISHED=$(npm view bot-mwsm version 2>/dev/null || echo "")
238
+ if [ "$PUBLISHED" = "$VERSION" ]; then
239
+ echo "⚠️ Versão $VERSION já publicada (detected after fallback check) — nada a fazer."
240
+ exit 0
241
+ fi
242
+
243
+ echo "🔁 Publicando versão $VERSION via token..."
244
+ npm publish --access public || {
245
+ echo "❌ Falha total no publish, mesmo com fallback."
246
+ exit 1
247
+ }
248
+ echo "✅ Publicação via token concluída com sucesso!"
249
+
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  <h1 align="center">📦 MkAuth WhatsApp Send Message (Mwsm)</h1>
2
2
  <p align="center">
3
3
  <a href="javascript:void(0)">
4
- <img src="https://img.shields.io/badge/Build-3.0.1-blue?style=for-the-badge" alt="Badge">
4
+ <img src="https://img.shields.io/badge/Build-3.0.2-blue?style=for-the-badge" alt="Badge">
5
5
  </a>
6
6
  <a href="javascript:void(0)">
7
- <img src="https://img.shields.io/badge/Update-14%2F10%2F2025%2020:44-green?style=for-the-badge" alt="Badge">
7
+ <img src="https://img.shields.io/badge/Update-15%2F10%2F2025%2013:20-green?style=for-the-badge" alt="Badge">
8
8
  </a>
9
9
  <a href="https://github.com/MKCodec/Mwsm">
10
10
  <img src="https://img.shields.io/github/stars/MKCodec/Mwsm?style=for-the-badge" alt="Badge">
package/mwsm.py CHANGED
@@ -37,10 +37,6 @@ logging.basicConfig(
37
37
  level=logging.INFO,
38
38
  format="%(asctime)s - %(message)s",
39
39
  )
40
-
41
- # =========================================
42
- # CONFIGURAÇÃO HUGGINGFACE
43
- # =========================================
44
40
  if not os.environ.get("HF_ENDPOINT"):
45
41
  os.environ["HF_ENDPOINT"] = "https://huggingface.co"
46
42
  os.environ["HF_HUB_OFFLINE"] = "0"
@@ -52,10 +48,6 @@ constants.HUGGINGFACE_CO_URL_TEMPLATE = f"{os.environ['HF_ENDPOINT']}/{{repo_id}
52
48
  log("Endpoint Hugging Face: https://huggingface.co")
53
49
  log(f"_CACHED_API_URL: {fd._CACHED_API_URL}")
54
50
  log(f"HUGGINGFACE_CO_URL_TEMPLATE: {constants.HUGGINGFACE_CO_URL_TEMPLATE}")
55
-
56
- # =========================================
57
- # CARREGAMENTO DO MODELO
58
- # =========================================
59
51
  log("Loading SentenceTransformer model...")
60
52
  try:
61
53
  model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
@@ -63,16 +55,10 @@ try:
63
55
  except Exception as e:
64
56
  log(f"Model loading failed: {e}", level="error")
65
57
  sys.exit(1)
66
-
67
- # =========================================
68
- # SERVIDOR FLASK
69
- # =========================================
70
58
  app = Flask(__name__)
71
-
72
59
  @app.route("/", methods=["GET"])
73
60
  def home():
74
61
  return jsonify({"status": "online", "model": "all-MiniLM-L6-v2"}), 200
75
-
76
62
  @app.route("/embed", methods=["POST"])
77
63
  def embed():
78
64
  data = request.json or {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bot-mwsm",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Bot-Mwsm: based on Whatsapp API",
5
5
  "main": "mwsm.js",
6
6
  "scripts": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "axios": "^1.6.8",
36
- "Emoji-API": "git+https://github.com/MKCodec/Emoji-API.git",
36
+ "Emoji-API": "git+https://github.com/MKCodec/Emoji-API",
37
37
  "express": "^4.19.2",
38
38
  "express-fileupload": "^1.5.0",
39
39
  "express-validator": "^7.0.1",
@@ -43,20 +43,13 @@
43
43
  "node-cron": "^3.0.3",
44
44
  "qrcode": "^1.5.3",
45
45
  "socket.io": "^2.5.0",
46
- "Url2PDF": "git+https://github.com/MKCodec/Url2PDF.git",
46
+ "Url2PDF": "git+https://github.com/MKCodec/Url2PDF",
47
47
  "util": "^0.12.5",
48
- "whatsapp-web.js": "latest"
48
+ "whatsapp-web.js": "^1.34.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "better-sqlite3": "^9.4.3",
52
52
  "nodemon": "^3.1.0",
53
53
  "sqlite3": "^5.1.7"
54
- },
55
- "directories": {
56
- "doc": "docs"
57
- },
58
- "bugs": {
59
- "url": "https://github.com/MKCodec/Mwsm/issues"
60
- },
61
- "homepage": "https://github.com/MKCodec/Mwsm#readme"
54
+ }
62
55
  }
package/version.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "version": [
3
3
  {
4
- "release": "3.0.1",
5
- "patch": "2025-10-14 20:44:00"
4
+ "release": "3.0.2",
5
+ "patch": "2025-10-15 13:20:07"
6
6
  }
7
- ]
7
+ ],
8
+ "patch": "2025-10-15 13:01:26"
8
9
  }
@@ -1,62 +0,0 @@
1
- name: 📦 Mwsm Publish Sync
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- workflow_dispatch:
7
-
8
- permissions:
9
- contents: read
10
- id-token: write # necessário para OIDC / Trusted Publisher
11
-
12
- jobs:
13
- publish:
14
- runs-on: ubuntu-latest
15
- steps:
16
- - name: 🧩 Checkout do repositório
17
- uses: actions/checkout@v4
18
-
19
- - name: ⚙️ Instalar jq (para editar package.json)
20
- run: sudo apt-get update && sudo apt-get install -y jq
21
-
22
- - name: 🧱 Corrigir nome do pacote temporariamente
23
- run: |
24
- cp package.json package_original.json
25
- NAME=$(jq -r '.name' package.json)
26
- LOWER=$(echo "$NAME" | tr '[:upper:]' '[:lower:]')
27
- if [ "$NAME" != "$LOWER" ]; then
28
- echo "🔧 Corrigindo nome do pacote: $NAME → $LOWER"
29
- jq --arg name "$LOWER" '.name = $name' package.json > tmp.json && mv tmp.json package.json
30
- else
31
- echo "✅ Nome já está em minúsculas: $NAME"
32
- fi
33
- jq '.name' package.json
34
-
35
- - name: ⚙️ Configurar Node.js (Trusted Publisher)
36
- uses: actions/setup-node@v4
37
- with:
38
- node-version: 20
39
- registry-url: 'https://registry.npmjs.org/'
40
- always-auth: true
41
-
42
- - name: 📦 Instalar dependências
43
- run: |
44
- if [ -f package-lock.json ]; then
45
- npm ci --no-audit --no-fund
46
- else
47
- npm install --no-audit --no-fund
48
- fi
49
-
50
- - name: 🚀 Publicar no npm (via OIDC / Trusted Publisher)
51
- run: |
52
- echo "🛰️ Publicando pacote via OIDC..."
53
- npm publish --access public
54
- continue-on-error: false
55
-
56
- - name: ♻️ Restaurar package.json original
57
- if: always()
58
- run: |
59
- if [ -f package_original.json ]; then
60
- mv -f package_original.json package.json
61
- echo "♻️ package.json restaurado ao original"
62
- fi