Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
697b38f
feat: Add changelog preview GitHub Action
BYK Dec 26, 2025
be12666
ci: Add changelog preview workflow for testing
BYK Dec 26, 2025
749a43b
ci: Fix changelog preview workflow for testing
BYK Dec 26, 2025
0a77633
fix: Use commit-based highlighting instead of PR number
BYK Dec 26, 2025
de8d3ee
debug: Add verbose output to changelog preview workflow
BYK Dec 26, 2025
3f80c2b
ci: Build craft from source for testing (changelog cmd not released)
BYK Dec 26, 2025
4391678
fix: Generate changelog up to merge base and inject current PR
BYK Dec 26, 2025
f2aefe9
fix: Add GITHUB_TOKEN env for Craft API access
BYK Dec 26, 2025
9647967
fix: Suppress stderr to hide node deprecation warning
BYK Dec 26, 2025
06a9014
refactor: Remove --until flag, compute merge base from PR's base branch
BYK Dec 26, 2025
4ea8507
feat: Make changelog-preview a reusable workflow
BYK Dec 26, 2025
e1756f3
fix: Add setup-node step for dogfooding
BYK Dec 26, 2025
8f7e9d2
fix: Remove explicit secrets requirement from workflow_call
BYK Dec 26, 2025
5aa67f1
refactor: Address PR review comments
BYK Dec 26, 2025
e5ecfc3
fix: Inline install logic in reusable workflow
BYK Dec 26, 2025
324d340
refactor: Address additional PR review comments
BYK Dec 26, 2025
5fab25c
refactor: Split changelog generation into raw data + serialization
BYK Dec 26, 2025
491804b
refactor: Use base branch tip instead of merge-base
BYK Dec 26, 2025
368750f
refactor: Separate RawChangelogData from ChangelogStats
BYK Dec 26, 2025
2c0f6d8
refactor: Inline injectCurrentPR into generateChangelogWithHighlight
BYK Dec 26, 2025
3adcf69
refactor: Clean sandwich approach for changelog with PR injection
BYK Dec 26, 2025
abbe627
feat: Display suggested version bump in changelog preview comment
BYK Dec 26, 2025
5777299
style: Make version bump more prominent with its own header
BYK Dec 26, 2025
bd046e2
refactor: Move version bump to top-level header, use temp file for co…
BYK Dec 26, 2025
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
105 changes: 105 additions & 0 deletions .github/workflows/changelog-preview.yml
Comment thread
BYK marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Changelog Preview

on:
# Allow this workflow to be called from other repositories
workflow_call:
inputs:
craft-version:
description: 'Version of Craft to use (tag or "latest")'
required: false
type: string
default: 'latest'

# Also run on PRs in this repository (for dogfooding)
# Includes 'edited' and 'labeled' to update when PR title/description/labels change
pull_request:
types: [opened, synchronize, reopened, edited, labeled]

permissions:
pull-requests: write

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

# Install Craft using the shared install action
# TODO: Change to @v2 or @master after this PR is merged
- name: Install Craft
uses: getsentry/craft/install@pull/669/head
with:
craft-version: ${{ inputs.craft-version || 'latest' }}

- name: Generate Changelog Preview
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CRAFT_LOG_LEVEL: Warn
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"

# Generate changelog with current PR injected and highlighted (JSON format)
echo "Running craft changelog --pr $PR_NUMBER --format json..."
RESULT=$(craft changelog --pr "$PR_NUMBER" --format json 2>/dev/null || echo '{"changelog":"","bumpType":null}')

# Extract fields from JSON
CHANGELOG=$(echo "$RESULT" | jq -r '.changelog // ""')
BUMP_TYPE=$(echo "$RESULT" | jq -r '.bumpType // "none"')

if [[ -z "$CHANGELOG" ]]; then
CHANGELOG="_No changelog entries will be generated from this PR._"
fi

# Format bump type for display
case "$BUMP_TYPE" in
major) BUMP_BADGE="🔴 **Major** (breaking changes)" ;;
minor) BUMP_BADGE="🟡 **Minor** (new features)" ;;
patch) BUMP_BADGE="🟢 **Patch** (bug fixes)" ;;
*) BUMP_BADGE="⚪ **None** (no version bump detected)" ;;
esac

# Build comment body using a temp file (safer than heredoc)
COMMENT_FILE=$(mktemp)
cat > "$COMMENT_FILE" << CRAFT_CHANGELOG_COMMENT_END
<!-- craft-changelog-preview -->
## Suggested Version Bump

${BUMP_BADGE}

## 📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).

---

${CHANGELOG}

---

<sub>🤖 This preview updates automatically when you update the PR.</sub>
CRAFT_CHANGELOG_COMMENT_END

# Find existing comment with our marker
COMMENT_ID=$(gh api \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
--jq '.[] | select(.body | contains("<!-- craft-changelog-preview -->")) | .id' \
| head -1)

if [[ -n "$COMMENT_ID" ]]; then
echo "Updating existing comment $COMMENT_ID..."
gh api -X PATCH \
"repos/$GITHUB_REPOSITORY/issues/comments/$COMMENT_ID" \
-F body=@"$COMMENT_FILE"
else
echo "Creating new comment..."
gh api -X POST \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \
-F body=@"$COMMENT_FILE"
fi

rm -f "$COMMENT_FILE"
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ craft publish 1.2.3
- **Changelog Management** - Auto-generate changelogs from commits or validate manual entries
- **Workspace Support** - Handle monorepos with NPM/Yarn workspaces
- **CI Integration** - Wait for CI to pass, download artifacts, and publish
- **GitHub Actions** - Built-in actions for release preparation and changelog previews

## Configuration

Expand Down Expand Up @@ -83,6 +84,78 @@ See the [configuration reference](https://getsentry.github.io/craft/configuratio

See the [targets documentation](https://getsentry.github.io/craft/targets/) for configuration details.

## GitHub Actions

Craft provides GitHub Actions for automating releases and previewing changelog entries.

### Prepare Release Action

Automates the `craft prepare` workflow in GitHub Actions:

```yaml
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (or "auto")'
required: false

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: getsentry/craft@v2
with:
version: ${{ github.event.inputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

**Inputs:**

| Input | Description | Default |
|-------|-------------|---------|
| `version` | Version to release (semver, "auto", "major", "minor", "patch") | Uses `versioning.policy` from config |
| `merge_target` | Target branch to merge into | Default branch |
| `force` | Force release even with blockers | `false` |
| `blocker_label` | Label that blocks releases | `release-blocker` |
| `publish_repo` | Repository for publish issues | `{owner}/publish` |

**Outputs:**

| Output | Description |
|--------|-------------|
| `version` | The resolved version being released |
| `branch` | The release branch name |
| `sha` | The commit SHA on the release branch |
| `changelog` | The changelog for this release |

### Changelog Preview (Reusable Workflow)

Posts a preview comment on PRs showing how they'll appear in the changelog:

```yaml
name: Changelog Preview
on:
pull_request:
types: [opened, synchronize, reopened, edited, labeled]

jobs:
changelog-preview:
uses: getsentry/craft/.github/workflows/changelog-preview.yml@v2
secrets: inherit
```

The workflow will:
- Generate the upcoming changelog including the PR's changes
- Highlight entries from the PR using blockquote style (left border)
- Post a comment on the PR with the preview
- Automatically update when you update the PR (push, edit title/description, or change labels)

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
Expand Down
38 changes: 2 additions & 36 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,8 @@ runs:
echo "GIT_AUTHOR_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV
echo "EMAIL=${GIT_USER_EMAIL}" >> $GITHUB_ENV

- name: Download Craft from build artifact
id: artifact
if: github.repository == 'getsentry/craft'
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
continue-on-error: true
with:
name: ${{ github.sha }}
path: /tmp/craft-artifact

- name: Install Craft from artifact
if: steps.artifact.outcome == 'success'
shell: bash
run: |
echo "Installing Craft from build artifact..."
sudo install -m 755 /tmp/craft-artifact/dist/craft /usr/local/bin/craft

- name: Install Craft from release
if: steps.artifact.outcome != 'success'
shell: bash
run: |
# Try action ref first (e.g., v2, 2.15.0)
ACTION_REF="${{ github.action_ref }}"
CRAFT_URL="https://github.com/getsentry/craft/releases/download/${ACTION_REF}/craft"

echo "Trying to download Craft from: ${CRAFT_URL}"

# Fallback to latest if ref doesn't have a release
if ! curl -sfI "$CRAFT_URL" >/dev/null 2>&1; then
echo "Release not found for ref '${ACTION_REF}', falling back to latest..."
CRAFT_URL=$(curl -s "https://github.com/ghapi/repos/getsentry/craft/releases/latest" \
| jq -r '.assets[] | select(.name == "craft") | .browser_download_url')
fi

echo "Installing Craft from: ${CRAFT_URL}"
sudo curl -sL -o /usr/local/bin/craft "$CRAFT_URL"
sudo chmod +x /usr/local/bin/craft
- name: Install Craft
uses: ./install

- name: Craft Prepare
id: craft
Expand Down
1 change: 1 addition & 0 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
{ label: 'Introduction', slug: '' },
{ label: 'Installation', slug: 'getting-started' },
{ label: 'Configuration', slug: 'configuration' },
{ label: 'GitHub Actions', slug: 'github-actions' },
],
},
{
Expand Down
Loading
Loading