|
| 1 | +name: Build and Release MCP Resources |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: [main] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Version number (e.g., 1.0.0)' |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-release: |
| 16 | + # Manual trigger OR (PR merged with label 'mcp-publish') |
| 17 | + if: | |
| 18 | + github.event_name == 'workflow_dispatch' || |
| 19 | + (github.event.pull_request.merged == true && |
| 20 | + contains(github.event.pull_request.labels.*.name, 'mcp-publish')) |
| 21 | +
|
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 # Fetch all history for proper versioning |
| 31 | + |
| 32 | + - name: Setup Node.js |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: 'lts/*' |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: npm install |
| 39 | + |
| 40 | + - name: Build markdown documentation |
| 41 | + run: npm run build:docs |
| 42 | + |
| 43 | + - name: Determine version |
| 44 | + id: version |
| 45 | + run: | |
| 46 | + if [ -n "${{ github.event.inputs.version }}" ]; then |
| 47 | + VERSION="${{ github.event.inputs.version }}" |
| 48 | + else |
| 49 | + # Get the latest tag, or use 1.0.0 if no tags exist |
| 50 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 51 | + # Remove 'v' prefix if present |
| 52 | + LATEST_VERSION=${LATEST_TAG#v} |
| 53 | + # Increment patch version |
| 54 | + IFS='.' read -r -a VERSION_PARTS <<< "$LATEST_VERSION" |
| 55 | + MAJOR=${VERSION_PARTS[0]:-0} |
| 56 | + MINOR=${VERSION_PARTS[1]:-0} |
| 57 | + PATCH=${VERSION_PARTS[2]:-0} |
| 58 | + PATCH=$((PATCH + 1)) |
| 59 | + VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 60 | + fi |
| 61 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 62 | + echo "tag=v${VERSION}" >> $GITHUB_OUTPUT |
| 63 | + echo "Building version: ${VERSION}" |
| 64 | +
|
| 65 | + - name: Create Release |
| 66 | + id: create_release |
| 67 | + uses: actions/create-release@v1 |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + with: |
| 71 | + tag_name: ${{ steps.version.outputs.tag }} |
| 72 | + release_name: Release ${{ steps.version.outputs.tag }} |
| 73 | + body: | |
| 74 | + Automated release of PostHog example projects as markdown documentation. |
| 75 | +
|
| 76 | + This release contains pre-processed markdown files for all example projects. |
| 77 | +
|
| 78 | + **Contents:** |
| 79 | + - `nextjs-app-router.md` - Next.js App Router example |
| 80 | + - `nextjs-pages-router.md` - Next.js Pages Router example |
| 81 | +
|
| 82 | + **SHA:** ${{ github.sha }} |
| 83 | + draft: false |
| 84 | + prerelease: false |
| 85 | + |
| 86 | + - name: Upload Release Asset |
| 87 | + uses: actions/upload-release-asset@v1 |
| 88 | + env: |
| 89 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + with: |
| 91 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 92 | + asset_path: ./dist/examples-mcp-resources.zip |
| 93 | + asset_name: examples-mcp-resources.zip |
| 94 | + asset_content_type: application/zip |
| 95 | + |
| 96 | + - name: Update latest tag |
| 97 | + run: | |
| 98 | + git config user.name "github-actions[bot]" |
| 99 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 100 | + # Create the version tag locally first |
| 101 | + git tag ${{ steps.version.outputs.tag }} |
| 102 | + # Point latest to the current commit (same as the version tag) |
| 103 | + git tag -f latest |
| 104 | + # Push both tags |
| 105 | + git push origin ${{ steps.version.outputs.tag }} |
| 106 | + git push -f origin latest |
| 107 | +
|
| 108 | + - name: Build Summary |
| 109 | + run: | |
| 110 | + echo "## Release Summary" >> $GITHUB_STEP_SUMMARY |
| 111 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 112 | + echo "- **Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 113 | + echo "- **Tag:** ${{ steps.version.outputs.tag }}" >> $GITHUB_STEP_SUMMARY |
| 114 | + echo "- **Artifact:** examples-mcp-resources.zip" >> $GITHUB_STEP_SUMMARY |
| 115 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 116 | + echo "### Files Generated" >> $GITHUB_STEP_SUMMARY |
| 117 | + ls -lh dist/ >> $GITHUB_STEP_SUMMARY |
0 commit comments