Skip to content
Merged
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
68 changes: 68 additions & 0 deletions .github/workflows/changelog-local.yml
Original file line number Diff line number Diff line change
@@ -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 (`./`)'
});
}
26 changes: 26 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`'
});
}
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Claude Changelog Action
name: Test Action

on:
push:
Expand All @@ -9,6 +9,7 @@ on:

jobs:
test-action:
name: Validate Action Structure
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -58,6 +59,7 @@ jobs:
echo "✅ Script structure validation passed"

lint-and-validate:
name: Lint and Syntax Check
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!-- AI_APPEND_HERE -->

<!-- Updated for AI processing at 2025-08-15T17:28:06.112Z -->
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ 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
# Look for the most recent version header by scanning from the bottom up
# 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")
Expand Down
64 changes: 64 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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)"