Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/publish-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish Package on Tag

on:
push:
tags:
- 'v*' # This will trigger on any tag that starts with 'v'

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@richardgaunt'

- name: Install dependencies
run: npm ci

- name: Lint code
run: npm run lint

- name: Run tests
run: npm test

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

- name: Check package.json version matches tag
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "Error: Tag version ($VERSION) does not match package.json version ($PKG_VERSION)"
exit 1
fi

- name: Publish to GitHub Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ env.VERSION }}
body: |
## Changes in this Release

- See the [CHANGELOG.md](./CHANGELOG.md) for details

## Installation

```bash
# Install from GitHub Packages
npm install -g @richardgaunt/cli-maker

# Or use with npx
npx @richardgaunt/cli-maker my-cli-app
```
draft: false
Comment on lines +55 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove trailing spaces to satisfy YAMLlint
YAMLlint errors are reported for trailing spaces in the release body. Here's a diff to strip them:

-          body: |
-            ## Changes in this Release 
-            
-            - See the [CHANGELOG.md](./CHANGELOG.md) for details 
-            
-            ## Installation 
-            
-            ```bash
-            # Install from GitHub Packages 
-            npm install -g @richardgaunt/cli-maker 
-            
-            # Or use with npx 
-            npx @richardgaunt/cli-maker my-cli-app 
-            ```
+          body: |
+            ## Changes in this Release
+
+            - See the [CHANGELOG.md](./CHANGELOG.md) for details
+
+            ## Installation
+
+            ```bash
+            # Install from GitHub Packages
+            npm install -g @richardgaunt/cli-maker
+
+            # Or use with npx
+            npx @richardgaunt/cli-maker my-cli-app
+            ```
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 57-57: trailing spaces

(trailing-spaces)


[error] 59-59: trailing spaces

(trailing-spaces)


[error] 61-61: trailing spaces

(trailing-spaces)


[error] 65-65: trailing spaces

(trailing-spaces)

prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish Package to GitHub Packages

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@richardgaunt'
- run: npm ci
- run: npm test
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - YYYY-MM-DD

### Added
- Initial release of the CLI app generator
- Command-line interface for scaffolding new CLI applications
- Interactive prompts for project configuration
- Support for common CLI features (Commander.js, Inquirer)
- Robust testing framework for interactive CLI applications
- ESLint configuration for code quality
- Git initialization and npm dependency installation
- Comprehensive documentation and examples

### Changed
- N/A (initial release)

### Fixed
- N/A (initial release)
51 changes: 51 additions & 0 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Add GitHub Action for Tag-Based Package Publishing

## Summary

This PR adds a GitHub Action workflow that automatically publishes the package to GitHub Packages whenever a new tag is pushed. This streamlines the release process by eliminating manual publishing steps and ensures consistency in our package deployment pipeline.

## Changes

- Add GitHub Action workflow to publish package when a new tag is pushed (`publish-on-tag.yml`)
- Add basic test workflow to run tests on all PRs and pushes to main branch (`test.yml`)
- Create CHANGELOG.md for tracking releases
- Update package.json with version management scripts and pre-publish hooks
- Update documentation on the publishing process

## Testing Done

- Validated workflow file syntax
- Confirmed GitHub token permissions are set correctly
- Tested version bump scripts locally
- Verified proper tag detection in workflow

## Documentation

This PR includes comprehensive documentation updates:

- PUBLISHING.md updated with tag-based workflow instructions
- Added version bump commands to simplify the release process
- Added CHANGELOG.md to track release history

## Checklist

- [x] GitHub Action workflow files are syntactically valid
- [x] Workflow has proper permissions to publish packages
- [x] Documentation is clear and comprehensive
- [x] Added version bump scripts for easy versioning
- [x] Set up proper pre-publish hooks to ensure quality

## How to Test

1. After merging, create a new version with:
```bash
npm run version:patch
git push origin main --tags
```

2. Check that the workflow runs automatically and publishes the package to GitHub Packages

3. Verify the package can be installed with:
```bash
npm install -g @richardgaunt/cli-maker
```
151 changes: 151 additions & 0 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Publishing to GitHub Packages

This document provides instructions for publishing this package to GitHub Packages.

## Prerequisites

1. GitHub account with permissions to publish to the repository
2. Personal access token with the appropriate scopes (write:packages, read:packages) if publishing manually

## Automated Publishing with Tags

This repository is configured to automatically publish to GitHub Packages whenever a new Git tag is pushed. The process is handled by the GitHub Actions workflow at `.github/workflows/publish-on-tag.yml`.

### Publishing Process

1. **Update CHANGELOG.md**: Document your changes in the CHANGELOG.md file

2. **Bump Version**: Use one of the following commands to update the version number:
```bash
# For bug fixes
npm run version:patch # e.g., 1.0.0 -> 1.0.1

# For new features
npm run version:minor # e.g., 1.0.0 -> 1.1.0

# For breaking changes
npm run version:major # e.g., 1.0.0 -> 2.0.0
```
This will:
- Update the version in package.json
- Create a Git tag for the new version
- Create a version commit

3. **Push Tag**: Push the newly created tag to trigger the workflow
```bash
git push origin v1.0.0 # Replace with your actual version
```

4. **Monitor Workflow**: Check the GitHub Actions tab to monitor the publishing process

5. **Verify Package**: Once published, verify the package is available on GitHub Packages

## CI/CD Workflows

### 1. Testing Workflow

The repository includes a continuous integration workflow that runs on all pushes to main and pull requests:

```yaml
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm test
```

### 2. Publishing Workflow

The tag-based publishing workflow is defined in `.github/workflows/publish-on-tag.yml`:

```yaml
name: Publish Package on Tag

on:
push:
tags:
- 'v*' # This will trigger on any tag that starts with 'v'

jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@richardgaunt'

# Additional steps...
```

## Using the Published Package

After publishing, you can install the package with:

```bash
npm install -g @richardgaunt/cli-maker
```

Or use it directly with npx:

```bash
npx @richardgaunt/cli-maker my-cli-app
```

## Local Testing Before Publishing

Before publishing, you can test the package locally:

1. Link the package locally:
```bash
npm link
```

2. Create a test CLI app:
```bash
cli-maker test-app
```

3. Verify the generated project works as expected

## Manual Publishing

If you prefer to publish manually:

1. Set up authentication for GitHub Packages:
```bash
echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" > ~/.npmrc
echo "@richardgaunt:registry=https://npm.pkg.github.com" >> ~/.npmrc
```

2. Publish the package:
```bash
npm publish
```
Loading