|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_type: |
| 7 | + description: 'Type of version bump' |
| 8 | + required: true |
| 9 | + default: 'patch' |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - patch |
| 13 | + - minor |
| 14 | + - major |
| 15 | + custom_version: |
| 16 | + description: 'Custom version (optional, overrides version_type)' |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + prerelease: |
| 20 | + description: 'Create a prerelease' |
| 21 | + required: false |
| 22 | + default: false |
| 23 | + type: boolean |
| 24 | + |
| 25 | +jobs: |
| 26 | + release: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + permissions: |
| 29 | + contents: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - name: Determine version |
| 38 | + id: version |
| 39 | + run: | |
| 40 | + if [ -n "${{ github.event.inputs.custom_version }}" ]; then |
| 41 | + BASE_VERSION="${{ github.event.inputs.custom_version }}" |
| 42 | + else |
| 43 | + # Get current version from header file |
| 44 | + if [ ! -f "include/sparrow_ipc/config/sparrow_ipc_version.hpp" ]; then |
| 45 | + echo "Error: sparrow_ipc_version.hpp not found" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + |
| 49 | + CURRENT_MAJOR=$(grep "constexpr int SPARROW_IPC_VERSION_MAJOR" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 50 | + CURRENT_MINOR=$(grep "constexpr int SPARROW_IPC_VERSION_MINOR" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 51 | + CURRENT_PATCH=$(grep "constexpr int SPARROW_IPC_VERSION_PATCH" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 52 | + |
| 53 | + # Verify version numbers were found |
| 54 | + if [ -z "$CURRENT_MAJOR" ] || [ -z "$CURRENT_MINOR" ] || [ -z "$CURRENT_PATCH" ]; then |
| 55 | + echo "Error: Could not parse current version from header file" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + |
| 59 | + echo "Current version: ${CURRENT_MAJOR}.${CURRENT_MINOR}.${CURRENT_PATCH}" |
| 60 | + |
| 61 | + case "${{ github.event.inputs.version_type }}" in |
| 62 | + "major") |
| 63 | + BASE_VERSION="$((CURRENT_MAJOR + 1)).0.0" |
| 64 | + ;; |
| 65 | + "minor") |
| 66 | + BASE_VERSION="${CURRENT_MAJOR}.$((CURRENT_MINOR + 1)).0" |
| 67 | + ;; |
| 68 | + "patch") |
| 69 | + BASE_VERSION="${CURRENT_MAJOR}.${CURRENT_MINOR}.$((CURRENT_PATCH + 1))" |
| 70 | + ;; |
| 71 | + esac |
| 72 | + fi |
| 73 | + |
| 74 | + # Handle prerelease |
| 75 | + if [ "${{ github.event.inputs.prerelease }}" = "true" ]; then |
| 76 | + # Find existing prerelease tags for this version |
| 77 | + EXISTING_TAGS=$(git tag -l "${BASE_VERSION}_r*" | sort -V) |
| 78 | + |
| 79 | + if [ -z "$EXISTING_TAGS" ]; then |
| 80 | + # No existing prereleases, start with _r0 |
| 81 | + PRERELEASE_NUM=0 |
| 82 | + else |
| 83 | + # Get the highest prerelease number and increment |
| 84 | + LAST_TAG=$(echo "$EXISTING_TAGS" | tail -n 1) |
| 85 | + PRERELEASE_NUM=$(echo "$LAST_TAG" | sed "s/${BASE_VERSION}_r//" | sed 's/^0*//') |
| 86 | + if [ -z "$PRERELEASE_NUM" ]; then |
| 87 | + PRERELEASE_NUM=0 |
| 88 | + fi |
| 89 | + PRERELEASE_NUM=$((PRERELEASE_NUM + 1)) |
| 90 | + fi |
| 91 | + |
| 92 | + FINAL_VERSION="${BASE_VERSION}_r${PRERELEASE_NUM}" |
| 93 | + echo "is_prerelease=true" >> $GITHUB_OUTPUT |
| 94 | + else |
| 95 | + FINAL_VERSION="$BASE_VERSION" |
| 96 | + echo "is_prerelease=false" >> $GITHUB_OUTPUT |
| 97 | + fi |
| 98 | + |
| 99 | + echo "Final version: $FINAL_VERSION" |
| 100 | + echo "version=$FINAL_VERSION" >> $GITHUB_OUTPUT |
| 101 | + echo "base_version=$BASE_VERSION" >> $GITHUB_OUTPUT |
| 102 | + |
| 103 | + - name: Update version in header file |
| 104 | + run: | |
| 105 | + BASE_VERSION="${{ steps.version.outputs.base_version }}" |
| 106 | + IFS='.' read -r NEW_MAJOR NEW_MINOR NEW_PATCH <<< "$BASE_VERSION" |
| 107 | + |
| 108 | + # Only update header file for non-prerelease versions |
| 109 | + if [ "${{ steps.version.outputs.is_prerelease }}" = "false" ]; then |
| 110 | + # Get current binary version numbers |
| 111 | + CURRENT_BINARY=$(grep "constexpr int SPARROW_IPC_BINARY_CURRENT" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 112 | + CURRENT_REVISION=$(grep "constexpr int SPARROW_IPC_BINARY_REVISION" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 113 | + CURRENT_AGE=$(grep "constexpr int SPARROW_IPC_BINARY_AGE" include/sparrow_ipc/config/sparrow_ipc_version.hpp | awk '{print $5}' | tr -d ';') |
| 114 | +
|
| 115 | + echo "Current binary version: $CURRENT_BINARY:$CURRENT_REVISION:$CURRENT_AGE" |
| 116 | + |
| 117 | + # Apply libtool versioning rules based on version bump type |
| 118 | + case "${{ github.event.inputs.version_type }}" in |
| 119 | + "patch") |
| 120 | + # Patch release: only increment revision (compatible changes) |
| 121 | + NEW_BINARY_CURRENT=$CURRENT_BINARY |
| 122 | + NEW_BINARY_REVISION=$((CURRENT_REVISION + 1)) |
| 123 | + NEW_BINARY_AGE=$CURRENT_AGE |
| 124 | + ;; |
| 125 | + "minor") |
| 126 | + # Minor release: new APIs added, increment current and age, reset revision |
| 127 | + NEW_BINARY_CURRENT=$((CURRENT_BINARY + 1)) |
| 128 | + NEW_BINARY_REVISION=0 |
| 129 | + NEW_BINARY_AGE=$((CURRENT_AGE + 1)) |
| 130 | + ;; |
| 131 | + "major") |
| 132 | + # Major release: breaking changes, increment current, reset revision and age |
| 133 | + NEW_BINARY_CURRENT=$((CURRENT_BINARY + 1)) |
| 134 | + NEW_BINARY_REVISION=0 |
| 135 | + NEW_BINARY_AGE=0 |
| 136 | + ;; |
| 137 | + esac |
| 138 | + |
| 139 | + echo "New binary version: $NEW_BINARY_CURRENT:$NEW_BINARY_REVISION:$NEW_BINARY_AGE" |
| 140 | + |
| 141 | + # Update version numbers in header file |
| 142 | + sed -i "s/constexpr int SPARROW_IPC_VERSION_MAJOR = [0-9]*/constexpr int SPARROW_IPC_VERSION_MAJOR = $NEW_MAJOR/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 143 | + sed -i "s/constexpr int SPARROW_IPC_VERSION_MINOR = [0-9]*/constexpr int SPARROW_IPC_VERSION_MINOR = $NEW_MINOR/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 144 | + sed -i "s/constexpr int SPARROW_IPC_VERSION_PATCH = [0-9]*/constexpr int SPARROW_IPC_VERSION_PATCH = $NEW_PATCH/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 145 | + sed -i "s/constexpr int SPARROW_IPC_BINARY_CURRENT = [0-9]*/constexpr int SPARROW_IPC_BINARY_CURRENT = $NEW_BINARY_CURRENT/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 146 | + sed -i "s/constexpr int SPARROW_IPC_BINARY_REVISION = [0-9]*/constexpr int SPARROW_IPC_BINARY_REVISION = $NEW_BINARY_REVISION/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 147 | + sed -i "s/constexpr int SPARROW_IPC_BINARY_AGE = [0-9]*/constexpr int SPARROW_IPC_BINARY_AGE = $NEW_BINARY_AGE/" include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 148 | + |
| 149 | + git config --local user.name "GitHub Action" |
| 150 | + git add include/sparrow_ipc/config/sparrow_ipc_version.hpp |
| 151 | + git commit -m "Release version ${{ steps.version.outputs.version }}" |
| 152 | + else |
| 153 | + echo "Skipping header file update for prerelease" |
| 154 | + git config --local user.name "GitHub Action" |
| 155 | + fi |
| 156 | + |
| 157 | + - name: Create tag |
| 158 | + run: | |
| 159 | + git tag -a "${{ steps.version.outputs.version }}" -m "Release version ${{ steps.version.outputs.version }}" |
| 160 | + |
| 161 | + - name: Push changes and tag |
| 162 | + run: | |
| 163 | + git push origin main |
| 164 | + git push origin "${{ steps.version.outputs.version }}" |
| 165 | + |
| 166 | + - name: Create GitHub Release |
| 167 | + uses: elgohr/Github-Release-Action@v5 |
| 168 | + env: |
| 169 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 170 | + with: |
| 171 | + title: "Release ${{ steps.version.outputs.version }}" |
| 172 | + tag: "${{ steps.version.outputs.version }}" |
| 173 | + prerelease: ${{ steps.version.outputs.is_prerelease }} |
0 commit comments