|
| 1 | +name: Common Build Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + description: "Release tag name for testing (e.g., 2.1.2)" |
| 8 | + required: false |
| 9 | + default: "" |
| 10 | + type: string |
| 11 | + build_archs: |
| 12 | + description: "Build arch to build for" |
| 13 | + required: false |
| 14 | + default: '["i386", "amd64", "arm64", "armhf"]' |
| 15 | + type: string |
| 16 | + build_dists: |
| 17 | + description: "Distributions to build for (comma-separated, e.g., focal,jammy, noble)" |
| 18 | + required: false |
| 19 | + default: '["noble", "jammy", "focal", "bionic", "bookworm", "bullseye", "buster"]' |
| 20 | + type: string |
| 21 | + smoke_test_images: |
| 22 | + description: "Docker images for smoke testing (comma-separated, e.g., ubuntu:20.04,ubuntu:22.04,ubuntu:24.04)" |
| 23 | + required: false |
| 24 | + default: '["ubuntu:noble", "ubuntu:jammy", "debian:bookworm", "debian:bullseye"]' |
| 25 | + type: string |
| 26 | + build_exclude: |
| 27 | + description: "Distributions to exclude build" |
| 28 | + required: false |
| 29 | + default: '[{"dist": "focal", "arch": "i386"}, {"dist": "jammy", "arch": "i386"}, {"dist": "noble", "arch": "i386"}]' |
| 30 | + type: string |
| 31 | + build_runner: |
| 32 | + description: "os in which build steps run on" |
| 33 | + required: false |
| 34 | + default: "ubuntu-22.04" |
| 35 | + type: string |
| 36 | + |
| 37 | +jobs: |
| 38 | + build-source-package: |
| 39 | + runs-on: ${{ inputs.build_runner }} |
| 40 | + continue-on-error: true |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + dist: ${{ fromJSON(inputs.build_dists) }} |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + path: sources |
| 48 | + - name: Validate configure.ac version matches GitHub Release (only on release) |
| 49 | + if: github.event.release.tag_name != '' |
| 50 | + env: |
| 51 | + VERSION: ${{ github.event.release.tag_name }} |
| 52 | + run: | |
| 53 | + # Extract the current version from configure.ac |
| 54 | + CURRENT_VERSION=$(awk -F'[(),]' '/AC_INIT/ {print $3}' sources/configure.ac | tr -d ' ') |
| 55 | +
|
| 56 | + echo "Current configure.ac version: $CURRENT_VERSION" |
| 57 | + echo "GitHub Release version: $VERSION" |
| 58 | +
|
| 59 | + # Check if versions match |
| 60 | + if [ "$CURRENT_VERSION" != "$VERSION" ]; then |
| 61 | + echo "❌ Version mismatch! configure.ac: $CURRENT_VERSION, GitHub Release: $VERSION" |
| 62 | + exit 1 # Fail the build |
| 63 | + else |
| 64 | + echo "Version match. Proceeding with the build." |
| 65 | + fi |
| 66 | + - name: Install dependencies |
| 67 | + run: | |
| 68 | + sudo apt-get update && \ |
| 69 | + sudo apt-get install \ |
| 70 | + build-essential autoconf automake libpcre3-dev libevent-dev \ |
| 71 | + pkg-config zlib1g-dev libssl-dev libboost-all-dev cmake flex \ |
| 72 | + debhelper dput |
| 73 | + - name: Create changelog |
| 74 | + env: |
| 75 | + VERSION: ${{ github.event.inputs.tag_name || github.event.release.tag_name }} |
| 76 | + DIST: ${{ matrix.dist }} |
| 77 | + run: | |
| 78 | + # for testing purposes if the version is empty (CI) we use 0.0.1 |
| 79 | + if [ -z "$VERSION" ]; then |
| 80 | + VERSION="0.0.1~test" |
| 81 | + fi |
| 82 | + mkdir -p sources/debian |
| 83 | + if [ "${{ github.event_name }}" = "release" ]; then |
| 84 | + RELEASE_URL=": ${{ github.event.release.html_url }}" |
| 85 | + else |
| 86 | + RELEASE_URL="" |
| 87 | + fi |
| 88 | + (echo "memtier-benchmark ($VERSION~$DIST) $DIST; urgency=medium" |
| 89 | + echo "" |
| 90 | + echo " * Release $VERSION$RELEASE_URL" |
| 91 | + echo "" |
| 92 | + echo " -- Redis Team <[email protected]> $(date -R)") > sources/debian/changelog |
| 93 | + - name: Build source package |
| 94 | + run: | |
| 95 | + cd sources && dpkg-buildpackage -S |
| 96 | + - name: Upload source package artifact |
| 97 | + uses: actions/upload-artifact@v4 |
| 98 | + with: |
| 99 | + name: source-${{ matrix.dist }} |
| 100 | + path: | |
| 101 | + *.debian.tar.* |
| 102 | + *.dsc |
| 103 | + memtier-benchmark_*.tar.* |
| 104 | +
|
| 105 | + build-binary-package: |
| 106 | + runs-on: ${{ inputs.build_runner }} |
| 107 | + environment: build |
| 108 | + continue-on-error: true |
| 109 | + strategy: |
| 110 | + matrix: |
| 111 | + dist: ${{ fromJSON(inputs.build_dists) }} |
| 112 | + arch: ${{ fromJSON(inputs.build_archs) }} |
| 113 | + exclude: ${{ fromJSON(inputs.build_exclude) }} |
| 114 | + needs: build-source-package |
| 115 | + steps: |
| 116 | + - uses: actions/checkout@v4 |
| 117 | + - name: Determine build architecture |
| 118 | + run: | |
| 119 | + if [ ${{ matrix.arch }} = "i386" ]; then |
| 120 | + BUILD_ARCH=i386 |
| 121 | + else |
| 122 | + BUILD_ARCH=amd64 |
| 123 | + fi |
| 124 | + echo "BUILD_ARCH=${BUILD_ARCH}" >> $GITHUB_ENV |
| 125 | + # Only setup APT signing key for releases, not for CI testing |
| 126 | + - name: Setup APT Signing key |
| 127 | + if: github.event_name == 'release' |
| 128 | + run: | |
| 129 | + mkdir -m 0700 -p ~/.gnupg |
| 130 | + echo "$APT_SIGNING_KEY" | gpg --import |
| 131 | + env: |
| 132 | + APT_SIGNING_KEY: ${{ secrets.APT_SIGNING_KEY }} |
| 133 | + |
| 134 | + - name: Install dependencies |
| 135 | + run: | |
| 136 | + sudo apt-get update && \ |
| 137 | + sudo apt-get install -y \ |
| 138 | + sbuild schroot debootstrap |
| 139 | + sudo sbuild-adduser $USER |
| 140 | +
|
| 141 | + - name: Prepare sbuild environment |
| 142 | + run: sudo ./debian/setup_sbuild.sh ${{ matrix.dist }} ${{ env.BUILD_ARCH }} |
| 143 | + - name: Get source package |
| 144 | + uses: actions/download-artifact@v4 |
| 145 | + with: |
| 146 | + name: source-${{ matrix.dist }} |
| 147 | + - name: Build binary package |
| 148 | + run: | |
| 149 | + sudo sbuild \ |
| 150 | + --nolog \ |
| 151 | + --host ${{ matrix.arch }} \ |
| 152 | + --build ${{ env.BUILD_ARCH }} \ |
| 153 | + --dist ${{ matrix.dist }} *.dsc |
| 154 | + - name: Upload binary package artifact |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: binary-${{ matrix.dist }}-${{ matrix.arch }} |
| 158 | + path: | |
| 159 | + *.deb |
| 160 | + - name: Upload as release assets |
| 161 | + # we don't upload on workflow dispatch and on forks |
| 162 | + if: github.event_name == 'release' && github.repository == 'redislabs/memtier_benchmark' |
| 163 | + uses: softprops/action-gh-release@v1 |
| 164 | + with: |
| 165 | + files: | |
| 166 | + *.deb |
| 167 | +
|
| 168 | + smoke-test-packages: |
| 169 | + runs-on: ${{ inputs.build_runner }} |
| 170 | + needs: build-binary-package |
| 171 | + env: |
| 172 | + ARCH: amd64 |
| 173 | + strategy: |
| 174 | + matrix: |
| 175 | + image: ${{ fromJSON(inputs.smoke_test_images) }} |
| 176 | + container: ${{ matrix.image }} |
| 177 | + steps: |
| 178 | + - name: Extract BUILD_ARCH from matrix.image |
| 179 | + run: | |
| 180 | + BUILD_ARCH=$(echo ${{ matrix.image }} | cut -d: -f2) |
| 181 | + if [ -z "$BUILD_ARCH" ]; then |
| 182 | + echo "Error: Failed to extract BUILD_ARCH from matrix.image" >&2 |
| 183 | + exit 1 |
| 184 | + fi |
| 185 | + echo "BUILD_ARCH=$BUILD_ARCH" >> $GITHUB_ENV |
| 186 | + - name: Get binary packages for other versions |
| 187 | + if: matrix.image != 'ubuntu:bionic' |
| 188 | + uses: actions/download-artifact@v4 |
| 189 | + with: |
| 190 | + name: binary-${{ env.BUILD_ARCH }}-${{ env.ARCH }} |
| 191 | + path: binary-${{ env.BUILD_ARCH }}-${{ env.ARCH }} |
| 192 | + - name: Install packages |
| 193 | + run: | |
| 194 | + apt-get update |
| 195 | + cd binary-${{ env.BUILD_ARCH }}-${{ env.ARCH }} && apt install --yes ./*.deb |
0 commit comments