|
| 1 | +name: "CI" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + Docker: |
| 7 | + required: false |
| 8 | + default: false |
| 9 | + type: boolean |
| 10 | + Release: |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + |
| 15 | +# TODO Comment out the next 2 lines so that it won't interfere with the old CI when tagging a version |
| 16 | +# Should fix after deprecate the old CI(build.yml) |
| 17 | +# push: |
| 18 | +# tags: ["v*.*.*"] |
| 19 | + |
| 20 | +env: |
| 21 | + SCCACHE_GHA_ENABLED: true |
| 22 | + RUSTC_WRAPPER: sccache |
| 23 | + CARGO_TERM_COLOR: always |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + linux: |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - target: x86_64-unknown-linux-gnu |
| 36 | + - target: x86_64-unknown-linux-musl |
| 37 | + - target: aarch64-unknown-linux-gnu |
| 38 | + build_env: "JEMALLOC_SYS_WITH_LG_PAGE=16" |
| 39 | + - target: aarch64-unknown-linux-musl |
| 40 | + build_env: "JEMALLOC_SYS_WITH_LG_PAGE=16" |
| 41 | + - target: armv7-unknown-linux-gnueabihf |
| 42 | + build_env: "JEMALLOC_SYS_WITH_LG_PAGE=16" |
| 43 | + - target: armv7-unknown-linux-musleabihf |
| 44 | + build_env: "JEMALLOC_SYS_WITH_LG_PAGE=16" |
| 45 | + - target: arm-unknown-linux-gnueabihf |
| 46 | + - target: arm-unknown-linux-musleabihf |
| 47 | + |
| 48 | + name: Build / ${{matrix.target}} |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Extract Metadata for Docker |
| 55 | + uses: docker/metadata-action@v5 |
| 56 | + id: meta |
| 57 | + with: |
| 58 | + images: | |
| 59 | + ${{github.repository}} |
| 60 | + ghcr.io/${{github.repository}} |
| 61 | + flavor: | |
| 62 | + suffix=${{ endsWith(matrix.target, 'musl') && '-alpine' || '' }},onlatest=true |
| 63 | + tags: | |
| 64 | + type=ref,event=tag |
| 65 | + type=edge,branch=main |
| 66 | + type=semver,pattern=v{{major}}.{{minor}} |
| 67 | +
|
| 68 | + - name: Set up QEMU |
| 69 | + uses: docker/setup-qemu-action@v3 |
| 70 | + |
| 71 | + - name: Set up Docker Buildx |
| 72 | + uses: docker/setup-buildx-action@v3 |
| 73 | + |
| 74 | + - name: Log In to GitHub Container Registry |
| 75 | + uses: docker/login-action@v3 |
| 76 | + with: |
| 77 | + registry: ghcr.io |
| 78 | + username: ${{github.repository_owner}} |
| 79 | + password: ${{github.token}} |
| 80 | + |
| 81 | + - name: Log In to DockerHub |
| 82 | + uses: docker/login-action@v3 |
| 83 | + env: |
| 84 | + dockerhub: ${{secrets.DOCKERHUB_USERNAME}}${{secrets.DOCKERHUB_TOKEN}} |
| 85 | + if: ${{ env.dockerhub != '' }} |
| 86 | + with: |
| 87 | + username: ${{secrets.DOCKERHUB_USERNAME}} |
| 88 | + password: ${{secrets.DOCKERHUB_TOKEN}} |
| 89 | + |
| 90 | + - name: Cache apt |
| 91 | + uses: actions/cache@v4 |
| 92 | + id: apt-cache |
| 93 | + with: |
| 94 | + path: | |
| 95 | + var-cache-apt |
| 96 | + var-lib-apt |
| 97 | + key: docker-apt-cache-${{ hashFiles('Dockerfile.build') }} |
| 98 | + |
| 99 | + - name: Calculate shasum of external deps |
| 100 | + id: cal-dep-shasum |
| 101 | + run: | |
| 102 | + echo "checksum=$(yq -p toml -oy '.package[] | select((.source | contains("")) or (.checksum | contains("")))' Cargo.lock | sha256sum | awk '{print $1}')" >> "$GITHUB_OUTPUT" |
| 103 | +
|
| 104 | + - name: Get latest zig version |
| 105 | + id: zig-version |
| 106 | + run: | |
| 107 | + echo "zig_version=$(curl -s "https://api.github.com/repos/ziglang/zig/releases/latest" | jq -r '.tag_name')" >> "$GITHUB_OUTPUT" |
| 108 | +
|
| 109 | + - name: Cache Cargo |
| 110 | + uses: actions/cache@v4 |
| 111 | + id: cargo-cache |
| 112 | + with: |
| 113 | + path: | |
| 114 | + usr-local-cargo-registry |
| 115 | + usr-local-cargo-git |
| 116 | + key: docker-cargo-cache-${{ steps.cal-dep-shasum.outputs.checksum }} |
| 117 | + |
| 118 | + - name: Inject cache into docker |
| 119 | + uses: reproducible-containers/[email protected] |
| 120 | + with: |
| 121 | + cache-map: | |
| 122 | + { |
| 123 | + "var-cache-apt": "/var/cache/apt", |
| 124 | + "var-lib-apt": "/var/lib/apt", |
| 125 | + "usr-local-cargo-registry": "/usr/local/cargo/registry", |
| 126 | + "usr-local-cargo-git": "/usr/local/cargo/git" |
| 127 | + } |
| 128 | + skip-extraction: ${{ steps.cargo-cache.outputs.cache-hit }} && ${{ steps.apt-cache.outputs.cache-hit }} |
| 129 | + |
| 130 | + - name: Build Artifact |
| 131 | + uses: docker/bake-action@v5 |
| 132 | + env: |
| 133 | + TARGET: ${{matrix.target}} |
| 134 | + DOCKER_BUILD_RECORD_UPLOAD: false |
| 135 | + ARTIFACT_REPO: ghcr.io/${{github.repository}} |
| 136 | + BUILD_ENV: ${{matrix.build_env}} |
| 137 | + ZIG_VERSION: ${{ steps.zig-version.outputs.zig_version }} |
| 138 | + with: |
| 139 | + files: | |
| 140 | + ./docker-bake.hcl |
| 141 | + ${{ steps.meta.outputs.bake-file }} |
| 142 | + targets: ${{(github.event_name == 'push' || inputs.Docker) && (startsWith(matrix.target, 'x86') || startsWith(matrix.target, 'aarch64')) && 'build,image' || 'build'}} |
| 143 | + |
| 144 | + - name: Upload Artifacts |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: ${{matrix.target}} |
| 148 | + path: | |
| 149 | + ./artifact |
| 150 | + !./artifact/*.json |
| 151 | +
|
| 152 | + windows: |
| 153 | + name: Build / ${{matrix.target}} |
| 154 | + runs-on: windows-latest |
| 155 | + strategy: |
| 156 | + fail-fast: false |
| 157 | + matrix: |
| 158 | + include: |
| 159 | + # - target: aarch64-pc-windows-msvc |
| 160 | + - target: x86_64-pc-windows-msvc |
| 161 | + |
| 162 | + steps: |
| 163 | + - name: Checkout |
| 164 | + uses: actions/checkout@v4 |
| 165 | + |
| 166 | + - name: Run sccache-cache |
| 167 | + uses: mozilla-actions/[email protected] |
| 168 | + with: |
| 169 | + disable_annotations: true |
| 170 | + |
| 171 | + - name: Build |
| 172 | + run: | |
| 173 | + rustup target add ${{matrix.target}} |
| 174 | + cargo build --release --target "${{matrix.target}}" -p mail-server -p stalwart-cli |
| 175 | + mkdir -p artifacts |
| 176 | + mv ./target/${{matrix.target}}/release/stalwart-mail.exe ./artifacts/stalwart-mail.exe |
| 177 | + mv ./target/${{matrix.target}}/release/stalwart-cli.exe ./artifacts/stalwart-cli.exe |
| 178 | +
|
| 179 | + - name: Upload Artifacts |
| 180 | + uses: actions/upload-artifact@v4 |
| 181 | + with: |
| 182 | + name: ${{matrix.target}} |
| 183 | + path: ./artifacts |
| 184 | + |
| 185 | + macos: |
| 186 | + name: Build / ${{matrix.target}} |
| 187 | + runs-on: macos-latest |
| 188 | + strategy: |
| 189 | + fail-fast: false |
| 190 | + matrix: |
| 191 | + include: |
| 192 | + - target: aarch64-apple-darwin |
| 193 | + - target: x86_64-apple-darwin |
| 194 | + steps: |
| 195 | + - name: Checkout |
| 196 | + uses: actions/checkout@v4 |
| 197 | + |
| 198 | + - name: Run sccache-cache |
| 199 | + uses: mozilla-actions/[email protected] |
| 200 | + with: |
| 201 | + disable_annotations: true |
| 202 | + |
| 203 | + - name: Build FoundationDB Edition |
| 204 | + run: | |
| 205 | + rustup target add ${{matrix.target}} |
| 206 | + # Get latest FoundationDB installer |
| 207 | + curl -Lo foundationdb.pkg "https://glare.now.sh/apple/foundationdb/${{startsWith(matrix.target, 'x86') && 'x86_64' || 'arm64'}}.pkg" |
| 208 | + sudo installer -allowUntrusted -dumplog -pkg foundationdb.pkg -target / |
| 209 | + cargo build --release --target "${{matrix.target}}" -p mail-server --no-default-features --features "foundationdb elastic s3 redis enterprise" |
| 210 | + mkdir -p artifacts |
| 211 | + mv ./target/${{matrix.target}}/release/stalwart-mail ./artifacts/stalwart-mail-foundationdb |
| 212 | +
|
| 213 | + - name: Build |
| 214 | + run: | |
| 215 | + rustup target add ${{matrix.target}} |
| 216 | + cargo build --release --target "${{matrix.target}}" -p mail-server -p stalwart-cli |
| 217 | + mkdir -p artifacts |
| 218 | + mv ./target/${{matrix.target}}/release/stalwart-mail ./artifacts/stalwart-mail |
| 219 | + mv ./target/${{matrix.target}}/release/stalwart-cli ./artifacts/stalwart-cli |
| 220 | +
|
| 221 | + - name: Upload Artifacts |
| 222 | + uses: actions/upload-artifact@v4 |
| 223 | + with: |
| 224 | + name: ${{matrix.target}} |
| 225 | + path: ./artifacts |
| 226 | + |
| 227 | + release: |
| 228 | + name: Release |
| 229 | + if: github.event_name == 'push' || inputs.Release |
| 230 | + needs: [linux, windows, macos] |
| 231 | + runs-on: ubuntu-latest |
| 232 | + steps: |
| 233 | + - name: Download Artifacts |
| 234 | + uses: actions/download-artifact@v4 |
| 235 | + with: |
| 236 | + path: ./archive |
| 237 | + |
| 238 | + - name: Compress |
| 239 | + run: | |
| 240 | + set -eux |
| 241 | + BASE_DIR="$(pwd)/archive" |
| 242 | + compress_files() { |
| 243 | + local dir="$1" |
| 244 | + cd "$dir" |
| 245 | + # Process each file in the directory |
| 246 | + for file in `ls`; do |
| 247 | + filename="${file%.*}" |
| 248 | + extension="${file##*.}" |
| 249 | + if [ "$extension" = "exe" ]; then |
| 250 | + 7z a -tzip "${filename}-${dir}.zip" "$file" > /dev/null |
| 251 | + else |
| 252 | + tar -czf "${filename}-${dir}.tar.gz" "$file" |
| 253 | + fi |
| 254 | + done |
| 255 | + cd $BASE_DIR |
| 256 | + } |
| 257 | + cd $BASE_DIR |
| 258 | + for arch_dir in `ls`; do |
| 259 | + dir_name=$(basename "$arch_dir") |
| 260 | + compress_files "$dir_name" |
| 261 | + done |
| 262 | +
|
| 263 | + - name: Release |
| 264 | + uses: softprops/action-gh-release@v2 |
| 265 | + with: |
| 266 | + files: | |
| 267 | + ./archive/**/*.tar.gz |
| 268 | + ./archive/**/*.zip |
| 269 | + prerelease: ${{!startsWith(github.ref, 'refs/tags/') || null}} |
| 270 | + tag_name: ${{!startsWith(github.ref, 'refs/tags/') && 'nightly' || null}} |
0 commit comments