Skip to content

Commit

Permalink
First generate the binaries correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik committed Jan 22, 2025
1 parent 49c74fb commit 00c4aa4
Showing 1 changed file with 90 additions and 91 deletions.
181 changes: 90 additions & 91 deletions .github/workflows/test-cli-plugin-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,8 @@ env:
BINARY_NAME: your_cli_name

jobs:
nix-build:
name: nix build
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-linux
- aarch64-linux
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Install Nix ❄
uses: cachix/install-nix-action@v30
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up the Nix Cache 🔌
uses: cachix/cachix-action@v15
with:
name: hasura-v3-dev
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
useDaemon: false # attempt to stop hanging on cleanup

- name: Build a binary with Nix
run: nix build --print-build-logs '.#${{ matrix.target }}'

- name: Build a Docker image with Nix
run: nix build --print-build-logs '.#docker-${{ matrix.target }}'

# scream into Slack if something goes wrong
- name: Report Status
if: always() && github.ref == 'refs/heads/main'
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
notify_when: failure
notification_title: "😧 Error on <{repo_url}|{repo}>"
message_format: "🐴 *{workflow}* {status_message} for <{repo_url}|{repo}>"
env:
SLACK_WEBHOOK_URL: ${{ secrets.BROKEN_BUILD_SLACK_WEBHOOK_URL }}

build:
name: Build the CLI binaries
build-cli-binaries:
name: build the CLI binaries
strategy:
matrix:
include:
Expand Down Expand Up @@ -83,59 +41,100 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: install protoc
uses: arduino/setup-protoc@v3
with:
targets: ${{ matrix.target }}
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
- name: install tools
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
rustup show
rustup target add ${{ matrix.target }}
- name: Build binary
run: cargo build --release --target ${{ matrix.target }}
- name: install other packages required
if: matrix.linux-packages
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.linux-packages }}
- name: Generate manifest entry
shell: bash
- name: build the CLI
run: |
# Calculate SHA256 of the binary
if [ "${{ runner.os }}" = "Windows" ]; then
SHA256=$(certutil -hashfile target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} SHA256 | grep -v "hash" | awk '{print $1}')
else
SHA256=$(sha256sum target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} | cut -d' ' -f1)
# If we're on a tag, use the tag name as the release version.
if [[ "$GITHUB_REF_TYPE" == 'tag' ]]; then
# Ensure that the version specified in Cargo.toml is the same as the tag (with a 'v' prefix).
CARGO_VERSION="$(cargo metadata --format-version=1 | jq -r '.packages | .[] | select(.name == "ndc-sqlserver") | .version')"
echo "Git tag: ${GIT_REF_NAME}"
echo "Cargo version: ${CARGO_VERSION}"
if [[ "$GITHUB_REF_NAME" != "v${CARGO_VERSION}" ]]; then
echo >&2 "The Git tag is \"${GITHUB_REF_NAME}\", but the version in Cargo.toml is \"${CARGO_VERSION}\"."
echo >&2 'These must be the same, with a "v" prefix for the tag. Aborting.'
exit 1
fi
export RELEASE_VERSION="$GITHUB_REF_NAME"
echo "RELEASE_VERSION = ${RELEASE_VERSION}"
fi
# Create manifest entry
echo "{
\"name\": \"${{ env.BINARY_NAME }}\",
\"target\": \"${{ matrix.target }}\",
\"sha256\": \"${SHA256}\",
\"url\": \"https://github.com/${{ github.repository }}/releases/download/${{ github.event.pull_request.head.sha }}/${{ env.BINARY_NAME }}-${{ matrix.target }}${{ matrix.binary_suffix }}\"
}" > manifest-entry.json
- name: Upload manifest entry
uses: actions/upload-artifact@v4
with:
name: manifest-${{ matrix.target }}
path: manifest-entry.json
retention-days: 1

create-manifest:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all manifest entries
uses: actions/download-artifact@v4
with:
path: entries

- name: Combine manifest entries
run: |
echo '{"binaries": [' > cli-manifest.json
find entries -name "manifest-entry.json" -exec cat {} \; | sed '$!s/$/,/' >> cli-manifest.json
echo ']}' >> cli-manifest.json
if [[ -n '${{ matrix.linker }}' ]]; then
TARGET_SCREAMING="$(echo '${{ matrix.target }}' | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
echo "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"='${{ matrix.linker }}'
declare "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"='${{ matrix.linker }}'
export "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"
fi
echo "Generated CLI Plugin Manifest:"
cat cli-manifest.json
if [[ -n '${{ matrix.extra-rust-flags }}' ]]; then
RUSTFLAGS="${RUSTFLAGS} ${{ matrix.extra-rust-flags }}"
export RUSTFLAGS
fi
echo "RUSTFLAGS = ${RUSTFLAGS}"
echo "Building for target: ${CARGO_BUILD_TARGET}"
cargo build --release --bin ndc-sqlserver-cli
mkdir -p release
mv -v target/${{ matrix.target }}/release/ndc-sqlserver-cli release/ndc-sqlserver-cli-${{ matrix.target }}${{ matrix.extension }}
echo "Generated binary successfully"
# - name: Generate manifest entry
# shell: bash
# run: |
# # Calculate SHA256 of the binary
# if [ "${{ runner.os }}" = "Windows" ]; then
# SHA256=$(certutil -hashfile target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} SHA256 | grep -v "hash" | awk '{print $1}')
# else
# SHA256=$(sha256sum target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} | cut -d' ' -f1)
# fi

# # Create manifest entry
# echo "{
# \"name\": \"${{ env.BINARY_NAME }}\",
# \"target\": \"${{ matrix.target }}\",
# \"sha256\": \"${SHA256}\",
# \"url\": \"https://github.com/${{ github.repository }}/releases/download/${{ github.event.pull_request.head.sha }}/${{ env.BINARY_NAME }}-${{ matrix.target }}${{ matrix.binary_suffix }}\"
# }" > manifest-entry.json

# - name: Upload manifest entry
# uses: actions/upload-artifact@v4
# with:
# name: manifest-${{ matrix.target }}
# path: manifest-entry.json
# retention-days: 1

# create-manifest:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - name: Download all manifest entries
# uses: actions/download-artifact@v4
# with:
# path: entries

# - name: Combine manifest entries
# run: |
# echo '{"binaries": [' > cli-manifest.json
# find entries -name "manifest-entry.json" -exec cat {} \; | sed '$!s/$/,/' >> cli-manifest.json
# echo ']}' >> cli-manifest.json

# echo "Generated CLI Plugin Manifest:"
# cat cli-manifest.json

0 comments on commit 00c4aa4

Please sign in to comment.