-
Notifications
You must be signed in to change notification settings - Fork 0
Added publishing workflows and instructions for creating packages. #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
richardgaunt
wants to merge
1
commit into
main
Choose a base branch
from
feature/add-publishing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 | ||
| prerelease: false | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
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
| 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}} |
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
| 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) |
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
| 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 | ||
| ``` |
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
| 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 | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove trailing spaces to satisfy YAMLlint
YAMLlint errors are reported for trailing spaces in the release body. Here's a diff to strip them:
🧰 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)