|
| 1 | +name: Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 20 | + |
| 21 | + - name: Get current version and calculate next version |
| 22 | + id: version |
| 23 | + run: | |
| 24 | + # Get current version from CMakeLists.txt |
| 25 | + CURRENT_VERSION=$(grep -oP 'VERSION \K[0-9]+\.[0-9]+\.[0-9]+' CMakeLists.txt | head -1) |
| 26 | + echo "Current version in CMakeLists.txt: $CURRENT_VERSION" |
| 27 | +
|
| 28 | + # Get latest tag |
| 29 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 30 | + LATEST_VERSION=${LATEST_TAG#v} |
| 31 | + echo "Latest git tag: $LATEST_TAG ($LATEST_VERSION)" |
| 32 | +
|
| 33 | + # Parse current version |
| 34 | + IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" |
| 35 | + MAJOR="${VERSION_PARTS[0]}" |
| 36 | + MINOR="${VERSION_PARTS[1]}" |
| 37 | + PATCH="${VERSION_PARTS[2]}" |
| 38 | +
|
| 39 | + # Auto-increment patch version |
| 40 | + PATCH=$((PATCH + 1)) |
| 41 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 42 | +
|
| 43 | + echo "New version: $NEW_VERSION" |
| 44 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 45 | + echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT |
| 46 | + echo "prev_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Update version in all files |
| 49 | + run: | |
| 50 | + VERSION="${{ steps.version.outputs.version }}" |
| 51 | + echo "Updating version to $VERSION in all files..." |
| 52 | +
|
| 53 | + # Update CMakeLists.txt |
| 54 | + sed -i "s/VERSION [0-9]\+\.[0-9]\+\.[0-9]\+/VERSION $VERSION/" CMakeLists.txt |
| 55 | +
|
| 56 | + # Update Doxyfile |
| 57 | + sed -i "s/PROJECT_NUMBER[[:space:]]*=[[:space:]]*\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/PROJECT_NUMBER = \"$VERSION\"/" Doxyfile |
| 58 | +
|
| 59 | + # Update vcpkg.json |
| 60 | + sed -i "s/\"version\":[[:space:]]*\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\": \"$VERSION\"/" vcpkg.json |
| 61 | +
|
| 62 | + # Update packaging/vcpkg-port/vcpkg.json |
| 63 | + sed -i "s/\"version\":[[:space:]]*\"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\": \"$VERSION\"/" packaging/vcpkg-port/vcpkg.json |
| 64 | +
|
| 65 | + # Update include/databricks/version.h |
| 66 | + sed -i "s/constexpr const char \*VERSION = \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/constexpr const char *VERSION = \"$VERSION\"/" include/databricks/version.h |
| 67 | +
|
| 68 | + # Update README.md - Latest Release line |
| 69 | + sed -i "s/\*\*Latest Release\*\*:[[:space:]]*\[v[0-9]\+\.[0-9]\+\.[0-9]\+\]/**Latest Release**: [v$VERSION]/" README.md |
| 70 | + sed -i "s|/releases/tag/v[0-9]\+\.[0-9]\+\.[0-9]\+|/releases/tag/v$VERSION|" README.md |
| 71 | +
|
| 72 | + echo "Version updated to $VERSION in all files" |
| 73 | +
|
| 74 | + - name: Generate release notes |
| 75 | + id: notes |
| 76 | + run: | |
| 77 | + PREV_TAG="${{ steps.version.outputs.prev_tag }}" |
| 78 | +
|
| 79 | + if [ "$PREV_TAG" = "v0.0.0" ]; then |
| 80 | + # First release - get all commits |
| 81 | + COMMITS=$(git log --pretty=format:"- %s (%h)" --reverse) |
| 82 | + else |
| 83 | + # Get commits since last tag |
| 84 | + COMMITS=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" --reverse) |
| 85 | + fi |
| 86 | +
|
| 87 | + # Create release notes |
| 88 | + cat > release_notes.md <<EOF |
| 89 | + ## What's Changed |
| 90 | +
|
| 91 | + $COMMITS |
| 92 | +
|
| 93 | + --- |
| 94 | +
|
| 95 | + **Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...v${{ steps.version.outputs.version }} |
| 96 | + EOF |
| 97 | +
|
| 98 | + echo "Generated release notes:" |
| 99 | + cat release_notes.md |
| 100 | +
|
| 101 | + - name: Commit version bump |
| 102 | + run: | |
| 103 | + git config user.name "github-actions[bot]" |
| 104 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 105 | + git add CMakeLists.txt Doxyfile vcpkg.json packaging/vcpkg-port/vcpkg.json include/databricks/version.h README.md |
| 106 | + git commit -m "chore: bump version to ${{ steps.version.outputs.version }}" |
| 107 | + git push origin main |
| 108 | +
|
| 109 | + - name: Create and push tag |
| 110 | + run: | |
| 111 | + git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" |
| 112 | + git push origin "v${{ steps.version.outputs.version }}" |
| 113 | +
|
| 114 | + - name: Create GitHub Release |
| 115 | + uses: softprops/action-gh-release@v2 |
| 116 | + with: |
| 117 | + tag_name: v${{ steps.version.outputs.version }} |
| 118 | + name: Release v${{ steps.version.outputs.version }} |
| 119 | + body_path: release_notes.md |
| 120 | + draft: false |
| 121 | + prerelease: false |
| 122 | + env: |
| 123 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments