diff --git a/.github/workflows/build-scuffle.yaml b/.github/workflows/build-scuffle.yaml new file mode 100644 index 000000000000..41148bd626fe --- /dev/null +++ b/.github/workflows/build-scuffle.yaml @@ -0,0 +1,235 @@ +name: Release rust-analyzer +on: + workflow_dispatch: + push: + branches: + - scuffle-fork + +defaults: + run: + shell: bash + +env: + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + RUSTFLAGS: "-D warnings -W unreachable-pub" + RUSTUP_MAX_RETRIES: 10 + FETCH_DEPTH: 0 + MACOSX_DEPLOYMENT_TARGET: 14.0 + ZIG_VERSION: 0.13.0 + ZIGBUILD_VERSION: 0.19.8 + +jobs: + builds: + strategy: + matrix: + include: + - runner: ubuntu-22.04 + os: linux + arch: x86_64 + target: x86_64-unknown-linux-gnu + container: quay.io/pypa/manylinux_2_28_x86_64 + pgo: clap-rs/clap@v4.5.36 + - runner: ubuntu-22.04-arm + os: linux + arch: aarch64 + target: aarch64-unknown-linux-gnu + container: quay.io/pypa/manylinux_2_28_aarch64 + pgo: clap-rs/clap@v4.5.36 + - runner: windows-2022 + os: windows + arch: x86_64 + target: x86_64-pc-windows-msvc + pgo: clap-rs/clap@v4.5.36 + - runner: macos-13 + os: darwin + arch: x86_64 + target: x86_64-apple-darwin + pgo: clap-rs/clap@v4.5.36 + - runner: macos-14 + os: darwin + arch: aarch64 + target: aarch64-apple-darwin + pgo: clap-rs/clap@v4.5.36 + + runs-on: ${{ matrix.runner }} + container: ${{ matrix.container }} + env: + NAME: "rust-analyzer-${{ matrix.os }}-${{ matrix.arch }}" + RA_TARGET: ${{ matrix.target }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: ${{ env.FETCH_DEPTH }} + + - name: Install zstd + if: ${{ runner.os == 'Windows' }} + uses: MinoruSekine/setup-scoop@v4.0.2 + with: + buckets: main + apps: zstd + + - name: Install rustup + if: ${{ matrix.container }} + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Install Rust toolchain + run: | + rustup update --no-self-update stable + rustup component add rust-src ${{ matrix.pgo && 'llvm-tools' || '' }} + rustup target add ${{ matrix.target }} + + - name: Build rust-analyzer + run: cargo xtask dist --client-patch-version ${{ github.run_number }} ${{ matrix.pgo && format('--pgo {0}', matrix.pgo) || ''}} + + - name: Generate archive + run: | + mkdir -p artifacts-archive + BIN_NAME="rust-analyzer${{ runner.os == 'Windows' && '.exe' || '' }}" + + mkdir -p "${NAME}" + cp "dist/${BIN_NAME}" "${NAME}/" + + tar -cf - "${NAME}" | zstd --ultra -22 -o "artifacts-archive/${NAME}.tar.zst" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.NAME }} + path: artifacts-archive/${{ env.NAME }}.tar.zst + + release: + needs: builds + runs-on: ubuntu-22.04 + permissions: + contents: write + env: + TAG_NAME: commit-${{ github.sha }} + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: ./artifacts + + - name: Generate dotslash file + run: | + set -euo pipefail + shopt -s globstar + + BASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ env.TAG_NAME }}/" + + cat > rust-analyzer <<'EOF' + #!/usr/bin/env dotslash + + { + "name": "rust-analyzer", + "platforms": { + EOF + + for archive in ./artifacts/**/*.tar.zst; do + FILE_NAME=$(basename "$archive") + SHA=$(sha256sum "$archive" | awk '{print $1}') + NAME="${FILE_NAME%.tar.zst}" + + # Parse os and arch from name + if [[ "$NAME" =~ rust-analyzer-([^-]+)-([^-]+) ]]; then + OS="${BASH_REMATCH[1]}" + ARCH="${BASH_REMATCH[2]}" + + # Map to dotslash format + case "$OS-$ARCH" in + "linux-x86_64") + PLATFORM="linux-x86_64" + ;; + "linux-aarch64") + PLATFORM="linux-aarch64" + ;; + "darwin-x86_64") + PLATFORM="macos-x86_64" + ;; + "darwin-aarch64") + PLATFORM="macos-aarch64" + ;; + "windows-x86_64") + PLATFORM="windows-x86_64" + ;; + *) + echo "Unknown platform: $OS-$ARCH" + continue + ;; + esac + + cat >> rust-analyzer </dev/null || stat -f%z "$archive"), + "hash": "sha256", + "digest": "$SHA", + "format": "tar.zst", + "path": "$NAME/rust-analyzer", + "providers": [ + { + "url": "${BASE_URL}${FILE_NAME}" + } + ] + }, + EOF + fi + done + + # Remove trailing comma and close JSON + sed -i '$ s/,$//' rust-analyzer + cat >> rust-analyzer <<'EOF' + } + } + EOF + + cat rust-analyzer + + - name: Generate release body + run: | + set -euo pipefail + shopt -s globstar + + cat > release_body.txt <> release_body.txt + done + + cat release_body.txt + env: + BASE_URL: "https://github.com/${{ github.repository }}/releases/download/${{ env.TAG_NAME }}/" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.TAG_NAME }} + name: "rust-analyzer build for ${{ github.sha }}" + body_path: release_body.txt + files: | + ./artifacts/**/*.tar.zst + rust-analyzer + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}