1+ name : Publish Package
2+
3+ on :
4+ release :
5+ types : [created]
6+
7+ jobs :
8+ verify :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - uses : actions/checkout@v3
12+
13+ - name : Use Node.js
14+ uses : actions/setup-node@v3
15+ with :
16+ node-version : ' >=18.0.0'
17+ cache : ' npm'
18+
19+ - name : Install dependencies
20+ run : npm ci
21+
22+ - name : Lint
23+ run : npm run lint
24+
25+ - name : Lint Fix
26+ run : npm run lint:fix
27+
28+ - name : Format
29+ run : npm run format
30+
31+ - name : Test
32+ run : npm test
33+
34+ - name : Test Coverage
35+ run : npm run test:coverage
36+
37+ - name : Check package version
38+ run : |
39+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
40+ TAG_VERSION=${GITHUB_REF#refs/tags/v}
41+ if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
42+ echo "::error::Package version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)"
43+ exit 1
44+ fi
45+
46+ build-and-publish-npm :
47+ needs : verify
48+ runs-on : ubuntu-latest
49+
50+ steps :
51+ - uses : actions/checkout@v3
52+
53+ - name : Use Node.js
54+ uses : actions/setup-node@v3
55+ with :
56+ node-version : ' >=18.0.0'
57+ registry-url : ' https://registry.npmjs.org'
58+ cache : ' npm'
59+
60+ - name : Install dependencies
61+ run : npm ci
62+
63+ - name : Build
64+ run : npm run build
65+
66+ - name : Publish to NPM
67+ run : npm publish --access public
68+ env :
69+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
70+
71+ notify :
72+ needs : [build-and-publish-npm]
73+ runs-on : ubuntu-latest
74+ if : success()
75+
76+ steps :
77+ - uses : actions/checkout@v3
78+
79+ - name : Get package info
80+ id : package
81+ run : |
82+ echo "name=$(node -p "require('./package.json').name")" >> $GITHUB_OUTPUT
83+ echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
84+
85+ - name : Create GitHub Release Summary
86+ run : |
87+ echo "## :rocket: Nova versão publicada com sucesso!" >> $GITHUB_STEP_SUMMARY
88+ echo "* **Pacote:** ${{ steps.package.outputs.name }}" >> $GITHUB_STEP_SUMMARY
89+ echo "* **Versão:** ${{ steps.package.outputs.version }}" >> $GITHUB_STEP_SUMMARY
90+ echo "* **Publicado em:** npm e GitHub Packages" >> $GITHUB_STEP_SUMMARY
91+ echo "* **Data:** $(date)" >> $GITHUB_STEP_SUMMARY
0 commit comments