Skip to content

Commit be91d9c

Browse files
authored
CI: Extract and don't hardcode artifact naming (#3463)
1 parent c0b75d7 commit be91d9c

File tree

3 files changed

+117
-29
lines changed

3 files changed

+117
-29
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Compute artifact names
2+
description: Central place for computing the artifact names in the CI builds.
3+
4+
inputs:
5+
build-name:
6+
description: The build name (e.g., linux-x86_64, macos-aarch64, etc.)
7+
required: true
8+
9+
runs:
10+
using: composite
11+
12+
steps:
13+
- name: Check valid build name
14+
if: >
15+
! contains(
16+
fromJson('[
17+
"linux-x86_64",
18+
"linux-x86_64-static",
19+
"macos-x86_64",
20+
"macos-aarch64",
21+
"macos-universal"
22+
]'),
23+
inputs.build-name
24+
)
25+
shell: sh
26+
run: |
27+
echo '::error::Invalid build name provided: ${{ inputs.build-name }}.'
28+
exit 1
29+
30+
- name: Set artifact names
31+
id: set-artifact-names
32+
shell: sh
33+
run: |
34+
echo "artifact-name=wasp-cli-${{ inputs.build-name }}" >> $GITHUB_OUTPUT
35+
echo "tarball-name=wasp-${{ inputs.build-name }}.tar.gz" >> $GITHUB_OUTPUT
36+
37+
outputs:
38+
artifact-name:
39+
value: ${{ steps.set-artifact-names.outputs.artifact-name }}
40+
description: "The name of the artifact attached to the CI build."
41+
tarball-name:
42+
value: ${{ steps.set-artifact-names.outputs.tarball-name }}
43+
description: "The name of the tarball inside the artifact."

.github/actions/fetch-nightly-cli/action.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ runs:
1919
using: composite
2020

2121
steps:
22+
- name: Compute artifact names
23+
uses: ./.github/actions/compute-artifact-names
24+
id: compute-artifact-names
25+
with:
26+
build-name: ${{ runner.os == 'Linux' && 'linux' || 'macos' }}-${{ runner.arch == 'ARM64' && 'aarch64' || 'x86_64' }}
27+
2228
- name: Get latest successful run ID
2329
id: get_run_id
2430
shell: bash
@@ -61,7 +67,9 @@ runs:
6167
GH_TOKEN: ${{ inputs.token }}
6268
RUN_ID: ${{ steps.get_run_id.outputs.run_id }}
6369
OUTPUT_DIR: ${{ inputs.output-dir }}
64-
ARTIFACT_NAME:
65-
# This is the name of the artifact (not the file), which must be in sync with:
66-
# /.github/workflows/ci-waspc-build.yaml
67-
"wasp-cli-${{ runner.os == 'Linux' && 'linux' || 'macos' }}-${{ runner.arch == 'ARM64' && 'aarch64' || 'x86_64' }}"
70+
ARTIFACT_NAME: ${{ steps.compute-artifact-names.outputs.artifact-name }}
71+
72+
outputs:
73+
artifact-path:
74+
description: "The path to the downloaded artifact directory."
75+
value: ${{ inputs.output-dir }}/${{ steps.compute-artifact-names.outputs.artifact-name }}

.github/workflows/ci-waspc-build.yaml

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ env:
2222

2323
jobs:
2424
build:
25+
outputs:
26+
output_linux-x86_64: ${{ steps.set-outputs.outputs.output_linux-x86_64 }}
27+
output_linux-x86_64-static: ${{ steps.set-outputs.outputs.output_linux-x86_64-static }}
28+
output_macos-x86_64: ${{ steps.set-outputs.outputs.output_macos-x86_64 }}
29+
output_macos-aarch64: ${{ steps.set-outputs.outputs.output_macos-aarch64 }}
30+
2531
strategy:
2632
fail-fast: false
2733

@@ -92,6 +98,12 @@ jobs:
9298
steps:
9399
- uses: actions/checkout@v6
94100

101+
- name: Compute artifact names
102+
uses: ./.github/actions/compute-artifact-names
103+
id: compute-artifact-names
104+
with:
105+
build-name: ${{ matrix.env.name }}
106+
95107
- name: Install dependencies
96108
if: ${{ matrix.env.install-deps }}
97109
run: ${{ matrix.env.install-deps }}
@@ -112,52 +124,77 @@ jobs:
112124
run: |
113125
./run build:all${{ matrix.env.static && ':static' || '' }}
114126
mkdir -p artifacts
115-
./tools/make_binary_package.sh "artifacts/wasp-${{ matrix.env.name }}.tar.gz"
127+
./tools/make_binary_package.sh "artifacts/${{ steps.compute-artifact-names.outputs.tarball-name }}"
116128
117129
- uses: actions/upload-artifact@v4
118130
with:
119-
path: ./waspc/artifacts/*
120-
name:
121-
"wasp-cli-${{ matrix.env.name }}"
122-
# This name must be in sync with the artifact name used in:
123-
# /.github/actions/fetch-nightly-cli/action.yaml
131+
path: ./waspc/artifacts/${{ steps.compute-artifact-names.outputs.tarball-name }}
132+
name: ${{ steps.compute-artifact-names.outputs.artifact-name }}
124133
if-no-files-found: error
125134

135+
- name: Set job outputs
136+
id: set-outputs
137+
env:
138+
OUTPUT_DATA: ${{ toJson(steps.compute-artifact-names.outputs) }}
139+
run: |
140+
{
141+
echo 'output_${{ matrix.env.name }}<<EOF'
142+
echo "$OUTPUT_DATA"
143+
echo 'EOF'
144+
} >> $GITHUB_OUTPUT
145+
126146
build-universal:
127147
name: Build Wasp (universal)
128148
needs: build
129149
runs-on: macos-15
150+
151+
env:
152+
X86_64_TARBALL_NAME: ${{ fromJson(needs.build.outputs.output_macos-x86_64).tarball-name }}
153+
X86_64_ARTIFACT_NAME: ${{ fromJson(needs.build.outputs.output_macos-x86_64).artifact-name }}
154+
AARCH64_TARBALL_NAME: ${{ fromJson(needs.build.outputs.output_macos-aarch64).tarball-name }}
155+
AARCH64_ARTIFACT_NAME: ${{ fromJson(needs.build.outputs.output_macos-aarch64).artifact-name }}
156+
130157
steps:
131-
- name: Download macOS binaries
158+
- uses: actions/checkout@v6
159+
160+
- name: Compute artifact names
161+
uses: ./.github/actions/compute-artifact-names
162+
id: compute-artifact-names
163+
with:
164+
build-name: macos-universal
165+
166+
- name: Download macOS Intel binaries
132167
uses: actions/download-artifact@v5
133168
with:
134-
pattern: wasp-cli-macos-*
169+
name: "${{ env.X86_64_ARTIFACT_NAME }}"
170+
171+
- name: Download macOS ARM binaries
172+
uses: actions/download-artifact@v5
173+
with:
174+
name: "${{ env.AARCH64_ARTIFACT_NAME }}"
135175

136176
- name: Unpack, create universal binary and pack
137177
run: |
138-
set -ex # Fail on error and print each command
178+
set -eux # Fail on error and print each command
139179
140-
input_arch=(
141-
macos-x86_64
142-
macos-aarch64
143-
)
180+
mkdir x86_64 aarch64 universal
144181
145-
# Extract each architecture
146-
for arch in "${input_arch[@]}"; do
147-
mkdir "arch-$arch"
148-
tar -xzf "wasp-cli-${arch}/wasp-${arch}.tar.gz" -C "arch-$arch"
149-
done
182+
# Unpack both architectures
183+
tar -xzf "$X86_64_TARBALL_NAME" -C x86_64
184+
tar -xzf "$AARCH64_TARBALL_NAME" -C aarch64
150185
151-
mkdir universal
152186
# Create the universal binary
153-
lipo -create arch-*/wasp-bin -output universal/wasp-bin
154-
# Copy the data folder too
155-
cp -R "arch-${input_arch[0]}/data" universal/
187+
lipo \
188+
-create "x86_64/wasp-bin" "aarch64/wasp-bin" \
189+
-output "universal/wasp-bin"
190+
191+
# Copy the data folder too (we take the first one, should be identical in both)
192+
cp -R "x86_64/data/" "universal/"
156193
157194
# Pack back up
158-
tar -czf wasp-macos-universal.tar.gz -C universal .
195+
tar -czf ${{ steps.compute-artifact-names.outputs.tarball-name }} -C universal .
159196
160197
- uses: actions/upload-artifact@v4
161198
with:
162-
name: wasp-cli-macos-universal
163-
path: ./wasp-macos-universal.tar.gz
199+
name: ${{ steps.compute-artifact-names.outputs.artifact-name }}
200+
path: ./${{ steps.compute-artifact-names.outputs.tarball-name }}

0 commit comments

Comments
 (0)