diff --git a/.github/workflows/changelog-local.yml b/.github/workflows/changelog-local.yml new file mode 100644 index 0000000..560e7f4 --- /dev/null +++ b/.github/workflows/changelog-local.yml @@ -0,0 +1,68 @@ +name: Update Changelog (Local Version) + +# This workflow uses the local version of Context Ledger from the PR +# Useful for testing changes before they're published + +on: + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - "docs/**" + - "**/CHANGELOG.md" + - "CHANGELOG.md" + + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + issues: write + +jobs: + update-changelog-local: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Update Changelog with Local Context Ledger + uses: ./ # Uses the local action code from this PR + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + changelog_path: "CHANGELOG.md" + target_name: "context-ledger" + version_increment: "auto" + auto_commit: ${{ github.event_name != 'pull_request' }} + create_pr_suggestions: ${{ github.event_name == 'pull_request' }} + continue-on-error: true + + - name: Add workflow source comment + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Only comment once per PR + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const hasComment = comments.data.some(c => + c.body.includes('🧪 Workflow: Local Version') + ); + + if (!hasComment) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '🧪 **Workflow: Local Version** - This changelog was generated using the PR\'s local code (`./`)' + }); + } diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index f6b2248..ae157e6 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -51,3 +51,29 @@ jobs: auto_commit: ${{ github.event_name != 'pull_request' }} create_pr_suggestions: ${{ github.event_name == 'pull_request' }} continue-on-error: true # Allow PR to succeed even if API key is missing + + - name: Add workflow source comment + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Only comment once per PR + const comments = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const hasComment = comments.data.some(c => + c.body.includes('🏷️ Workflow: Production Version') + ); + + if (!hasComment) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '🏷️ **Workflow: Production Version** - This changelog was generated using `lukemun/context-ledger@v1`' + }); + } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b017fd0..86f3b09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test Claude Changelog Action +name: Test Action on: push: @@ -9,6 +9,7 @@ on: jobs: test-action: + name: Validate Action Structure runs-on: ubuntu-latest permissions: contents: write @@ -58,6 +59,7 @@ jobs: echo "✅ Script structure validation passed" lint-and-validate: + name: Lint and Syntax Check runs-on: ubuntu-latest steps: @@ -104,6 +106,7 @@ jobs: echo "✅ JavaScript syntax is valid" integration-test: + name: Manual Integration Test runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' permissions: diff --git a/CHANGELOG.md b/CHANGELOG.md index ebe8e51..8835178 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,5 +38,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Provides detailed outputs for integration with other workflows - - diff --git a/README.md b/README.md index 6659663..d9373a4 100644 --- a/README.md +++ b/README.md @@ -430,6 +430,38 @@ npm test act pull_request -s ANTHROPIC_API_KEY=your_test_key ``` +## 🧪 Testing & Development + +### Dual Workflow Approach + +Context Ledger provides two workflows for maximum flexibility: + +1. **Production Workflow** (`changelog.yml`) - Uses the published version (`@v1`) + - Stable, tested version + - What your users will experience + - Runs automatically on PRs and releases + +2. **Local Workflow** (`changelog-local.yml`) - Uses the PR's code (`./`) + - Test changes before merging + - Verify fixes work as expected + - Same functionality, different source + +### Release Process + +When ready to release a new version: + +```bash +# 1. Ensure CHANGELOG.md has the new version +# 2. Merge your PR to main +# 3. Run the release script +./scripts/release.sh +``` + +This will: +- Create a new version tag (e.g., `v1.0.19`) +- Update the floating major tag (e.g., `v1`) +- Push both tags to GitHub + ## 🛡️ Security - **API Key Security**: Store your Anthropic API key in GitHub Secrets, never in code diff --git a/action.yml b/action.yml index a5b17ec..457f898 100644 --- a/action.yml +++ b/action.yml @@ -207,7 +207,7 @@ runs: # Get current branch and recent tags CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) - + # Try to get latest version from CHANGELOG.md first LATEST_VERSION="" if [ -f "CHANGELOG.md" ]; then @@ -215,7 +215,7 @@ runs: # Matches lines like: ## [0.3.0] LATEST_VERSION=$(tac CHANGELOG.md | grep -m1 -E '^\#\# \[[0-9]+\.[0-9]+\.[0-9]+\]' | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || true) fi - + # If no version in changelog, try git tags if [ -z "$LATEST_VERSION" ]; then LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..3b7a403 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# Release script for Context Ledger +# This automates the release process and ensures proper tagging + +set -e + +# Colors for output +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +RED='\033[0;31m' +NC='\033[0m' # No Color + +echo -e "${GREEN}Context Ledger Release Process${NC}" +echo "=================================" + +# Check if we're on main branch +CURRENT_BRANCH=$(git branch --show-current) +if [ "$CURRENT_BRANCH" != "main" ]; then + echo -e "${RED}Error: Must be on main branch to release${NC}" + exit 1 +fi + +# Get the latest version from CHANGELOG.md +LATEST_VERSION=$(tac CHANGELOG.md | grep -m1 -E '^\#\# \[[0-9]+\.[0-9]+\.[0-9]+\]' | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || echo "0.0.0") +echo -e "${YELLOW}Latest version in CHANGELOG: v$LATEST_VERSION${NC}" + +# Get the latest git tag +LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") +echo -e "${YELLOW}Latest git tag: $LATEST_TAG${NC}" + +# Ensure we have a new version +if [ "v$LATEST_VERSION" == "$LATEST_TAG" ]; then + echo -e "${RED}Error: No new version found in CHANGELOG.md${NC}" + echo "Please update CHANGELOG.md with a new version before releasing" + exit 1 +fi + +NEW_VERSION="v$LATEST_VERSION" +MAJOR_VERSION=$(echo $LATEST_VERSION | cut -d. -f1) + +echo -e "${GREEN}Releasing version: $NEW_VERSION${NC}" + +# Create and push the exact version tag +echo "Creating tag $NEW_VERSION..." +git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION" + +# Update the major version tag (floating tag) +echo "Updating floating tag v$MAJOR_VERSION..." +git tag -fa "v$MAJOR_VERSION" -m "Update v$MAJOR_VERSION to $NEW_VERSION" + +# Push tags +echo "Pushing tags..." +git push origin "$NEW_VERSION" +git push -f origin "v$MAJOR_VERSION" + +echo -e "${GREEN}✅ Release complete!${NC}" +echo "" +echo "Tagged and pushed:" +echo " - $NEW_VERSION (exact version)" +echo " - v$MAJOR_VERSION (floating tag)" +echo "" +echo "Users can now use:" +echo " - lukemun/context-ledger@$NEW_VERSION (pinned)" +echo " - lukemun/context-ledger@v$MAJOR_VERSION (auto-updates)"