|
| 1 | +name: Auto Release on Release Branch |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - release |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + auto-release: |
| 14 | + # Only run if PR was merged to release branch (not just closed) |
| 15 | + if: github.event.pull_request.merged == true |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 # Fetch all history for versioning |
| 23 | + |
| 24 | + - name: Setup Zig |
| 25 | + uses: goto-bus-stop/setup-zig@v2 |
| 26 | + with: |
| 27 | + version: 0.14.1 |
| 28 | + |
| 29 | + - name: Read VERSION file |
| 30 | + id: get_version |
| 31 | + run: | |
| 32 | + VERSION=$(cat VERSION) |
| 33 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "tag=v$VERSION" >> $GITHUB_OUTPUT |
| 35 | + |
| 36 | + - name: Check if tag exists |
| 37 | + id: check_tag |
| 38 | + run: | |
| 39 | + if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then |
| 40 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 41 | + echo "⚠️ Tag v${{ steps.get_version.outputs.version }} already exists" |
| 42 | + else |
| 43 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 44 | + echo "✅ Tag v${{ steps.get_version.outputs.version }} does not exist" |
| 45 | + fi |
| 46 | + |
| 47 | + - name: Run tests |
| 48 | + if: steps.check_tag.outputs.exists == 'false' |
| 49 | + run: zig build test |
| 50 | + |
| 51 | + - name: Build library |
| 52 | + if: steps.check_tag.outputs.exists == 'false' |
| 53 | + run: zig build |
| 54 | + |
| 55 | + - name: Update build.zig.zon version |
| 56 | + if: steps.check_tag.outputs.exists == 'false' |
| 57 | + run: | |
| 58 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 59 | + sed -i "s/\.version = \".*\"/\.version = \"$VERSION\"/" build.zig.zon |
| 60 | + |
| 61 | + - name: Generate changelog |
| 62 | + if: steps.check_tag.outputs.exists == 'false' |
| 63 | + id: changelog |
| 64 | + run: | |
| 65 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 66 | + |
| 67 | + # Get previous tag |
| 68 | + PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 69 | + |
| 70 | + if [ -z "$PREV_TAG" ]; then |
| 71 | + echo "## 🎉 Initial Release" > CHANGELOG.md |
| 72 | + echo "" >> CHANGELOG.md |
| 73 | + echo "First release of zig-poseidon - A Zig implementation of Poseidon2 hash function." >> CHANGELOG.md |
| 74 | + echo "" >> CHANGELOG.md |
| 75 | + echo "### Features" >> CHANGELOG.md |
| 76 | + echo "- BabyBear field (p = 2³¹ - 2²⁷ + 1) for Ethereum Lean chain" >> CHANGELOG.md |
| 77 | + echo "- KoalaBear field (p = 2³¹ - 2²⁴ + 1) for plonky3 and Rust hash-sig compatibility" >> CHANGELOG.md |
| 78 | + echo "- Generic Montgomery form implementation" >> CHANGELOG.md |
| 79 | + echo "- Compression mode for Merkle Trees" >> CHANGELOG.md |
| 80 | + echo "- Comprehensive test suite" >> CHANGELOG.md |
| 81 | + else |
| 82 | + echo "## Changes since $PREV_TAG" > CHANGELOG.md |
| 83 | + echo "" >> CHANGELOG.md |
| 84 | + git log "$PREV_TAG"..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md |
| 85 | + fi |
| 86 | + |
| 87 | + cat CHANGELOG.md |
| 88 | + |
| 89 | + - name: Create Git tag |
| 90 | + if: steps.check_tag.outputs.exists == 'false' |
| 91 | + run: | |
| 92 | + git config user.name "github-actions[bot]" |
| 93 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 94 | + git tag -a "${{ steps.get_version.outputs.tag }}" -m "Release ${{ steps.get_version.outputs.tag }}" |
| 95 | + git push origin "${{ steps.get_version.outputs.tag }}" |
| 96 | + |
| 97 | + - name: Create GitHub Release |
| 98 | + if: steps.check_tag.outputs.exists == 'false' |
| 99 | + uses: softprops/action-gh-release@v1 |
| 100 | + with: |
| 101 | + tag_name: ${{ steps.get_version.outputs.tag }} |
| 102 | + name: Release ${{ steps.get_version.outputs.tag }} |
| 103 | + body_path: CHANGELOG.md |
| 104 | + draft: false |
| 105 | + prerelease: false |
| 106 | + env: |
| 107 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + |
| 109 | + - name: Calculate tarball hash |
| 110 | + if: steps.check_tag.outputs.exists == 'false' |
| 111 | + id: tarball_hash |
| 112 | + run: | |
| 113 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 114 | + TARBALL_URL="https://github.com/${{ github.repository }}/archive/v${VERSION}.tar.gz" |
| 115 | + |
| 116 | + # Download and calculate hash |
| 117 | + curl -L "$TARBALL_URL" -o release.tar.gz |
| 118 | + HASH=$(zig fetch release.tar.gz 2>&1 | grep -o '12[0-9a-f]*' || echo "") |
| 119 | + |
| 120 | + if [ -z "$HASH" ]; then |
| 121 | + echo "⚠️ Could not calculate hash automatically" |
| 122 | + echo "📦 Users can get the hash by running:" |
| 123 | + echo " zig fetch --save $TARBALL_URL" |
| 124 | + else |
| 125 | + echo "hash=$HASH" >> $GITHUB_OUTPUT |
| 126 | + echo "📦 Tarball hash: $HASH" |
| 127 | + fi |
| 128 | + |
| 129 | + - name: Post release information |
| 130 | + if: steps.check_tag.outputs.exists == 'false' |
| 131 | + run: | |
| 132 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 133 | + echo "🎉 Release ${{ steps.get_version.outputs.tag }} created successfully!" |
| 134 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 135 | + echo "" |
| 136 | + echo "📦 To use this release in your project's build.zig.zon:" |
| 137 | + echo "" |
| 138 | + echo ".dependencies = .{" |
| 139 | + echo " .poseidon = .{" |
| 140 | + echo " .url = \"https://github.com/${{ github.repository }}/archive/${{ steps.get_version.outputs.tag }}.tar.gz\"," |
| 141 | + echo " .hash = \"${{ steps.tarball_hash.outputs.hash }}\"," |
| 142 | + echo " }," |
| 143 | + echo "}," |
| 144 | + echo "" |
| 145 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 146 | + |
| 147 | + - name: Skip release (tag exists) |
| 148 | + if: steps.check_tag.outputs.exists == 'true' |
| 149 | + run: | |
| 150 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 151 | + echo "⚠️ Skipping release - tag ${{ steps.get_version.outputs.tag }} already exists" |
| 152 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 153 | + echo "" |
| 154 | + echo "To create a new release:" |
| 155 | + echo "1. Update the VERSION file with a new version number" |
| 156 | + echo "2. Commit the change" |
| 157 | + echo "3. Create and merge a PR" |
| 158 | + echo "" |
| 159 | + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |
| 160 | +
|
0 commit comments