-
-
Notifications
You must be signed in to change notification settings - Fork 759
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
Verify on CI that gleam binary architectures match target architectures #3897
base: main
Are you sure you want to change the base?
Verify on CI that gleam binary architectures match target architectures #3897
Conversation
…atches target architecture
…target architecture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Why is it that there are new workflows for this? There is a very large amount of extra work being performed and CI complexity to maintain here. I would have expected 1 extra step in each workflow to run the check command.
@@ -0,0 +1,75 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regular shell please 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, ok – shall we change it for all the other scripts as well then?
shell: bash
is being used for all the inline scripts of the workflow steps. That's why I went for bash
to not mix and match shells.
bin/verify-binary-architecture.sh
Outdated
;; | ||
*"windows"*) | ||
# Parse binary architecture | ||
pe_header_output=$(powershell -Command " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is file
unavailable on the Windows runners, even though it has a posix shell installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid not. Same is true for which
vs where
. It's been a pain getting this to work for Windows in the least verbose way.
That's the reason why I opted for creating separate workflows. So that I can test an even broader set of target architectures and OSes and make it work:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I added an isolated file output test workflow step on a separate testing branch:
- name: Test file output
shell: bash
run: |
set -xeuo pipefail
BINARY_PATH="target/${{ matrix.target }}/release/gleam"
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
BINARY_PATH="${BINARY_PATH}.exe"
fi
file_output=$(file "${BINARY_PATH}")
And ran it on the various target architectures and OSes:
target/x86_64-unknown-linux-gnu/release/gleam: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=7fa5e3ea50b409f61625cfaa5cf439a30de76936, for GNU/Linux 3.2.0, not stripped
target/aarch64-unknown-linux-gnu/release/gleam: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=75394ba54846e1cd0654df8f49cf615896418733, not stripped
target/x86_64-unknown-linux-musl/release/gleam: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, BuildID[sha1]=1892a4eef798936540c664af5c9f3f96d7253d6f, not stripped
target/aarch64-unknown-linux-musl/release/gleam: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
target/x86_64-apple-darwin/release/gleam: Mach-O 64-bit executable x86_64
target/aarch64-apple-darwin/release/gleam: Mach-O 64-bit executable arm64
target/x86_64-pc-windows-msvc/release/gleam.exe: PE32+ executable (console) x86-64, for MS Windows, 5 sections
target/aarch64-pc-windows-msvc/release/gleam.exe: PE32+ executable (console) Aarch64, for MS Windows, 11 sections
Seems like I was wrong – it works - sorry! Not sure why it hasn't previously. Let me fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups, I figured out why it appeared to not work when I did this initially... 🤦
Anyways: refactored the bash script to use file on Windows too in commit 425e8fb.
bin/verify-binary-architecture.sh
Outdated
file_output=$(file -b "${BINARY_PATH}") | ||
BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86_64\|arm64" || echo "") | ||
# Map expected binary architecture | ||
case "${TARGET_ARCHITECTURE}" in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pass the expected substring in from the workflow rather than having mappings from the target triple to these strings here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expected substring is different for each target architecture and OS.
In my initial version I had it mapped like so:
declare -A ARCHITECTURE_PATTERNS=(
["darwin"]="x86_64\|arm64"
["linux"]="x86-64\|aarch64"
)
declare -A ARCHITECTURE_MAP=(
["darwin:x86_64"]="x86_64"
["darwin:aarch64"]="arm64"
["linux:x86_64"]="x86-64"
["linux:aarch64"]="aarch64"
["windows:x86_64"]="X64"
["windows:aarch64"]="Arm64"
)
Which reduced the logic to just:
BINARY_ARCHITECTURE=$(file "${BINARY_PATH}" | grep -o "${ARCHITECTURE_PATTERNS["linux"]}" || echo "")
EXPECTED_BINARY_ARCHITECTURE="${ARCHITECTURE_MAP["linux:${TARGET_ARCHITECTURE}"]:-}"
Way more clear – it sadly doesn't run on darwin
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope its more clear now in the refactored version of the script?
Let me quote some bits from above:
I just added them for testing purposes – wanted to make sure this works in the exact environment it is supposed to be run: GitHub runners. This way:
I wanted to keep the changes to the existing workflows as minimal as possible. |
…t architecture to use file command on Windows
425e8fb
to
7fb022f
Compare
This PR is regarding issue #1630:
./bin/verify-binary-architecture.sh
./.github/workflows/ci-verify-binary-architecture.yaml
./.github/workflows/release-nightly-verify-binary-architecture.yaml
./.github/workflows/release-verify-binary-architecture.yaml
./.github/workflows/ci.yaml
./.github/workflows/release-nightly.yaml
./.github/workflows/release.yaml
How it works:
target architecture
and thebinary path
as arguments and does it's thingbinary path
and pass them to the bash scriptWhen reviewing:
./.github/workflows/*-verify-binary-architecture.yaml
workflows in the first pass, as they are adding a lot of noise – and focus on the bash script and the changes to the existing workflows instead.Notes and Todos:
file
outputs for the various target architectures and OSes somewhere for future reference?