Created
March 5, 2025 12:27
-
-
Save carloscarucce/295b443be045cae37bd1c962b1d80f44 to your computer and use it in GitHub Desktop.
GithubAction para publicação de pacotes npm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usa a versão específica do Node que está no .nvmrc | |
FROM node:20.11.1-slim | |
WORKDIR /app | |
# Copia os arquivos | |
COPY . . | |
# Instala as dependências e builda o projeto | |
RUN yarn install --frozen-lockfile | |
RUN yarn build | |
# Configura o NPM para usar o token | |
ARG NPM_TOKEN | |
RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc | |
# Publica o pacote | |
CMD ["npm", "publish"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Package | |
on: | |
release: | |
types: [published] | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and Publish | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
docker build \ | |
--build-arg NPM_TOKEN=${NPM_TOKEN} \ | |
-f Dockerfile.publish \ | |
-t npm-publisher . | |
docker run npm-publisher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment