|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v[0-9]+.[0-9]+.[0-9]+* |
| 7 | + # Manual dry run: builds and uploads workflow artifacts, but never |
| 8 | + # publishes a GitHub release. |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + RUST_BACKTRACE: 1 |
| 14 | + NYDUS_FEATURES: cli,uffd,fanotify,backend-dragonfly-proxy |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: release-${{ github.ref }} |
| 21 | + cancel-in-progress: false |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: Build ${{ matrix.arch }} static binaries |
| 26 | + runs-on: ${{ matrix.runner }} |
| 27 | + timeout-minutes: 90 |
| 28 | + strategy: |
| 29 | + fail-fast: false |
| 30 | + matrix: |
| 31 | + include: |
| 32 | + - arch: amd64 |
| 33 | + runner: ubuntu-24.04 |
| 34 | + target: x86_64-unknown-linux-musl |
| 35 | + - arch: arm64 |
| 36 | + runner: ubuntu-24.04-arm |
| 37 | + target: aarch64-unknown-linux-musl |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v6 |
| 41 | + with: |
| 42 | + # Tags are needed for the dry-run tarball name fallback. |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Rust cache |
| 46 | + uses: Swatinem/rust-cache@v2 |
| 47 | + with: |
| 48 | + cache-on-failure: true |
| 49 | + shared-key: release-${{ matrix.arch }} |
| 50 | + |
| 51 | + - name: Install Protoc |
| 52 | + uses: arduino/setup-protoc@v3 |
| 53 | + with: |
| 54 | + repo-token: ${{ secrets.GH_TOKEN }} |
| 55 | + |
| 56 | + - name: Install musl toolchain |
| 57 | + run: | |
| 58 | + sudo apt-get update |
| 59 | + # perl/make are needed by openssl-src, which builds OpenSSL from |
| 60 | + # source for the musl target (dragonfly-client-util vendors it). |
| 61 | + sudo apt-get install -y --no-install-recommends \ |
| 62 | + musl-tools musl-dev pkg-config perl make file |
| 63 | +
|
| 64 | + - name: Add Rust musl target |
| 65 | + run: rustup target add ${{ matrix.target }} |
| 66 | + |
| 67 | + - name: Build nydus |
| 68 | + env: |
| 69 | + RUSTFLAGS: -C target-feature=+crt-static |
| 70 | + CC_x86_64_unknown_linux_musl: musl-gcc |
| 71 | + CC_aarch64_unknown_linux_musl: musl-gcc |
| 72 | + run: | |
| 73 | + cargo build -p nydus --release \ |
| 74 | + --target ${{ matrix.target }} \ |
| 75 | + --features "${NYDUS_FEATURES}" |
| 76 | +
|
| 77 | + - name: Set up Go |
| 78 | + uses: actions/setup-go@v6 |
| 79 | + with: |
| 80 | + # docker/cli guards `cli/config/configfile` with `//go:build go1.25`, |
| 81 | + # so the go.mod directive (1.24.2) is not enough to build nydusify. |
| 82 | + go-version: "1.25.5" |
| 83 | + cache-dependency-path: nydusify/go.sum |
| 84 | + |
| 85 | + - name: Build nydusify |
| 86 | + env: |
| 87 | + CGO_ENABLED: "0" |
| 88 | + GOOS: linux |
| 89 | + GOARCH: ${{ matrix.arch }} |
| 90 | + run: | |
| 91 | + cd nydusify |
| 92 | + go build -ldflags "-s -w" -o nydusify . |
| 93 | +
|
| 94 | + - name: Assemble release directory |
| 95 | + run: | |
| 96 | + mkdir -p nydus-static |
| 97 | + cp target/${{ matrix.target }}/release/nydus nydus-static/ |
| 98 | + cp nydusify/nydusify nydus-static/ |
| 99 | + cp config.yaml nydus-static/ |
| 100 | + chmod +x nydus-static/nydus nydus-static/nydusify |
| 101 | +
|
| 102 | + - name: Verify binaries are static |
| 103 | + run: | |
| 104 | + for bin in nydus-static/nydus nydus-static/nydusify; do |
| 105 | + echo "== ${bin}" |
| 106 | + file "${bin}" |
| 107 | + # musl release builds come out as `static-pie linked`, while the |
| 108 | + # CGO-free Go binary is plain `statically linked`. |
| 109 | + file "${bin}" | grep -Eq 'statically linked|static-pie linked' |
| 110 | + done |
| 111 | + ./nydus-static/nydus --help > /dev/null |
| 112 | + ./nydus-static/nydusify --help > /dev/null |
| 113 | +
|
| 114 | + - name: Create release tarball |
| 115 | + run: | |
| 116 | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then |
| 117 | + tag="${GITHUB_REF_NAME}" |
| 118 | + else |
| 119 | + tag=$(git describe --match 'v[0-9]*' --always --tags) |
| 120 | + fi |
| 121 | + tarball="nydus-static-${tag}-linux-${{ matrix.arch }}.tgz" |
| 122 | + tar cf - nydus-static | gzip > "${tarball}" |
| 123 | + sha256sum "${tarball}" > "${tarball}.sha256sum" |
| 124 | + echo "tarball=${tarball}" >> "${GITHUB_ENV}" |
| 125 | +
|
| 126 | + - name: Upload artifacts |
| 127 | + uses: actions/upload-artifact@v6 |
| 128 | + with: |
| 129 | + name: nydus-release-tarball-linux-${{ matrix.arch }} |
| 130 | + path: | |
| 131 | + ${{ env.tarball }} |
| 132 | + ${{ env.tarball }}.sha256sum |
| 133 | + if-no-files-found: error |
| 134 | + |
| 135 | + release: |
| 136 | + name: Publish GitHub release |
| 137 | + needs: [build] |
| 138 | + if: startsWith(github.ref, 'refs/tags/') |
| 139 | + runs-on: ubuntu-24.04 |
| 140 | + timeout-minutes: 30 |
| 141 | + permissions: |
| 142 | + contents: write |
| 143 | + steps: |
| 144 | + - name: Download artifacts |
| 145 | + uses: actions/download-artifact@v7 |
| 146 | + with: |
| 147 | + pattern: nydus-release-tarball-* |
| 148 | + merge-multiple: true |
| 149 | + path: nydus-tarball |
| 150 | + |
| 151 | + - name: Publish release |
| 152 | + uses: softprops/action-gh-release@v2 |
| 153 | + with: |
| 154 | + name: Nydus ${{ github.ref_name }} |
| 155 | + generate_release_notes: true |
| 156 | + prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-alpha') || contains(github.ref_name, '-beta') }} |
| 157 | + files: nydus-tarball/* |
| 158 | + fail_on_unmatched_files: true |
0 commit comments