Skip to content
ChaiBytes

How to use GitHub Actions to publish your first package

Learn how to use GitHub Actions and GitHub Packages to automatically test and publish your Node.js projects online.

By Ali RazaOfficial admin

2 min read 2 views

Share

What you need

To follow this guide, you will need a GitHub account and a local machine where you can run commands. You will also need to have Node.js and npm installed to manage your project files.

Step by step

  1. Create a new repository on GitHub Start by making a new space on GitHub to hold your project. When setting this up, add a “.gitignore” file specifically for Node to ensure unnecessary files stay off the internet.

  2. Clone the repository to your local machine Download a copy of your new GitHub repository onto your own computer so you can work on it locally.

  3. Create an index.js file Make a new file named “index.js” in your project folder. Example: If you are building a tiny “Hello World” project, you might add a simple alert inside this file to test that it works.

  4. Initialize your npm package Run the command npm init in your terminal. A wizard will guide you through the setup. When asked for the package name, use the format @YOUR-USERNAME/YOUR-REPOSITORY and set your test script to exit 0.

  5. Generate your package files Run npm install to create a “package-lock.json” file. This file helps keep track of your project’s dependencies.

  6. Commit and push your changes Save your work locally and send the updated files back up to your GitHub repository.

  7. Set up the workflow directory Create a folder named “.github” and inside that, create another folder named “workflows”.

  8. Create the release file Inside that “workflows” folder, create a new file called “release-package.yml”.

  9. Add the configuration content Copy your specific YAML instructions into the “release-package.yml” file to tell GitHub how to handle your code.

  10. Configure your registry settings You must tell npm where to publish your work. You can do this by creating a “.npmrc” file in your main folder or by adding a “publishConfig” key directly into your “package.json” file.

  11. Create a new release To trigger the automation, go to the “Code” tab of your repository on GitHub and create a new release. If your tests pass, your package will be published to GitHub Packages automatically.

  12. View your published package Go to your repository’s main page on GitHub. Look at the right-hand sidebar and click on “Packages”. You can then search for and click your package name to see the details.

Tips and common mistakes

  • Check your naming: Ensure your package name follows the @username/repository format during the npm init step, or the publishing process might not work as expected.
  • Automation triggers: Remember that the workflow you set up is designed to run specifically when a new release is created. If you just upload code without making a release, the package might not publish.

Use it responsibly

Always check the answers and code generated by AI tools to ensure they are correct for your specific project. Protect your privacy by never uploading sensitive information, such as private passwords or personal data, to a public repository. Finally, ensure you are following the terms of service for GitHub and any rules set by your school or workplace when using these developer tools.

Sources

  1. 1. Quickstart for GitHub Packages - GitHub Docs — GitHub Docs

Drafted with AI assistance from the reports above and checked automatically for sourcing. Always confirm dates, fees and requirements on the official website before acting.

Was this helpful?

Comments

No comments yet. Share a question or what you know.

Leave a comment

Be respectful. Comments with links are reviewed before they appear. Your email is used only to contact you about your comment.