|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [br_release] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + name: Create Release with Native Binaries |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Get version from latest tag |
| 21 | + id: version |
| 22 | + run: | |
| 23 | + # Get the latest tag on this branch |
| 24 | + VERSION_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 25 | +
|
| 26 | + if [ -z "$VERSION_TAG" ]; then |
| 27 | + echo "Error: No tags found. Run dump-version.sh first." |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +
|
| 31 | + # Remove 'v' prefix for version number |
| 32 | + VERSION="${VERSION_TAG#v}" |
| 33 | +
|
| 34 | + echo "version_tag=${VERSION_TAG}" >> $GITHUB_OUTPUT |
| 35 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 36 | + echo "Version Tag: ${VERSION_TAG}" |
| 37 | + echo "Version: ${VERSION}" |
| 38 | +
|
| 39 | + - name: Check if release already exists |
| 40 | + id: check_release |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + run: | |
| 44 | + if gh release view ${{ steps.version.outputs.version_tag }} &>/dev/null; then |
| 45 | + echo "Release ${{ steps.version.outputs.version_tag }} already exists" |
| 46 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "Release ${{ steps.version.outputs.version_tag }} does not exist" |
| 49 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Download native binaries from gopher-orch |
| 53 | + if: steps.check_release.outputs.exists != 'true' |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ secrets.GOPHER_ORCH_TOKEN }} |
| 56 | + run: | |
| 57 | + echo "Downloading native binaries for ${{ steps.version.outputs.version_tag }}..." |
| 58 | +
|
| 59 | + mkdir -p downloads |
| 60 | +
|
| 61 | + # Download all platform binaries from gopher-orch release |
| 62 | + gh release download ${{ steps.version.outputs.version_tag }} \ |
| 63 | + -R GopherSecurity/gopher-orch \ |
| 64 | + -D downloads \ |
| 65 | + -p "libgopher-orch-*.tar.gz" \ |
| 66 | + -p "libgopher-orch-*.zip" || { |
| 67 | + echo "Warning: Could not download some binaries" |
| 68 | + echo "Available assets:" |
| 69 | + gh release view ${{ steps.version.outputs.version_tag }} -R GopherSecurity/gopher-orch --json assets -q '.assets[].name' |
| 70 | + } |
| 71 | +
|
| 72 | + echo "Downloaded files:" |
| 73 | + ls -la downloads/ |
| 74 | +
|
| 75 | + - name: Rename binaries for Go SDK release |
| 76 | + if: steps.check_release.outputs.exists != 'true' |
| 77 | + run: | |
| 78 | + mkdir -p release-assets |
| 79 | +
|
| 80 | + # Copy and optionally rename binaries |
| 81 | + for file in downloads/*; do |
| 82 | + if [ -f "$file" ]; then |
| 83 | + cp "$file" "release-assets/" |
| 84 | + fi |
| 85 | + done |
| 86 | +
|
| 87 | + echo "Release assets:" |
| 88 | + ls -la release-assets/ |
| 89 | +
|
| 90 | + - name: Generate release notes |
| 91 | + if: steps.check_release.outputs.exists != 'true' |
| 92 | + run: | |
| 93 | + VERSION="${{ steps.version.outputs.version }}" |
| 94 | + VERSION_TAG="${{ steps.version.outputs.version_tag }}" |
| 95 | +
|
| 96 | + cat > RELEASE_NOTES.md << EOF |
| 97 | + ## gopher-mcp-go ${VERSION_TAG} |
| 98 | +
|
| 99 | + Go SDK for gopher-orch orchestration framework. |
| 100 | +
|
| 101 | + ### Installation |
| 102 | +
|
| 103 | + \`\`\`bash |
| 104 | + # Install Go module |
| 105 | + go get github.com/GopherSecurity/gopher-mcp-go@${VERSION_TAG} |
| 106 | +
|
| 107 | + # Download native library for your platform |
| 108 | + # macOS (Apple Silicon) |
| 109 | + gh release download ${VERSION_TAG} -R GopherSecurity/gopher-mcp-go -p "libgopher-orch-macos-arm64.tar.gz" |
| 110 | + tar -xzf libgopher-orch-macos-arm64.tar.gz -C /usr/local |
| 111 | +
|
| 112 | + # macOS (Intel) |
| 113 | + gh release download ${VERSION_TAG} -R GopherSecurity/gopher-mcp-go -p "libgopher-orch-macos-x64.tar.gz" |
| 114 | + tar -xzf libgopher-orch-macos-x64.tar.gz -C /usr/local |
| 115 | +
|
| 116 | + # Linux (x64) |
| 117 | + gh release download ${VERSION_TAG} -R GopherSecurity/gopher-mcp-go -p "libgopher-orch-linux-x64.tar.gz" |
| 118 | + sudo tar -xzf libgopher-orch-linux-x64.tar.gz -C /usr/local |
| 119 | +
|
| 120 | + # Linux (arm64) |
| 121 | + gh release download ${VERSION_TAG} -R GopherSecurity/gopher-mcp-go -p "libgopher-orch-linux-arm64.tar.gz" |
| 122 | + sudo tar -xzf libgopher-orch-linux-arm64.tar.gz -C /usr/local |
| 123 | + \`\`\` |
| 124 | +
|
| 125 | + ### Environment Setup |
| 126 | +
|
| 127 | + \`\`\`bash |
| 128 | + export CGO_CFLAGS="-I/usr/local/include" |
| 129 | + export CGO_LDFLAGS="-L/usr/local/lib -lgopher-orch" |
| 130 | + export DYLD_LIBRARY_PATH="/usr/local/lib:\$DYLD_LIBRARY_PATH" # macOS |
| 131 | + export LD_LIBRARY_PATH="/usr/local/lib:\$LD_LIBRARY_PATH" # Linux |
| 132 | + \`\`\` |
| 133 | +
|
| 134 | + ### Build Information |
| 135 | +
|
| 136 | + - **Version:** ${VERSION} |
| 137 | + - **gopher-orch:** ${VERSION_TAG} |
| 138 | + - **Commit:** ${{ github.sha }} |
| 139 | + - **Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 140 | +
|
| 141 | + EOF |
| 142 | +
|
| 143 | + # Extract changelog content |
| 144 | + if [ -f "CHANGELOG.md" ]; then |
| 145 | + echo "### What's Changed" >> RELEASE_NOTES.md |
| 146 | + echo "" >> RELEASE_NOTES.md |
| 147 | +
|
| 148 | + # Get content from the version section |
| 149 | + sed -n "/^## \[${VERSION}\]/,/^## \[/p" CHANGELOG.md | \ |
| 150 | + grep -v "^## \[" | \ |
| 151 | + head -30 >> RELEASE_NOTES.md || true |
| 152 | + fi |
| 153 | +
|
| 154 | + # Add comparison link |
| 155 | + PREV_TAG=$(git tag --sort=-creatordate | grep -v "^${VERSION_TAG}$" | head -1) |
| 156 | + if [ -n "$PREV_TAG" ]; then |
| 157 | + echo "" >> RELEASE_NOTES.md |
| 158 | + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${VERSION_TAG}" >> RELEASE_NOTES.md |
| 159 | + fi |
| 160 | +
|
| 161 | + echo "=== Release Notes ===" |
| 162 | + cat RELEASE_NOTES.md |
| 163 | +
|
| 164 | + - name: Create GitHub Release |
| 165 | + if: steps.check_release.outputs.exists != 'true' |
| 166 | + uses: softprops/action-gh-release@v1 |
| 167 | + with: |
| 168 | + tag_name: ${{ steps.version.outputs.version_tag }} |
| 169 | + name: gopher-mcp-go ${{ steps.version.outputs.version_tag }} |
| 170 | + body_path: RELEASE_NOTES.md |
| 171 | + draft: false |
| 172 | + prerelease: ${{ contains(steps.version.outputs.version, '-') }} |
| 173 | + files: release-assets/* |
| 174 | + env: |
| 175 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 176 | + |
| 177 | + - name: Summary |
| 178 | + run: | |
| 179 | + echo "## Release Summary" >> $GITHUB_STEP_SUMMARY |
| 180 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 181 | + echo "- **Version:** ${{ steps.version.outputs.version_tag }}" >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "- **Release URL:** https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.version_tag }}" >> $GITHUB_STEP_SUMMARY |
| 183 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 184 | + echo "### Native Libraries" >> $GITHUB_STEP_SUMMARY |
| 185 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 186 | + if [ -d "release-assets" ]; then |
| 187 | + ls release-assets/ | while read file; do |
| 188 | + echo "- \`${file}\`" >> $GITHUB_STEP_SUMMARY |
| 189 | + done |
| 190 | + fi |
| 191 | +
|
| 192 | + test: |
| 193 | + name: Run Tests |
| 194 | + runs-on: ubuntu-latest |
| 195 | + steps: |
| 196 | + - name: Checkout |
| 197 | + uses: actions/checkout@v4 |
| 198 | + |
| 199 | + - name: Setup Go |
| 200 | + uses: actions/setup-go@v5 |
| 201 | + with: |
| 202 | + go-version: '1.21' |
| 203 | + |
| 204 | + - name: Run tests (without native library) |
| 205 | + run: | |
| 206 | + # Run tests that don't require native library |
| 207 | + go test ./... -v -short || echo "Some tests may require native library" |
| 208 | +
|
| 209 | + notify: |
| 210 | + name: Notify on Failure |
| 211 | + needs: [release, test] |
| 212 | + runs-on: ubuntu-latest |
| 213 | + if: failure() |
| 214 | + steps: |
| 215 | + - name: Report failure |
| 216 | + run: | |
| 217 | + echo "Release workflow failed!" |
| 218 | + echo "Check the logs for details." |
0 commit comments