Introduction
In this guide, you'll create a GitHub Actions workflow to test your code and then publish it to Paquetes de GitHub.
Publishing your package
-
Create a new repository on GitHub, adding the
.gitignorefor Node. For more information, see "Creating a new repository." -
Clone the repository to your local machine.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git $ cd YOUR-REPOSITORY -
Create an
index.jsfile and add a basic alert to say "Hello world!"JavaScript alert("Hello, World!"); -
Initialize an npm package with
npm init. In the package initialization wizard, enter your package with the name:@YOUR-USERNAME/YOUR-REPOSITORY, and set the test script toexit 0. This will generate apackage.jsonfile with information about your package.$ npm init ... package name: @YOUR-USERNAME/YOUR-REPOSITORY ... test command: exit 0 ...
-
Run
npm installto generate thepackage-lock.jsonfile, then commit and push your changes to GitHub.$ npm install $ git add index.js package.json package-lock.json $ git commit -m "initialize npm package" $ git push -
Create a
.github/workflowsdirectory. In that directory, create a file namedrelease-package.yml. -
Copy the following YAML content into the
release-package.ymlfile.YAML name: Node.js Package on: release: types: [created] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: 12 - run: npm ci - run: npm test publish-gpr: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: 12 registry-url: https://npm.pkg.github.com/ - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} -
Commit and push your changes to GitHub.
$ git add .github/workflows/release-package.yml $ git commit -m "workflow to publish package" $ git push -
The workflow that you created will run whenever a new release is created in your repository. If the tests pass, then the package will be published to Paquetes de GitHub.
To test this out, navigate to the Code tab in your repository and create a new release. For more information, see "Managing releases in a repository."
Viewing your published package
Packages are published at the repository level. You can see all the packages in a repository and search for a specific package.
-
En GitHub, visita la página principal del repositorio.
-
A la derecha de la lista de archivos, da clic en Paquetes.

-
Da clic en el nombre del paquete que quieres ver.

Installing a published package
Now that you've published the package, you'll want to use it as a dependency across your projects. For more information, see "Configuring npm for use with Paquetes de GitHub."
Next steps
The basic workflow you just added runs any time a new release is created in your repository. But, this is only the beginning of what you can do with Paquetes de GitHub. You can publish your package to multiple registries with a single workflow, trigger the workflow to run on different events such as a merged pull request, manage containers, and more.
Combining Paquetes de GitHub and GitHub Actions can help you automate nearly every aspect of your application development processes. Ready to get started? Here are some helpful resources for taking your next steps with Paquetes de GitHub and GitHub Actions:
- "Learn Paquetes de GitHub" for an in-depth tutorial on GitHub Packages
- "Learn GitHub Actions" for an in-depth tutorial on GitHub Actions
- "Guides" for specific uses cases and examples