-
Notifications
You must be signed in to change notification settings - Fork 0
Build and publish a prebuilt release binary on tag push #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - '[0-9]*.[0-9]*.[0-9]*' | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: macos-latest | ||
| outputs: | ||
| asset-url: ${{ steps.package.outputs.asset-url }} | ||
| sha256: ${{ steps.package.outputs.sha256 }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Select Xcode | ||
| uses: maxim-lobanov/setup-xcode@v1 | ||
| with: | ||
| # This project requires Xcode 26+ (see README Requirements). Pin an exact | ||
| # version here if `latest-stable` ever resolves below that floor. | ||
| xcode-version: latest-stable | ||
|
|
||
| - name: Build universal release binary | ||
| id: build | ||
| run: | | ||
| set -euo pipefail | ||
| flags=(--configuration release --arch arm64 --arch x86_64) | ||
| swift build "${flags[@]}" --disable-sandbox | ||
| # Ask SwiftPM for the product directory instead of hardcoding | ||
| # .build/apple/Products/Release, which is an implementation detail that has | ||
| # moved across toolchain versions before. | ||
| echo "products=$(swift build "${flags[@]}" --show-bin-path)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Package | ||
| id: package | ||
| run: | | ||
| set -euo pipefail | ||
| version="${{ github.ref_name }}" | ||
| name="sourcekit-xcode-bsp-${version}-macos.tar.gz" | ||
| products="${{ steps.build.outputs.products }}" | ||
| staging="$RUNNER_TEMP/stage" | ||
|
|
||
| mkdir -p "$staging" | ||
| cp "$products/sourcekit-xcode-bsp" "$products/SWBBuildServiceBundle" "$staging/" | ||
| # swift-build ships one resource bundle per supported platform; glob rather than | ||
| # hardcode names so a swift-build revision bump can't silently drop one. | ||
| cp -R "$products"/*.bundle "$staging/" | ||
| tar -czf "$name" -C "$staging" . | ||
|
|
||
| # Extract to a directory other than $staging to prove the tarball is relocatable, | ||
| # not just runnable in place. | ||
| verify="$RUNNER_TEMP/verify" | ||
| mkdir -p "$verify" | ||
| tar -xzf "$name" -C "$verify" | ||
|
|
||
| # --help returns before Serve.run(), so it never exercises the co-located | ||
| # SWBBuildServiceBundle lookup and wouldn't catch a single-arch artifact. | ||
| # Check architectures directly instead. | ||
| for bin in sourcekit-xcode-bsp SWBBuildServiceBundle; do | ||
| archs="$(lipo -info "$verify/$bin" | awk -F': ' '{print $NF}')" | ||
| for arch in arm64 x86_64; do | ||
| if [[ "$archs" != *"$arch"* ]]; then | ||
| echo "::error::$bin is missing $arch (found: $archs)" | ||
| exit 1 | ||
| fi | ||
| done | ||
| done | ||
| "$verify/sourcekit-xcode-bsp" --help >/dev/null | ||
|
|
||
| sha=$(shasum -a 256 "$name" | awk '{print $1}') | ||
| echo "sha256=$sha" >> "$GITHUB_OUTPUT" | ||
| echo "asset-url=https://github.com/${{ github.repository }}/releases/download/${version}/${name}" >> "$GITHUB_OUTPUT" | ||
| echo "ASSET_PATH=$name" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Publish release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -euo pipefail | ||
| tag="${{ github.ref_name }}" | ||
| # Tolerate a rerun after update-tap failed on a prior attempt: the release | ||
| # already exists, so upload to it instead of erroring out of gh release create. | ||
| if gh release view "$tag" --repo "${{ github.repository }}" >/dev/null 2>&1; then | ||
| gh release upload "$tag" "$ASSET_PATH" --clobber | ||
| else | ||
| gh release create "$tag" "$ASSET_PATH" --title "$tag" --generate-notes | ||
| fi | ||
|
|
||
| update-tap: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout tap | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: slime-studio/homebrew-tap | ||
| token: ${{ secrets.TAP_GITHUB_TOKEN }} | ||
|
|
||
| - name: Update formula | ||
| run: | | ||
| set -euo pipefail | ||
| version="${{ github.ref_name }}" | ||
| asset_url="${{ needs.build.outputs.asset-url }}" | ||
| sha="${{ needs.build.outputs.sha256 }}" | ||
| # `0,/pattern/s` limits the substitution to the first match, so the `head do` | ||
| # block's source url/sha256 (if the formula has one) is left untouched. | ||
| sed -i "0,/^ url \".*\"\$/s|^ url \".*\"\$| url \"${asset_url}\"|" Formula/sourcekit-xcode-bsp.rb | ||
| sed -i "0,/^ sha256 \".*\"\$/s|^ sha256 \".*\"\$| sha256 \"${sha}\"|" Formula/sourcekit-xcode-bsp.rb | ||
|
|
||
| - name: Open PR | ||
| env: | ||
| GH_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} | ||
| run: | | ||
| version="${{ github.ref_name }}" | ||
| branch="update/sourcekit-xcode-bsp-${version}" | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git config --global credential.helper "" | ||
| git checkout -b "$branch" | ||
| git add Formula/sourcekit-xcode-bsp.rb | ||
| git commit -m "Update sourcekit-xcode-bsp to ${version}" | ||
| git push "https://x-access-token:${GH_TOKEN}@github.com/slime-studio/homebrew-tap.git" "$branch" | ||
| gh pr create \ | ||
| --repo slime-studio/homebrew-tap \ | ||
| --title "Update sourcekit-xcode-bsp to ${version}" \ | ||
| --body "Automated formula update for version \`${version}\`. | ||
|
|
||
| - Prebuilt asset: \`${{ needs.build.outputs.asset-url }}\` | ||
| - SHA-256: \`${{ needs.build.outputs.sha256 }}\`" \ | ||
| --base main \ | ||
| --head "$branch" | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.