feat: CLI Device auth flow #13
Workflow file for this run
This file contains 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 CLI Binary" | |
on: | |
push: | |
branches: [main] | |
paths: | |
- "packages/gensx-cli/**/*" | |
pull_request: | |
branches: [main] | |
paths: | |
- "packages/gensx-cli/**/*" | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ env.VERSION }} | |
strategy: | |
fail-fast: false | |
matrix: | |
target: | |
- node22-linux-arm64 | |
- node22-linux-x64 | |
- node22-macos-arm64 | |
- node22-macos-x64 | |
- node22-win-arm64 | |
- node22-win-x64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: "Sanitize Branch Name" | |
id: sanitize-branch-name | |
uses: transferwise/sanitize-branch-name@v1 | |
- name: Setup Node ⚙️ | |
uses: ./.github/actions/setup-node | |
with: | |
version: 20.x | |
- name: Extract Version from Package.json for main | |
if: github.ref == 'refs/heads/main' | |
run: | | |
VERSION=$(jq -r '.version' packages/gensx-cli/package.json) | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Extract Version from Package.json for CI | |
if: github.ref != 'refs/heads/main' | |
run: | | |
VERSION=$(jq -r '.version' packages/gensx-cli/package.json) | |
echo "VERSION=${{ steps.sanitize-branch-name.outputs.sanitized-branch-name }}-${{ github.sha }}" >> $GITHUB_ENV | |
- name: Build CLI | |
run: pnpm build | |
working-directory: packages/gensx-cli | |
- name: Building... | |
run: TARGET=${{ matrix.target }} pnpm run package | |
working-directory: packages/gensx-cli | |
- name: Prepare content... | |
run: | | |
mv README.md dist/pkg | |
working-directory: packages/gensx-cli | |
- name: Setup environment (Unix) | |
if: contains(fromJSON('["node22-linux-arm64", "node22-linux-x64", "node22-macos-arm64", "node22-macos-x64"]'), matrix.target) | |
run: | | |
echo "_EXT=tar.gz" >> $GITHUB_ENV | |
- name: Setup environment (Windows) | |
if: contains(fromJSON('["node22-win-arm64", "node22-win-x64"]'), matrix.target) | |
run: | | |
echo "_EXT=zip" >> $GITHUB_ENV | |
- name: Change permissions (Unix) | |
if: contains(fromJSON('["node22-linux-arm64", "node22-linux-x64", "node22-macos-arm64", "node22-macos-x64"]'), matrix.target) | |
run: | | |
chmod -R 777 ./dist/pkg | |
working-directory: packages/gensx-cli | |
- name: Tar dist (Unix) | |
if: contains(fromJSON('["node22-linux-arm64", "node22-linux-x64", "node22-macos-arm64", "node22-macos-x64"]'), matrix.target) | |
run: | | |
tar czf ${{ matrix.target }}.${{ env._EXT }} -C ./dist/pkg . | |
cp ${{ matrix.target }}.${{ env._EXT }} gensx_${{ env.VERSION }}_${{ matrix.target }}.${{ env._EXT }} | |
working-directory: packages/gensx-cli | |
- name: Zipping dist (Windows) | |
if: contains(fromJSON('["win-arm64", "win-x64"]'), matrix.target) | |
working-directory: packages/gensx-cli/dist/pkg | |
run: | | |
zip -r ${{ matrix.target }}.${{ env._EXT }} . | |
mv ${{ matrix.target }}.${{ env._EXT }} ../../ | |
cd ../.. | |
cp ${{ matrix.target }}.${{ env._EXT }} gensx_${{ env.VERSION }}_${{ matrix.target }}.${{ env._EXT }} | |
- name: Uploading Artifact | |
if: github.ref != 'refs/heads/main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: gensx_${{ env.VERSION }}_${{ matrix.target }}.${{ env._EXT }} | |
path: packages/gensx-cli/gensx_${{ env.VERSION }}_${{ matrix.target }}.${{ env._EXT }} | |
- name: Uploading Release | |
# if: github.ref == 'refs/heads/main' | |
uses: softprops/action-gh-release@v2.0.8 | |
with: | |
tag_name: gensx-cli-binary-v${{ env.VERSION }} | |
token: ${{ secrets.PAT_GITHUB_TOKEN }} | |
prerelease: true | |
files: packages/gensx-cli/gensx_${{ env.VERSION }}_${{ matrix.target }}.${{ env._EXT }} | |
update-homebrew: | |
needs: build | |
# if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download macOS ARM64 Release | |
uses: dsaltares/fetch-gh-release-asset@1.1.1 | |
with: | |
version: tags/gensx-cli-binary-v${{ needs.build.outputs.version }} | |
file: gensx_${{ needs.build.outputs.version }}_node22-macos-arm64.tar.gz | |
token: ${{ secrets.PAT_GITHUB_TOKEN }} | |
- name: Download macOS x64 Release | |
uses: dsaltares/fetch-gh-release-asset@1.1.1 | |
with: | |
version: tags/gensx-cli-binary-v${{ needs.build.outputs.version }} | |
file: gensx_${{ needs.build.outputs.version }}_node22-macos-x64.tar.gz | |
token: ${{ secrets.PAT_GITHUB_TOKEN }} | |
- name: Calculate SHA256 Checksums | |
run: | | |
echo "ARM64_SHA256=$(sha256sum gensx_${{ needs.build.outputs.version }}_node22-macos-arm64.tar.gz | cut -d ' ' -f 1)" >> $GITHUB_ENV | |
echo "X64_SHA256=$(sha256sum gensx_${{ needs.build.outputs.version }}_node22-macos-x64.tar.gz | cut -d ' ' -f 1)" >> $GITHUB_ENV | |
- name: Checkout homebrew-gensx repo | |
uses: actions/checkout@v4 | |
with: | |
repository: gensx-inc/homebrew-gensx | |
token: ${{ secrets.PAT_GITHUB_TOKEN }} | |
path: homebrew-gensx | |
- name: Update Formula | |
run: | | |
cat > homebrew-gensx/Formula/gensx.rb << EOL | |
class Gensx < Formula | |
desc "GenSX CLI - The command-line interface for GenSX" | |
homepage "https://gensx.com" | |
version "${{ needs.build.outputs.version }}" | |
license "MIT" | |
on_macos do | |
on_arm do | |
url "https://github.com/gensx-inc/gensx/releases/download/gensx-cli-binary-v${{ needs.build.outputs.version }}/gensx_${{ needs.build.outputs.version }}_node22-macos-arm64.tar.gz" | |
sha256 "${{ env.ARM64_SHA256 }}" | |
end | |
on_intel do | |
url "https://github.com/gensx-inc/gensx/releases/download/gensx-cli-binary-v${{ needs.build.outputs.version }}/gensx_${{ needs.build.outputs.version }}_node22-macos-x64.tar.gz" | |
sha256 "${{ env.X64_SHA256 }}" | |
end | |
end | |
def install | |
# Extract the tar.gz file | |
system "tar", "xf", cached_download | |
# Install the 'run' file as 'gensx' in the bin directory | |
bin.install "run" => "gensx" | |
# Make the file executable | |
chmod 0755, bin/"gensx" | |
end | |
end | |
EOL | |
- name: Commit and Push Changes | |
run: | | |
cd homebrew-gensx | |
git config user.name "GitHub Actions Bot" | |
git config user.email "actions@github.com" | |
git add Formula/gensx.rb | |
git commit -m "Update formula to version ${{ needs.build.outputs.version }}" | |
git push |