Skip to content

Commit 1d2cd19

Browse files
authored
Merge pull request #360 from jprendes/cross-for-release
Use `cross-rs` for release builds
2 parents 416c12f + 19b96d2 commit 1d2cd19

File tree

5 files changed

+59
-239
lines changed

5 files changed

+59
-239
lines changed

.github/workflows/release.yml

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
outputs:
2020
crate: ${{ steps.parse-ref.outputs.crate }}
2121
version: ${{ steps.parse-ref.outputs.version }}
22+
runtime: ${{ steps.parse-ref.outputs.runtime }}
2223
steps:
2324
- uses: actions/checkout@v3
2425
with:
@@ -41,8 +42,11 @@ jobs:
4142
exit 1
4243
fi
4344
45+
RUNTIME="$(cut -d- -f3 <<<"${CRATE}")"
46+
4447
echo "CRATE=${CRATE}" >> $GITHUB_OUTPUT
4548
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
49+
echo "RUNTIME=${RUNTIME}" >> $GITHUB_OUTPUT
4650
4751
setVersion="$(./scripts/version.sh "${CRATE}")"
4852
if [ ! "${VERSION#v}" = "${setVersion}" ]; then
@@ -55,26 +59,46 @@ jobs:
5559
- generate
5660
strategy:
5761
matrix:
58-
os: ["ubuntu-20.04", "ubuntu-22.04"]
59-
runs-on: ${{ matrix.os }}
62+
arch: ["x86_64", "aarch64"]
63+
runs-on: "ubuntu-22.04"
6064
steps:
61-
- uses: Swatinem/rust-cache@v2
62-
with:
63-
key: release-${{ needs.generate.outputs.crate }}
6465
- uses: actions/checkout@v3
6566
- name: Setup build env
6667
run: ./scripts/setup-linux.sh
67-
shell: bash
68-
- name: Install rust
69-
uses: actions-rust-lang/setup-rust-toolchain@v1
68+
- uses: actions-rust-lang/setup-rust-toolchain@v1
69+
env:
70+
RUST_CACHE_KEY_OS: rust-release-cache-${{ needs.generate.outputs.crate }}-${{ matrix.arch }}
7071
with:
71-
cache: false
72+
rustflags: '' #Disable. By default this action sets environment variable is set to -D warnings. We manage this in the Makefile
73+
- name: Setup cross-rs
74+
run: ./scripts/setup-cross.sh ${{ matrix.arch }}-unknown-linux-musl
75+
- name: Setup build profile
76+
shell: bash
77+
run: echo "OPT_PROFILE=release" >> ${GITHUB_ENV}
7278
- name: Build
73-
timeout-minutes: 5
74-
run: make build-$(cut -d- -f3 <<<"${{ needs.generate.outputs.crate }}")
79+
timeout-minutes: 10
80+
run: make build-${{ needs.generate.outputs.runtime }}
7581
- name: Test
76-
timeout-minutes: 5
77-
run: make test-$(cut -d- -f3 <<<"${{ needs.generate.outputs.crate }}")
82+
if: ${{ matrix.arch == 'x86_64' }}
83+
timeout-minutes: 10
84+
run: make test-${{ needs.generate.outputs.runtime }}
85+
- name: Package artifacts
86+
if: ${{ needs.generate.outputs.runtime != 'wasm' }}
87+
shell: bash
88+
run: |
89+
make dist-${{ needs.generate.outputs.runtime }}
90+
# Check if there's any files to archive as tar fails otherwise
91+
if stat dist/bin/* >/dev/null 2>&1; then
92+
tar -czf dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz -C dist/bin .
93+
else
94+
tar -czf dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz -T /dev/null
95+
fi
96+
- name: Upload artifacts
97+
if: ${{ needs.generate.outputs.runtime != 'wasm' }}
98+
uses: actions/upload-artifact@master
99+
with:
100+
name: containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}
101+
path: dist/containerd-shim-${{ needs.generate.outputs.runtime }}-${{ matrix.arch }}.tar.gz
78102

79103
release:
80104
permissions:
@@ -85,29 +109,23 @@ jobs:
85109
runs-on: ubuntu-latest
86110
steps:
87111
- uses: actions/checkout@v3
88-
- name: Setup buildx
89-
run: docker buildx create --use
90-
- name: build binaries
91-
run: docker buildx bake --set *.cache-from=type=gha,scope=buildkit-release-${CRATE} --set *.cache-to=type=gha,scope=buildkit-release-${CRATE} tar-cross
92-
env:
93-
CRATE: ${{ needs.generate.outputs.crate }}
94-
- name: upload binary as GitHub artifact
95-
uses: actions/upload-artifact@v3
112+
- name: Download artifacts
113+
if: ${{ needs.generate.outputs.runtime != 'wasm' }}
114+
uses: actions/download-artifact@master
96115
with:
97-
path: release/
98-
name: ${{ needs.generate.outputs.crate }}-${{ needs.generate.outputs.version }}
116+
path: release
99117
- name: Create release
100118
run: |
101119
gh release create ${{ github.ref }} --generate-notes --prerelease
102-
# skip upload if there are no files
103-
if stat release/* >/dev/null 2>&1; then
104-
for i in release/*; do
105-
gh release upload ${RELEASE_NAME} $i
106-
done
107-
else
108-
echo "No files to upload"
109-
exit 0
110-
fi
120+
env:
121+
GH_TOKEN: ${{ github.token }}
122+
RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }}
123+
- name: Upload release artifacts
124+
if: ${{ needs.generate.outputs.runtime != 'wasm' }}
125+
run: |
126+
for i in release/*/*; do
127+
gh release upload ${RELEASE_NAME} $i
128+
done
111129
env:
112130
GH_TOKEN: ${{ github.token }}
113131
RELEASE_NAME: ${{ needs.generate.outputs.crate }}/${{ needs.generate.outputs.version }}

Dockerfile

Lines changed: 0 additions & 74 deletions
This file was deleted.

docker-bake.hcl

Lines changed: 0 additions & 69 deletions
This file was deleted.

scripts/dockerfile-utils.sh

Lines changed: 0 additions & 60 deletions
This file was deleted.

scripts/setup-cross.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22
cargo install cross --git https://github.com/cross-rs/cross
3-
echo "CARGO=cross" >> ${GITHUB_ENV}
43

5-
if [ ! -z "$1" ]; then
6-
echo "TARGET=$1" >> ${GITHUB_ENV}
7-
fi
4+
if [ ! -z "$CI" ]; then
5+
6+
echo "CARGO=cross" >> ${GITHUB_ENV}
7+
8+
if [ ! -z "$1" ]; then
9+
echo "TARGET=$1" >> ${GITHUB_ENV}
10+
fi
11+
12+
fi

0 commit comments

Comments
 (0)