Skip to content

Commit 6ce2ef4

Browse files
Build please_pex releases in native environments
Now that please_pex writes a preamble C binary that is native to each platform supported by Please, please_pex is no longer just a Go binary that can be cross-compiled for every platform on a Linux amd64 runner: the preamble needs to be built natively for each platform and embedded in the please_pex binary for that platform. Reorganise the please_pex test, build and release workflow so that the release binaries are built natively on their respective platforms: [alpine-builder](https://github.com/please-build/alpine-builder) for Linux (linking statically to musl results in a nice ~94KB binary), [freebsd-builder](https://github.com/please-build/freebsd-builder) for FreeBSD, and GitHub Actions' macOS 15 runners for Darwin. Although Ubuntu arm64 GitHub runners are available, the linux_arm64 release has to be built on an Ubuntu amd64 runner because JavaScript-based workflow actions currently can't be executed on an Alpine arm64 container running on an arm64 host - see: - actions/upload-artifact#739 - actions/runner#801
1 parent 4c0d0c0 commit 6ce2ef4

File tree

4 files changed

+106
-7
lines changed

4 files changed

+106
-7
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
platform:
5+
description: "The platform on which this workflow should run. Must be one of darwin_amd64, darwin_arm64, freebsd_amd64, linux_amd64 or linux_arm64."
6+
required: true
7+
type: string
8+
jobs:
9+
build:
10+
name: ${{ inputs.platform }}
11+
runs-on: ${{ (inputs.platform == 'freebsd_amd64' || startsWith(inputs.platform, 'linux_')) && 'ubuntu-24.04' || (inputs.platform == 'darwin_amd64' && 'macos-15-intel' || (inputs.platform == 'darwin_arm64' && 'macos-15' || 'unknown')) }}
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v6
15+
- name: Set up QEMU
16+
if: ${{ startsWith(inputs.platform, 'linux_') }}
17+
uses: docker/setup-qemu-action@v3
18+
- name: Set up Docker
19+
if: ${{ startsWith(inputs.platform, 'linux_') }}
20+
uses: docker/setup-docker-action@v4
21+
with:
22+
daemon-config: |
23+
{
24+
"debug": true,
25+
"features": {
26+
"containerd-snapshotter": true
27+
}
28+
}
29+
- name: Build please_pex binary (on freebsd-builder image)
30+
if: ${{ inputs.platform == 'freebsd_amd64' }}
31+
uses: cross-platform-actions/action@v0.30.0
32+
with:
33+
operating_system: freebsd
34+
architecture: x86-64
35+
version: '14.3'
36+
image_url: https://github.com/please-build/freebsd-builder/releases/download/v0.12.0-please.3/freebsd-14.3-x86-64.qcow2
37+
shell: bash
38+
shutdown_vm: true
39+
run: package/gha_release.sh //package:please_pex_${{ inputs.platform }}
40+
- name: Build please_pex binary (in alpine-builder container)
41+
if: ${{ startsWith(inputs.platform, 'linux_') }}
42+
run: |
43+
docker run --rm \
44+
--platform ${{ inputs.platform == 'linux_amd64' && 'linux/amd64' || 'linux/arm64' }} \
45+
-v "/home/runner/work:/home/runner/work" \
46+
--env "GITHUB_ACTIONS=$GITHUB_ACTIONS" \
47+
--env "GITHUB_ENV=$GITHUB_ENV" \
48+
--workdir "$GITHUB_WORKSPACE" \
49+
ghcr.io/please-build/alpine-builder:v3.22-please.3 \
50+
/bin/bash package/gha_release.sh //package:please_pex_${{ inputs.platform }}
51+
- name: Build please_pex binary (on host)
52+
if: ${{ startsWith(inputs.platform, 'darwin_') }}
53+
run: package/gha_release.sh //package:please_pex_${{ inputs.platform }}
54+
- name: Upload please_pex binary to artifact storage
55+
uses: actions/upload-artifact@v5
56+
with:
57+
name: please_pex_${{ inputs.platform }}
58+
path: ${{ env.ARTIFACT_PATH }}
59+
if-no-files-found: error
60+
compression-level: 9
61+
retention-days: 1

.github/workflows/plugin.yaml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- '3.13'
2929
- '3.14'
3030
test-please_pex:
31-
name: Test (${{ matrix.platform}}, Python ${{ matrix.python }}, in-repo please_pex)
31+
name: Test please_pex
3232
uses: ./.github/workflows/plugin_test.yaml
3333
with:
3434
platform: ${{ matrix.platform }}
@@ -71,23 +71,46 @@ jobs:
7171
- '3.12'
7272
- '3.13'
7373
- '3.14'
74+
build-please_pex-artifacts:
75+
name: Build please_pex release artifacts
76+
if: github.ref == 'refs/heads/master'
77+
needs:
78+
- test-please_pex
79+
uses: ./.github/workflows/please_pex_build.yaml
80+
with:
81+
platform: ${{ matrix.platform }}
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
platform:
86+
- darwin_amd64
87+
- darwin_arm64
88+
- freebsd_amd64
89+
- linux_amd64
90+
- linux_arm64
7491
release-please_pex:
7592
name: Release please_pex
7693
if: github.ref == 'refs/heads/master'
7794
needs:
78-
- test-please_pex
95+
- build-please_pex-artifacts
7996
runs-on: ubuntu-latest
97+
env:
98+
BIN_DIR: /tmp/please_pex_release
8099
steps:
100+
- name: Download please_pex binaries from artifact storage
101+
uses: actions/download-artifact@v6
102+
with:
103+
path: ${{ env.BIN_DIR }}
104+
pattern: please_pex_*
105+
merge-multiple: true
81106
- name: Check out code
82-
uses: actions/checkout@v5
83-
- name: Build release files
84-
run: ./pleasew build //package:please_pex_release_files
107+
uses: actions/checkout@v6
85108
- name: Create release
86109
env:
87110
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88111
uses: thought-machine/release-action@master
89112
with:
90-
release-files: plz-out/package/please_pex
113+
release-files: ${{ env.BIN_DIR }}
91114
version-file: tools/please_pex/VERSION
92115
change-log-file: tools/please_pex/ChangeLog
93116
release-prefix: please_pex

.github/workflows/plugin_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
default: //...
2525
jobs:
2626
test:
27-
name: Run tests
27+
name: ${{ inputs.platform }}, Python ${{ inputs.python }}
2828
runs-on: ${{ (inputs.platform == 'freebsd_amd64' || inputs.platform == 'linux_amd64') && 'ubuntu-24.04' || (inputs.platform == 'linux_arm64' && 'ubuntu-24.04-arm' || (inputs.platform == 'darwin_amd64' && 'macos-15-intel' || (inputs.platform == 'darwin_arm64' && 'macos-15' || 'unknown'))) }}
2929
steps:
3030
- name: Install Python in CI environment

package/gha_release.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# This script builds a tool release (i.e. an architecture-specific binary target
4+
# in //tools) and reports its location to the actions/upload-artifact action so
5+
# it can be uploaded as part of the release workflow.
6+
7+
if [ "$GITHUB_ACTIONS" != true ]; then
8+
echo "This script should only be executed on GitHub Actions runners." >&2
9+
exit 1
10+
fi
11+
12+
target="$1"
13+
14+
./pleasew -v notice -p build "$target"
15+
echo ARTIFACT_PATH="$(./pleasew query output $target)" >> $GITHUB_ENV

0 commit comments

Comments
 (0)