Skip to content

Commit 00c4aa4

Browse files
committed
First generate the binaries correctly
1 parent 49c74fb commit 00c4aa4

File tree

1 file changed

+90
-91
lines changed

1 file changed

+90
-91
lines changed

.github/workflows/test-cli-plugin-manifest.yaml

+90-91
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,8 @@ env:
1111
BINARY_NAME: your_cli_name
1212

1313
jobs:
14-
nix-build:
15-
name: nix build
16-
runs-on: ubuntu-latest
17-
strategy:
18-
matrix:
19-
target:
20-
- x86_64-linux
21-
- aarch64-linux
22-
steps:
23-
- name: Checkout 🛎️
24-
uses: actions/checkout@v4
25-
26-
- name: Install Nix ❄
27-
uses: cachix/install-nix-action@v30
28-
with:
29-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
30-
31-
- name: Set up the Nix Cache 🔌
32-
uses: cachix/cachix-action@v15
33-
with:
34-
name: hasura-v3-dev
35-
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
36-
useDaemon: false # attempt to stop hanging on cleanup
37-
38-
- name: Build a binary with Nix
39-
run: nix build --print-build-logs '.#${{ matrix.target }}'
40-
41-
- name: Build a Docker image with Nix
42-
run: nix build --print-build-logs '.#docker-${{ matrix.target }}'
43-
44-
# scream into Slack if something goes wrong
45-
- name: Report Status
46-
if: always() && github.ref == 'refs/heads/main'
47-
uses: ravsamhq/notify-slack-action@v2
48-
with:
49-
status: ${{ job.status }}
50-
notify_when: failure
51-
notification_title: "😧 Error on <{repo_url}|{repo}>"
52-
message_format: "🐴 *{workflow}* {status_message} for <{repo_url}|{repo}>"
53-
env:
54-
SLACK_WEBHOOK_URL: ${{ secrets.BROKEN_BUILD_SLACK_WEBHOOK_URL }}
55-
56-
build:
57-
name: Build the CLI binaries
14+
build-cli-binaries:
15+
name: build the CLI binaries
5816
strategy:
5917
matrix:
6018
include:
@@ -83,59 +41,100 @@ jobs:
8341
steps:
8442
- uses: actions/checkout@v4
8543

86-
- name: Install Rust
87-
uses: dtolnay/rust-toolchain@stable
44+
- name: install protoc
45+
uses: arduino/setup-protoc@v3
8846
with:
89-
targets: ${{ matrix.target }}
47+
version: "25.x"
48+
repo-token: ${{ secrets.GITHUB_TOKEN }}
9049

91-
- name: Install cross-compilation tools
92-
if: matrix.target == 'aarch64-unknown-linux-gnu'
50+
- name: install tools
9351
run: |
94-
sudo apt-get update
95-
sudo apt-get install -y gcc-aarch64-linux-gnu
52+
rustup show
53+
rustup target add ${{ matrix.target }}
9654
97-
- name: Build binary
98-
run: cargo build --release --target ${{ matrix.target }}
55+
- name: install other packages required
56+
if: matrix.linux-packages
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y ${{ matrix.linux-packages }}
9960
100-
- name: Generate manifest entry
101-
shell: bash
61+
- name: build the CLI
10262
run: |
103-
# Calculate SHA256 of the binary
104-
if [ "${{ runner.os }}" = "Windows" ]; then
105-
SHA256=$(certutil -hashfile target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} SHA256 | grep -v "hash" | awk '{print $1}')
106-
else
107-
SHA256=$(sha256sum target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} | cut -d' ' -f1)
63+
# If we're on a tag, use the tag name as the release version.
64+
if [[ "$GITHUB_REF_TYPE" == 'tag' ]]; then
65+
# Ensure that the version specified in Cargo.toml is the same as the tag (with a 'v' prefix).
66+
CARGO_VERSION="$(cargo metadata --format-version=1 | jq -r '.packages | .[] | select(.name == "ndc-sqlserver") | .version')"
67+
echo "Git tag: ${GIT_REF_NAME}"
68+
echo "Cargo version: ${CARGO_VERSION}"
69+
70+
if [[ "$GITHUB_REF_NAME" != "v${CARGO_VERSION}" ]]; then
71+
echo >&2 "The Git tag is \"${GITHUB_REF_NAME}\", but the version in Cargo.toml is \"${CARGO_VERSION}\"."
72+
echo >&2 'These must be the same, with a "v" prefix for the tag. Aborting.'
73+
exit 1
74+
fi
75+
export RELEASE_VERSION="$GITHUB_REF_NAME"
76+
echo "RELEASE_VERSION = ${RELEASE_VERSION}"
10877
fi
10978
110-
# Create manifest entry
111-
echo "{
112-
\"name\": \"${{ env.BINARY_NAME }}\",
113-
\"target\": \"${{ matrix.target }}\",
114-
\"sha256\": \"${SHA256}\",
115-
\"url\": \"https://github.com/${{ github.repository }}/releases/download/${{ github.event.pull_request.head.sha }}/${{ env.BINARY_NAME }}-${{ matrix.target }}${{ matrix.binary_suffix }}\"
116-
}" > manifest-entry.json
117-
118-
- name: Upload manifest entry
119-
uses: actions/upload-artifact@v4
120-
with:
121-
name: manifest-${{ matrix.target }}
122-
path: manifest-entry.json
123-
retention-days: 1
124-
125-
create-manifest:
126-
needs: build
127-
runs-on: ubuntu-latest
128-
steps:
129-
- name: Download all manifest entries
130-
uses: actions/download-artifact@v4
131-
with:
132-
path: entries
133-
134-
- name: Combine manifest entries
135-
run: |
136-
echo '{"binaries": [' > cli-manifest.json
137-
find entries -name "manifest-entry.json" -exec cat {} \; | sed '$!s/$/,/' >> cli-manifest.json
138-
echo ']}' >> cli-manifest.json
79+
if [[ -n '${{ matrix.linker }}' ]]; then
80+
TARGET_SCREAMING="$(echo '${{ matrix.target }}' | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
81+
echo "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"='${{ matrix.linker }}'
82+
declare "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"='${{ matrix.linker }}'
83+
export "CARGO_TARGET_${TARGET_SCREAMING}_LINKER"
84+
fi
13985
140-
echo "Generated CLI Plugin Manifest:"
141-
cat cli-manifest.json
86+
if [[ -n '${{ matrix.extra-rust-flags }}' ]]; then
87+
RUSTFLAGS="${RUSTFLAGS} ${{ matrix.extra-rust-flags }}"
88+
export RUSTFLAGS
89+
fi
90+
echo "RUSTFLAGS = ${RUSTFLAGS}"
91+
92+
echo "Building for target: ${CARGO_BUILD_TARGET}"
93+
cargo build --release --bin ndc-sqlserver-cli
94+
95+
mkdir -p release
96+
mv -v target/${{ matrix.target }}/release/ndc-sqlserver-cli release/ndc-sqlserver-cli-${{ matrix.target }}${{ matrix.extension }}
97+
echo "Generated binary successfully"
98+
99+
# - name: Generate manifest entry
100+
# shell: bash
101+
# run: |
102+
# # Calculate SHA256 of the binary
103+
# if [ "${{ runner.os }}" = "Windows" ]; then
104+
# SHA256=$(certutil -hashfile target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} SHA256 | grep -v "hash" | awk '{print $1}')
105+
# else
106+
# SHA256=$(sha256sum target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}${{ matrix.binary_suffix }} | cut -d' ' -f1)
107+
# fi
108+
109+
# # Create manifest entry
110+
# echo "{
111+
# \"name\": \"${{ env.BINARY_NAME }}\",
112+
# \"target\": \"${{ matrix.target }}\",
113+
# \"sha256\": \"${SHA256}\",
114+
# \"url\": \"https://github.com/${{ github.repository }}/releases/download/${{ github.event.pull_request.head.sha }}/${{ env.BINARY_NAME }}-${{ matrix.target }}${{ matrix.binary_suffix }}\"
115+
# }" > manifest-entry.json
116+
117+
# - name: Upload manifest entry
118+
# uses: actions/upload-artifact@v4
119+
# with:
120+
# name: manifest-${{ matrix.target }}
121+
# path: manifest-entry.json
122+
# retention-days: 1
123+
124+
# create-manifest:
125+
# needs: build
126+
# runs-on: ubuntu-latest
127+
# steps:
128+
# - name: Download all manifest entries
129+
# uses: actions/download-artifact@v4
130+
# with:
131+
# path: entries
132+
133+
# - name: Combine manifest entries
134+
# run: |
135+
# echo '{"binaries": [' > cli-manifest.json
136+
# find entries -name "manifest-entry.json" -exec cat {} \; | sed '$!s/$/,/' >> cli-manifest.json
137+
# echo ']}' >> cli-manifest.json
138+
139+
# echo "Generated CLI Plugin Manifest:"
140+
# cat cli-manifest.json

0 commit comments

Comments
 (0)