Skip to content

Commit c6c72ec

Browse files
committed
Replace manual publishing with GitHub Actions workflow
1 parent ae59bf5 commit c6c72ec

2 files changed

Lines changed: 51 additions & 72 deletions

File tree

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Package to GitHub Packages
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: '18.x'
18+
registry-url: 'https://npm.pkg.github.com'
19+
scope: '@aashari'
20+
- run: npm ci
21+
- run: npm test
22+
- run: npm publish
23+
env:
24+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

PUBLISHING.md

Lines changed: 27 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,40 @@
11
# Publishing to GitHub Packages
22

3-
This guide explains how to publish this package to GitHub Packages.
3+
This package is automatically published to GitHub Packages using GitHub Actions.
44

5-
## Method 1: Using GitHub CLI (Recommended)
5+
## Automatic Publishing with GitHub Actions
66

7-
If you have the GitHub CLI installed, you can use it to authenticate and publish the package:
7+
The package is automatically published to GitHub Packages whenever a new GitHub Release is created. The workflow is defined in `.github/workflows/publish.yml`.
88

9-
1. Make sure you're logged in to GitHub CLI:
10-
```bash
11-
gh auth status
12-
```
9+
### How to Publish a New Version
1310

14-
2. If not logged in, authenticate:
15-
```bash
16-
gh auth login
17-
```
11+
1. Update the version in `package.json`
12+
2. Commit and push your changes
13+
3. Create a new tag:
14+
```bash
15+
git tag -a vX.Y.Z -m "Version X.Y.Z"
16+
git push origin vX.Y.Z
17+
```
18+
4. Create a new release on GitHub:
19+
```bash
20+
gh release create vX.Y.Z --title "Version X.Y.Z" --notes "Release notes for version X.Y.Z"
21+
```
1822

19-
3. Create a temporary .npmrc file with your GitHub token:
20-
```bash
21-
echo "@aashari:registry=https://npm.pkg.github.com" > .npmrc
22-
echo "//npm.pkg.github.com/:_authToken=$(gh auth token)" >> .npmrc
23-
```
24-
25-
4. Publish the package:
26-
```bash
27-
npm publish
28-
```
29-
30-
5. After publishing, you can remove the token from your .npmrc file:
31-
```bash
32-
echo "@aashari:registry=https://npm.pkg.github.com" > .npmrc
33-
```
34-
35-
## Method 2: Using Personal Access Token (PAT)
36-
37-
If you don't have GitHub CLI, you can use a Personal Access Token:
38-
39-
### Prerequisites
40-
41-
1. You need a GitHub Personal Access Token (PAT) with the following scopes:
42-
- `read:packages`
43-
- `write:packages`
44-
- `delete:packages`
45-
- `repo`
46-
47-
### Setup
48-
49-
1. Create a `.npmrc` file in your home directory:
50-
51-
```bash
52-
echo "@aashari:registry=https://npm.pkg.github.com" > ~/.npmrc
53-
echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT" >> ~/.npmrc
54-
```
55-
56-
Replace `YOUR_GITHUB_PAT` with your GitHub Personal Access Token.
57-
58-
2. Create a `.npmrc` file in the project directory:
59-
60-
```bash
61-
echo "@aashari:registry=https://npm.pkg.github.com" > .npmrc
62-
```
63-
64-
### Publishing
65-
66-
Once you have set up authentication, you can publish the package:
67-
68-
```bash
69-
npm publish
70-
```
23+
The GitHub Actions workflow will automatically build, test, and publish the package to GitHub Packages.
7124

7225
## Consuming the Package
7326

74-
To use this package in another project, add the following to your project's `.npmrc` file:
27+
To use this package in another project:
7528

76-
```
77-
@aashari:registry=https://npm.pkg.github.com
78-
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT
79-
```
29+
1. Create a `.npmrc` file in your project with:
30+
```
31+
@aashari:registry=https://npm.pkg.github.com
32+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
33+
```
8034

81-
Then install the package:
35+
2. Install the package:
36+
```bash
37+
npm install @aashari/nodejs-geocoding
38+
```
8239

83-
```bash
84-
npm install @aashari/nodejs-geocoding
85-
```
40+
Replace `YOUR_GITHUB_TOKEN` with a GitHub Personal Access Token that has the `read:packages` scope.

0 commit comments

Comments
 (0)