From 0309218706ef0edacc2ee9f08371ca3c6e8d5cc7 Mon Sep 17 00:00:00 2001 From: Rahul Guha <19rahul2003@gmail.com> Date: Wed, 15 Oct 2025 19:08:31 +0530 Subject: [PATCH 1/2] init --- .github/workflows/auto-release.yml | 126 +++++++++++++++++++++++++++++ VERSION | 1 + 2 files changed, 127 insertions(+) create mode 100644 .github/workflows/auto-release.yml create mode 100644 VERSION diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..ffe5475 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,126 @@ +name: Auto Release + +on: + pull_request: + types: [closed] + branches: + - release + +jobs: + release: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Zig + uses: korandoru/setup-zig@v1 + with: + zig-version: 0.14.0 + + - name: Read version + id: version + run: | + VERSION=$(cat VERSION) + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "Version: $VERSION" + + - name: Check if tag exists + id: check_tag + run: | + if git rev-parse "v${{ steps.version.outputs.VERSION }}" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Exit if tag exists + if: steps.check_tag.outputs.exists == 'true' + run: | + echo "Tag v${{ steps.version.outputs.VERSION }} already exists. Skipping release." + exit 0 + + - name: Run tests + if: steps.check_tag.outputs.exists == 'false' + run: zig build test --summary all + + - name: Build library + if: steps.check_tag.outputs.exists == 'false' + run: zig build + + - name: Update build.zig.zon version + if: steps.check_tag.outputs.exists == 'false' + run: | + sed -i "s/\.version = \".*\"/\.version = \"${{ steps.version.outputs.VERSION }}\"/" build.zig.zon + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add build.zig.zon + git diff --cached --quiet || git commit -m "chore: bump version to ${{ steps.version.outputs.VERSION }}" + + - name: Generate changelog + if: steps.check_tag.outputs.exists == 'false' + id: changelog + run: | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + if [ -z "$PREVIOUS_TAG" ]; then + CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges) + else + CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) + fi + echo "CHANGELOG<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create Git tag + if: steps.check_tag.outputs.exists == 'false' + run: | + git tag -a "v${{ steps.version.outputs.VERSION }}" -m "Release v${{ steps.version.outputs.VERSION }}" + git push origin "v${{ steps.version.outputs.VERSION }}" + + - name: Create GitHub Release + if: steps.check_tag.outputs.exists == 'false' + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.version.outputs.VERSION }} + release_name: v${{ steps.version.outputs.VERSION }} + body: | + # Release v${{ steps.version.outputs.VERSION }} + + ## Changes + ${{ steps.changelog.outputs.CHANGELOG }} + + ## Usage + To use this release in your Zig project: + + ```bash + zig fetch --save https://github.com/${{ github.repository }}/archive/v${{ steps.version.outputs.VERSION }}.tar.gz + ``` + + Then add to your `build.zig`: + + ```zig + const snappyframesz = b.dependency("snappyframesz", .{ + .target = target, + .optimize = optimize, + }); + exe.root_module.addImport("snappyframesz", snappyframesz.module("snappyframesz")); + ``` + draft: false + prerelease: false + + - name: Calculate tarball hash + if: steps.check_tag.outputs.exists == 'false' + run: | + TARBALL_URL="https://github.com/${{ github.repository }}/archive/v${{ steps.version.outputs.VERSION }}.tar.gz" + echo "Tarball URL: $TARBALL_URL" + echo "Calculating hash..." + curl -L "$TARBALL_URL" | sha256sum + echo "" + echo "Use the above hash when adding this package as a dependency." diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 From d2863cdbb7e8b7b99aa2316f8bac87b5929c9603 Mon Sep 17 00:00:00 2001 From: Rahul Guha <19rahul2003@gmail.com> Date: Wed, 15 Oct 2025 19:23:59 +0530 Subject: [PATCH 2/2] add more info --- .github/workflows/auto-release.yml | 177 ++++++++++++++++++----------- 1 file changed, 111 insertions(+), 66 deletions(-) diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index ffe5475..19e80c2 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -1,4 +1,4 @@ -name: Auto Release +name: Auto Release on Release Branch on: pull_request: @@ -6,48 +6,47 @@ on: branches: - release +permissions: + contents: write + jobs: - release: + auto-release: + # Only run if PR was merged to release branch (not just closed) if: github.event.pull_request.merged == true runs-on: ubuntu-latest - permissions: - contents: write + steps: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 # Fetch all history for versioning - - name: Set up Zig - uses: korandoru/setup-zig@v1 + - name: Setup Zig + uses: goto-bus-stop/setup-zig@v2 with: - zig-version: 0.14.0 + version: 0.14.0 - - name: Read version - id: version + - name: Read VERSION file + id: get_version run: | VERSION=$(cat VERSION) - echo "VERSION=$VERSION" >> $GITHUB_OUTPUT - echo "Version: $VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=v$VERSION" >> $GITHUB_OUTPUT - name: Check if tag exists id: check_tag run: | - if git rev-parse "v${{ steps.version.outputs.VERSION }}" >/dev/null 2>&1; then + if git rev-parse "v${{ steps.get_version.outputs.version }}" >/dev/null 2>&1; then echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag v${{ steps.get_version.outputs.version }} already exists" else echo "exists=false" >> $GITHUB_OUTPUT + echo "Tag v${{ steps.get_version.outputs.version }} does not exist" fi - - name: Exit if tag exists - if: steps.check_tag.outputs.exists == 'true' - run: | - echo "Tag v${{ steps.version.outputs.VERSION }} already exists. Skipping release." - exit 0 - - name: Run tests if: steps.check_tag.outputs.exists == 'false' - run: zig build test --summary all + run: zig build test - name: Build library if: steps.check_tag.outputs.exists == 'false' @@ -56,71 +55,117 @@ jobs: - name: Update build.zig.zon version if: steps.check_tag.outputs.exists == 'false' run: | - sed -i "s/\.version = \".*\"/\.version = \"${{ steps.version.outputs.VERSION }}\"/" build.zig.zon - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add build.zig.zon - git diff --cached --quiet || git commit -m "chore: bump version to ${{ steps.version.outputs.VERSION }}" + VERSION="${{ steps.get_version.outputs.version }}" + sed -i "s/\.version = \"[^\"]*\"/\.version = \"$VERSION\"/" build.zig.zon - name: Generate changelog if: steps.check_tag.outputs.exists == 'false' id: changelog run: | - PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") - if [ -z "$PREVIOUS_TAG" ]; then - CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges) + VERSION="${{ steps.get_version.outputs.version }}" + + # Get previous tag + PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + + if [ -z "$PREV_TAG" ]; then + echo "## Initial Release" > CHANGELOG.md + echo "" >> CHANGELOG.md + echo "First release of snappyframesz - A Zig implementation of Snappy frame format." >> CHANGELOG.md + echo "" >> CHANGELOG.md + echo "### Features" >> CHANGELOG.md + echo "- Snappy frame format support" >> CHANGELOG.md + echo "- Frame compression and decompression" >> CHANGELOG.md + echo "- CRC32C checksum validation" >> CHANGELOG.md + echo "- Comprehensive test suite" >> CHANGELOG.md else - CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges) + echo "## Changes since $PREV_TAG" > CHANGELOG.md + echo "" >> CHANGELOG.md + git log "$PREV_TAG"..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md fi - echo "CHANGELOG<> $GITHUB_OUTPUT - echo "$CHANGELOG" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT + + cat CHANGELOG.md + + - name: Commit version update + if: steps.check_tag.outputs.exists == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add build.zig.zon + git diff --staged --quiet || git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}" + + - name: Push version update + if: steps.check_tag.outputs.exists == 'false' + run: | + git push origin release - name: Create Git tag if: steps.check_tag.outputs.exists == 'false' run: | - git tag -a "v${{ steps.version.outputs.VERSION }}" -m "Release v${{ steps.version.outputs.VERSION }}" - git push origin "v${{ steps.version.outputs.VERSION }}" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "${{ steps.get_version.outputs.tag }}" -m "Release ${{ steps.get_version.outputs.tag }}" + git push origin "${{ steps.get_version.outputs.tag }}" - name: Create GitHub Release if: steps.check_tag.outputs.exists == 'false' - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - tag_name: v${{ steps.version.outputs.VERSION }} - release_name: v${{ steps.version.outputs.VERSION }} - body: | - # Release v${{ steps.version.outputs.VERSION }} - - ## Changes - ${{ steps.changelog.outputs.CHANGELOG }} - - ## Usage - To use this release in your Zig project: - - ```bash - zig fetch --save https://github.com/${{ github.repository }}/archive/v${{ steps.version.outputs.VERSION }}.tar.gz - ``` - - Then add to your `build.zig`: - - ```zig - const snappyframesz = b.dependency("snappyframesz", .{ - .target = target, - .optimize = optimize, - }); - exe.root_module.addImport("snappyframesz", snappyframesz.module("snappyframesz")); - ``` + tag_name: ${{ steps.get_version.outputs.tag }} + name: Release ${{ steps.get_version.outputs.tag }} + body_path: CHANGELOG.md draft: false prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Calculate tarball hash if: steps.check_tag.outputs.exists == 'false' + id: tarball_hash run: | - TARBALL_URL="https://github.com/${{ github.repository }}/archive/v${{ steps.version.outputs.VERSION }}.tar.gz" - echo "Tarball URL: $TARBALL_URL" - echo "Calculating hash..." - curl -L "$TARBALL_URL" | sha256sum + VERSION="${{ steps.get_version.outputs.version }}" + TARBALL_URL="https://github.com/${{ github.repository }}/archive/v${VERSION}.tar.gz" + + # Download and calculate hash + curl -L "$TARBALL_URL" -o release.tar.gz + HASH=$(zig fetch release.tar.gz 2>&1 | grep -o '12[0-9a-f]*' || echo "") + + if [ -z "$HASH" ]; then + echo "Could not calculate hash automatically" + echo "Users can get the hash by running:" + echo " zig fetch --save $TARBALL_URL" + else + echo "hash=$HASH" >> $GITHUB_OUTPUT + echo "Tarball hash: $HASH" + fi + + - name: Post release information + if: steps.check_tag.outputs.exists == 'false' + run: | + echo "==========================================================================" + echo "Release ${{ steps.get_version.outputs.tag }} created successfully!" + echo "==========================================================================" + echo "" + echo "To use this release in your project's build.zig.zon:" + echo "" + echo ".dependencies = .{" + echo " .snappyframesz = .{" + echo " .url = \"https://github.com/${{ github.repository }}/archive/${{ steps.get_version.outputs.tag }}.tar.gz\"," + echo " .hash = \"${{ steps.tarball_hash.outputs.hash }}\"," + echo " }," + echo "}," + echo "" + echo "==========================================================================" + + - name: Skip release (tag exists) + if: steps.check_tag.outputs.exists == 'true' + run: | + echo "==========================================================================" + echo "Skipping release - tag ${{ steps.get_version.outputs.tag }} already exists" + echo "==========================================================================" + echo "" + echo "To create a new release:" + echo "1. Update the VERSION file with a new version number" + echo "2. Commit the change" + echo "3. Create and merge a PR to the release branch" echo "" - echo "Use the above hash when adding this package as a dependency." + echo "=========================================================================="