Merge pull request #58 from posit-dev/feature/resource-usage #222
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Build Kallichore Release" | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| # Extract the current version of Kallichore from its Cargo.toml file. | |
| get_version: | |
| name: Determine Kallichore Version | |
| runs-on: ubuntu-latest | |
| outputs: | |
| KALLICHORE_VERSION: ${{ steps.extract_version.outputs.result }} | |
| steps: | |
| # Checkout sources | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| # Extract version | |
| - name: Determine Version | |
| id: extract_version | |
| run: | | |
| VERSION=$(cat crates/kcserver/Cargo.toml | grep '^version' | head -1 | sed -e "s/[^.0-9]//g") | |
| echo "Kallichore version: ${VERSION}" | |
| echo "Found version ${VERSION}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "result=${VERSION}" >> "$GITHUB_OUTPUT" | |
| # Check to see whether we have already released this version. If we have, we will skip the | |
| # release process later on. | |
| check_release: | |
| name: Check for Existing Release | |
| runs-on: ubuntu-latest | |
| needs: [get_version] | |
| outputs: | |
| EXISTING_RELEASE: ${{ steps.release_flag.outputs.result }} | |
| steps: | |
| - name: Check for existing release tag | |
| uses: mukunku/tag-exists-action@v1.3.0 | |
| id: check_tag | |
| with: | |
| tag: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| - name: Set release flag | |
| id: release_flag | |
| run: | | |
| echo "Existing ${{ needs.get_version.outputs.KALLICHORE_VERSION }} release: ${{steps.check_tag.outputs.exists}}" | |
| echo "result=${{steps.check_tag.outputs.exists}}" >> $GITHUB_OUTPUT | |
| do_release: | |
| name: Trigger a new release | |
| if: ${{ needs.check_release.outputs.EXISTING_RELEASE == 'false' && github.ref == 'refs/heads/main' }} | |
| runs-on: ubuntu-latest | |
| needs: [check_release] | |
| steps: | |
| - name: Dummy step | |
| run: echo "" | |
| # Build Kallichore for macOS. Both arm64 (Apple Silicon) and x64 (Intel) hosts. | |
| build_macos: | |
| name: Build macOS | |
| runs-on: macos-latest | |
| needs: [get_version] | |
| timeout-minutes: 40 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| DEBUG_FLAG: ${{ matrix.flavor == 'debug' && '-debug' || '' }} | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| arch: [arm64, x64] | |
| flavor: [debug, release] | |
| include: | |
| - arch: arm64 | |
| arch_terminal: arm64 | |
| homebrew_folder: /opt/homebrew | |
| rust_target_prefix: aarch64 | |
| - arch: x64 | |
| arch_terminal: x86_64 | |
| homebrew_folder: /usr/local | |
| rust_target_prefix: x86_64 | |
| steps: | |
| - name: Install Rust toolchain | |
| run: | | |
| rustup update --no-self-update stable | |
| rustup default stable | |
| - name: Setup for x86 cross-compiling | |
| if: matrix.arch == 'x64' | |
| run: | | |
| # Install x86 homebrew | |
| arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| # Install x86 Rust target | |
| rustup target add x86_64-apple-darwin | |
| # Checkout sources | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| # Zeromq calls whatever pkg-config version is findable on the PATH to be able to locate | |
| # libsodium, so we have to ensure the x86_64 version is first on the PATH when compiling for | |
| # that architecture, so that it finds the x86_64 version of libsodium for zeromq to link against. | |
| - name: Update PATH to pkg-config for zeromq | |
| id: update_path_for_zeromq | |
| if: matrix.arch == 'x64' | |
| run: | | |
| echo "${{matrix.homebrew_folder}}/bin" >> $GITHUB_PATH | |
| # Compile | |
| - name: Compile Kallichore (${{ matrix.arch }}) | |
| env: | |
| npm_config_arch: ${{ matrix.arch }} | |
| KALLICHORE_BUILD_TYPE: ${{ matrix.flavor }} | |
| RUST_TARGET: ${{ matrix.rust_target_prefix }}-apple-darwin | |
| CARGO_FLAGS: | |
| PKG_CONFIG_ALLOW_CROSS: 1 | |
| run: | | |
| cargo clean | |
| cargo build ${{ matrix.flavor == 'release' && '--release' || '' }} --target ${{ matrix.rust_target_prefix }}-apple-darwin | |
| # Compress server to a zip file | |
| - name: Create archive | |
| run: | | |
| # Enter the build directory | |
| pushd target/${{ matrix.rust_target_prefix }}-apple-darwin/${{ matrix.flavor }} | |
| # Compress the server to an archive | |
| ARCHIVE="$GITHUB_WORKSPACE/kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}${{ env.DEBUG_FLAG }}-darwin-${{ matrix.arch }}.zip" | |
| [ -e LICENSE.txt ] || cp "$GITHUB_WORKSPACE/LICENSE.txt" LICENSE.txt | |
| zip -Xry $ARCHIVE kcserver LICENSE.txt | |
| popd | |
| # Create build artifact | |
| - name: Upload client archive | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-darwin-${{ matrix.arch }}-archive | |
| path: kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}${{ env.DEBUG_FLAG }}-darwin-${{ matrix.arch }}.zip | |
| build_windows: | |
| name: Build Windows | |
| runs-on: ${{ matrix.os }} | |
| timeout-minutes: 40 | |
| needs: [get_version] | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| strategy: | |
| matrix: | |
| arch: [x64, arm64] | |
| flavor: [debug, release] | |
| include: | |
| - arch: x64 | |
| rust_target_prefix: x86_64 | |
| os: windows-latest | |
| - arch: arm64 | |
| rust_target_prefix: aarch64 | |
| os: windows-11-arm | |
| steps: | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies (Windows) | |
| run: | | |
| vcpkg install zeromq:${{ matrix.arch }}-windows | |
| shell: cmd | |
| - name: Compile Kallichore | |
| env: | |
| Kallichore_BUILD_TYPE: ${{ matrix.flavor }} | |
| RUST_TARGET: ${{ matrix.rust_target_prefix }}-pc-windows-msvc | |
| shell: cmd | |
| run: | | |
| cargo clean | |
| cargo build ${{ matrix.flavor == 'release' && '--release' || '' }} --target ${{ matrix.rust_target_prefix }}-pc-windows-msvc | |
| - name: Upload unsigned executable for signing | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-windows-${{ matrix.arch }}-unsigned | |
| path: target\${{ matrix.rust_target_prefix }}-pc-windows-msvc\${{ matrix.flavor }}\kcserver.exe | |
| build_linux: | |
| name: "Build Linux" | |
| uses: ./.github/workflows/release-linux.yml | |
| needs: [get_version] | |
| secrets: inherit | |
| with: | |
| version: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| sign_windows: | |
| name: "Sign Windows Binaries" | |
| uses: posit-dev/posit-gh-actions/.github/workflows/sign-windows.yml@main | |
| needs: [build_windows, get_version] | |
| secrets: inherit | |
| strategy: | |
| matrix: | |
| arch: [x64, arm64] | |
| flavor: [debug, release] | |
| with: | |
| unsigned_artifact_name: kallichore-${{ matrix.flavor }}-windows-${{ matrix.arch }}-unsigned | |
| signed_artifact_name: kallichore-${{ matrix.flavor }}-windows-${{ matrix.arch }}-signed | |
| repackage_signed_windows: | |
| name: Repackage Signed Windows Binaries | |
| runs-on: windows-latest | |
| needs: [sign_windows, get_version] | |
| strategy: | |
| matrix: | |
| arch: [x64, arm64] | |
| flavor: [debug, release] | |
| steps: | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| - name: Download signed executable | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-windows-${{ matrix.arch }}-signed | |
| path: signed | |
| - name: Create signed archive | |
| shell: pwsh | |
| run: | | |
| # Create the signed archive with the signed executable and license | |
| $params = @{ | |
| Path = "signed\kcserver.exe", "LICENSE.txt" | |
| DestinationPath = "kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}-${{ matrix.flavor }}-windows-${{ matrix.arch }}.zip" | |
| } | |
| Compress-Archive @params | |
| - name: Upload signed archive | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-windows-${{ matrix.arch }}-signed-archive | |
| path: kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}-${{ matrix.flavor }}-windows-${{ matrix.arch }}.zip | |
| create_release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: [do_release, get_version, build_macos, repackage_signed_windows, build_linux] | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| steps: | |
| - name: Create release | |
| uses: actions/create-release@v1 | |
| id: create_release | |
| with: | |
| draft: false | |
| prerelease: true | |
| release_name: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| tag_name: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| # Uploads binaries, if we created a release | |
| upload_release_binaries: | |
| name: Upload Release Binaries | |
| runs-on: macos-latest | |
| needs: [create_release, get_version] | |
| permissions: | |
| contents: write # Required for creating a tag and release | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| DEBUG_FLAG: ${{ matrix.flavor == 'debug' && '-debug' || '' }} | |
| RELEASE_TAG: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| flavor: [debug, release] | |
| steps: | |
| # Download all binaries | |
| - name: Download Kallichore for macOS arm64 server (${{ matrix.flavor }}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-darwin-arm64-archive | |
| - name: Download Kallichore for macOS x64 (${{ matrix.flavor}}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-darwin-x64-archive | |
| - name: Download Kallichore for Windows x64 (${{ matrix.flavor}}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-windows-x64-signed-archive | |
| - name: Download Kallichore for Windows arm64 (${{ matrix.flavor}}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-windows-arm64-signed-archive | |
| - name: Download Kallichore for Linux x64 (${{ matrix.flavor}}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-linux-x64-archive | |
| - name: Download Kallichore for Linux arm64 (${{ matrix.flavor}}) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: kallichore-${{ matrix.flavor }}-linux-arm64-archive | |
| # Combine macOS binaries to a single binary with lipo | |
| - name: Create macOS universal binary | |
| run: | | |
| # Decompress x64 builds | |
| rm -rf x64 && mkdir x64 && pushd x64 | |
| unzip ../kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-x64.zip | |
| popd | |
| # Decompress arm64 build | |
| rm -rf arm64 && mkdir arm64 && pushd arm64 | |
| unzip ../kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-arm64.zip | |
| popd | |
| # Create a universal binary | |
| lipo -create x64/kcserver arm64/kcserver -output kcserver | |
| # Copy the license | |
| cp arm64/LICENSE.txt LICENSE.txt | |
| # Compress and bundle | |
| ARCHIVE="$GITHUB_WORKSPACE/kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-universal.zip" | |
| [ -e LICENSE.txt ] || cp "$GITHUB_WORKSPACE/LICENSE.txt" LICENSE.txt | |
| zip -Xry $ARCHIVE kcserver LICENSE.txt | |
| - name: Upload macOS release artifact (universal) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-universal.zip | |
| asset_name: kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}${{ env.DEBUG_FLAG }}-darwin-universal.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload macOS release artifact (arm64/Apple Silicon) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-arm64.zip | |
| asset_name: kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}${{ env.DEBUG_FLAG }}-darwin-arm64.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload macOS release artifact (x64/Intel) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-darwin-x64.zip | |
| asset_name: kallichore-${{ needs.get_version.outputs.KALLICHORE_VERSION }}${{ env.DEBUG_FLAG }}-darwin-x64.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload Windows release artifact (x64) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-windows-x64.zip | |
| asset_name: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-windows-x64.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload Windows release artifact (arm64) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-windows-arm64.zip | |
| asset_name: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-windows-arm64.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload Linux release artifacts (x64) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-linux-x64.zip | |
| asset_name: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-linux-x64.zip | |
| asset_content_type: application/octet-stream | |
| - name: Upload Linux release artifacts (arm64) | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.upload_url }} | |
| asset_path: kallichore-${{ env.RELEASE_TAG }}-${{ matrix.flavor }}-linux-arm64.zip | |
| asset_name: kallichore-${{ env.RELEASE_TAG }}${{ env.DEBUG_FLAG }}-linux-arm64.zip | |
| asset_content_type: application/octet-stream | |
| # Publish new releases to the kallichore-builds public repository | |
| publish_public_release: | |
| name: Publish Public Release | |
| runs-on: ubuntu-latest | |
| needs: [upload_release_binaries, get_version] | |
| permissions: | |
| contents: write # Required for creating a tag and release | |
| env: | |
| RELEASE_TAG: ${{ needs.get_version.outputs.KALLICHORE_VERSION }} | |
| steps: | |
| - name: Download macOS release (universal) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-darwin-universal.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download macOS release (arm64/Apple Silicon) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-darwin-arm64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download macOS release (x64/Intel) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-darwin-x64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Linux release (x64) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-linux-x64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Linux release (arm64) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-linux-arm64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Windows release (x64) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-windows-x64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Windows release (arm64) | |
| uses: dsaltares/fetch-gh-release-asset@1.1.2 | |
| with: | |
| version: tags/${{ env.RELEASE_TAG }} | |
| file: kallichore-${{ env.RELEASE_TAG }}-windows-arm64.zip | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create access token | |
| uses: actions/create-github-app-token@v1 | |
| id: app-token | |
| with: | |
| app-id: ${{ vars.POSITRON_BOT_APP_ID }} | |
| private-key: ${{ secrets.POSITRON_BOT_PRIVATE_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: | | |
| kallichore | |
| kallichore-builds | |
| - name: Create public release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| repository: posit-dev/kallichore-builds | |
| tag_name: ${{ env.RELEASE_TAG }} | |
| prerelease: true | |
| fail_on_unmatched_files: true | |
| generate_release_notes: false | |
| body: | | |
| Kallichore ${{env.RELEASE_TAG }} | |
| files: | | |
| kallichore-${{ env.RELEASE_TAG }}-darwin-universal.zip | |
| kallichore-${{ env.RELEASE_TAG }}-darwin-arm64.zip | |
| kallichore-${{ env.RELEASE_TAG }}-darwin-x64.zip | |
| kallichore-${{ env.RELEASE_TAG }}-windows-x64.zip | |
| kallichore-${{ env.RELEASE_TAG }}-windows-arm64.zip | |
| kallichore-${{ env.RELEASE_TAG }}-linux-x64.zip | |
| kallichore-${{ env.RELEASE_TAG }}-linux-arm64.zip | |
| status: | |
| if: ${{ failure() }} | |
| runs-on: self-hosted | |
| needs: [build_macos, build_windows, sign_windows, repackage_signed_windows, get_version] | |
| steps: | |
| - name: Notify slack if build fails | |
| uses: slackapi/slack-github-action@v1.24.0 | |
| id: slack-failure | |
| with: | |
| payload: | | |
| { | |
| "message": "Kallichore build ${{ needs.get_version.outputs.KALLICHORE_VERSION }} failed", | |
| "status": "Failure", | |
| "run_url": "https://github.com/posit-dev/positron/actions/runs/${{ github.run_id }}" | |
| } | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |