From f41669d94eec74d2dd2fd54d885ab9554fb60e32 Mon Sep 17 00:00:00 2001 From: Atanas Dinov Date: Fri, 10 Nov 2023 10:59:06 +0200 Subject: [PATCH] Adjust CI workflows to use the Rust codebase (#7) * Use Cargo in Build & Test CI jobs Signed-off-by: Atanas Dinov * Use Cargo in Release CI job Signed-off-by: Atanas Dinov * Enforce stricter lint rules Signed-off-by: Atanas Dinov * Update Cargo.toml Signed-off-by: Atanas Dinov * Ignore tags in Build & Test CI workflow Signed-off-by: Atanas Dinov * Replace standard compilation with a container build While built-in cargo compilation is much faster (especially when targetting aarch64), using the latest Ubuntu version causes incompatible (in the short term) and unreliable (in the long term) builds causing issues for the targeted SUSE distros - Leap / SLE Micro. Signed-off-by: Atanas Dinov --------- Signed-off-by: Atanas Dinov --- .github/workflows/build_and_test.yml | 29 ++++++++++++---- .github/workflows/release.yml | 33 +++++++++++-------- Cargo.toml | 2 ++ Dockerfile | 6 ++++ .../generate/expected/bridge0.nmconnection | 2 +- testdata/generate/expected/eth0.nmconnection | 2 +- testdata/generate/expected/lo.nmconnection | 2 +- 7 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e14cce4..4b73490 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,16 +1,31 @@ -on: [push, pull_request] +on: + pull_request: + push: + branches: + - "*" + name: Build & Test +env: + CARGO_TERM_COLOR: always + jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Format + run: cargo fmt --all -- --check + - name: Lint + run: cargo clippy --all-targets --all-features -- -D warnings build: runs-on: ubuntu-latest + needs: [ lint ] steps: - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - name: Build - run: go build -v ./... + run: cargo build - name: Test - run: go test -v ./... + run: cargo test --no-fail-fast + env: + RUST_LOG: debug diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31eb2c4..9e00b5d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,24 +8,31 @@ name: Release permissions: contents: write +env: + CARGO_TERM_COLOR: always + jobs: - build: + release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - - name: Run tests - run: go test -v ./... - - name: Build binaries + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build x86_64 binary + run: | + docker build -t nmc:amd64 --platform linux/amd64 . + container_id=$(docker create nmc:amd64 --entrypoint /) + docker cp $container_id:/target/release/nmc nmc-x86_64 + - name: Build aarch64 binary run: | - GOOS=linux GOARCH=arm64 go build -o nm-configurator-arm64 main.go - GOOS=linux GOARCH=amd64 go build -o nm-configurator-amd64 main.go - - name: Create a release + docker build -t nmc:arm64 --platform linux/arm64 . + container_id=$(docker create nmc:arm64 --entrypoint /) + docker cp $container_id:/target/release/nmc nmc-aarch64 + - name: Release uses: softprops/action-gh-release@v1 with: files: | - nm-configurator-arm64 - nm-configurator-amd64 + nmc-aarch64 + nmc-x86_64 diff --git a/Cargo.toml b/Cargo.toml index 443f0b8..0a8b7a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ name = "nmc" version = "0.1.0" edition = "2021" +authors = ["Atanas Dinov "] +license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eac5caa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM registry.suse.com/bci/rust:1.73 + +COPY . / +WORKDIR / + +RUN cargo build --release --config net.git-fetch-with-cli=true diff --git a/testdata/generate/expected/bridge0.nmconnection b/testdata/generate/expected/bridge0.nmconnection index 28f0544..cf8e656 100644 --- a/testdata/generate/expected/bridge0.nmconnection +++ b/testdata/generate/expected/bridge0.nmconnection @@ -17,4 +17,4 @@ addr-gen-mode=0 method=link-local [ethernet] -cloned-mac-address=FE:C4:05:42:8B:AA \ No newline at end of file +cloned-mac-address=FE:C4:05:42:8B:AA diff --git a/testdata/generate/expected/eth0.nmconnection b/testdata/generate/expected/eth0.nmconnection index 37963ad..d993b1a 100644 --- a/testdata/generate/expected/eth0.nmconnection +++ b/testdata/generate/expected/eth0.nmconnection @@ -16,4 +16,4 @@ method=link-local [ethernet] auto-negotiate=false -cloned-mac-address=0E:4D:C6:B8:C4:72 \ No newline at end of file +cloned-mac-address=0E:4D:C6:B8:C4:72 diff --git a/testdata/generate/expected/lo.nmconnection b/testdata/generate/expected/lo.nmconnection index 11d9034..eccc046 100644 --- a/testdata/generate/expected/lo.nmconnection +++ b/testdata/generate/expected/lo.nmconnection @@ -13,4 +13,4 @@ method=manual [ipv6] addr-gen-mode=0 address0=::1/128 -method=manual \ No newline at end of file +method=manual