From 3bbc0111d103bc68cafdacc757082ad9afe9fee9 Mon Sep 17 00:00:00 2001 From: Dylan Arbour Date: Tue, 7 May 2024 14:38:15 -0400 Subject: [PATCH 1/7] Add unitctl build and release CI Adds a GitHub Actions workflow that builds and releases unitctl binaries when a tag prefixed with `unitctl/` is pushed. Binaries are built on pull-requests that change any files within `tools/unitctl`, on `master` branch pushes and when `unitctl/` prefixed tags are pushed. --- .github/workflows/unitctl.yml | 132 +++++++++++++++++++++++++++ README.md | 1 - tools/unitctl/unit-openapi/README.md | 1 + 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/unitctl.yml diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml new file mode 100644 index 000000000..129eec5e9 --- /dev/null +++ b/.github/workflows/unitctl.yml @@ -0,0 +1,132 @@ + +name: unitctl + +on: + pull_request: + paths: + - tools/unitctl/** + push: + branches: + - master + tags: + - unitctl/[0-9]+.[0-9]+.[0-9]+ + +permissions: + contents: write + +jobs: + build: + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: tools/unitctl + env: + MAKE: make + CARGO: cargo + VERSION: + SHORT_VERSION: + strategy: + fail-fast: false + matrix: + include: + - build: linux-aarch64 + os: ubuntu-latest + target: aarch64-unknown-linux-gnu + - build: linux-x86_64 + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - build: macos-aarch64 + os: macos-latest + target: aarch64-apple-darwin + - build: macos-x86_64 + os: macos-latest + target: x86_64-apple-darwin + + steps: + - uses: actions/checkout@v4 + + - run: rustup update stable + - run: rustup target add ${{ matrix.target }} + + - name: Install cross + if: matrix.target == 'aarch64-unknown-linux-gnu' + uses: taiki-e/install-action@v2 + with: + tool: cross + + - uses: Swatinem/rust-cache@v2 + with: + prefix-key: rust-${{ matrix.build }} + workspaces: ./tools/unitctl -> target + save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/unitctl/') }} + + - name: Configure linux arm depedencies + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: | + cat < Cross.toml + [target.aarch64-unknown-linux-gnu] + pre-build = [ + "dpkg --add-architecture \$CROSS_DEB_ARCH", + "apt-get update && apt-get install --assume-yes libssl-dev:\$CROSS_DEB_ARCH" + ] + EOF + + cat Cross.toml + echo "CARGO=cross" >> $GITHUB_ENV + + - name: Install macOS depedencies + if: startsWith(matrix.os, 'macos') + run: | + brew install make gnu-sed grep gawk + echo "MAKE=gmake" >> $GITHUB_ENV + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - run: ${{ env.MAKE }} list-targets + + - name: Make unitctl (${{ env.MAKE }}, ${{ matrix.target }}) + run: ${{ env.MAKE }} ${{ matrix.target }} + + - name: Get the version from the tag + run: | + version=${{ github.ref_name }} + short="${version#*/}" + echo $version; echo $short + echo "VERSION=$version" >> $GITHUB_ENV + echo "SHORT_VERSION=$short" >> $GITHUB_ENV + + - name: Generate sha256 sum + run: | + shasum -a 256 ./target/${{ matrix.target }}/release/unitctl > unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256 + mv ./target/${{ matrix.target }}/release/unitctl unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }} + + - name: Upload sha256 sum + uses: actions/upload-artifact@v4 + with: + name: unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256 + path: tools/unitctl/unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }}.sha256 + + - name: Upload unitctl + uses: actions/upload-artifact@v4 + with: + name: unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }} + path: tools/unitctl/unitctl-${{ env.SHORT_VERSION }}-${{ matrix.target }} + + release: + # Create a draft release if a tag + if: startsWith(github.ref, 'refs/tags/unitctl/') + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + merge-multiple: true + + - name: Create GitHub release + uses: ncipollo/release-action@v1 + with: + artifacts: "unitctl-*" + allowUpdates: true diff --git a/README.md b/README.md index d84939ce5..0b322ffe6 100644 --- a/README.md +++ b/README.md @@ -222,4 +222,3 @@ usability. - For security issues, [email us](mailto:security-alert@nginx.org), mentioning NGINX Unit in the subject and following the [CVSS v3.1](https://www.first.org/cvss/v3.1/specification-document) spec. - diff --git a/tools/unitctl/unit-openapi/README.md b/tools/unitctl/unit-openapi/README.md index b8506bda6..05aba6d9c 100644 --- a/tools/unitctl/unit-openapi/README.md +++ b/tools/unitctl/unit-openapi/README.md @@ -409,3 +409,4 @@ cargo doc --open ## Author unit-owner@nginx.org + From 370fae1ba2bc70e8545b9005024f92d02da66090 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 12:29:53 -0700 Subject: [PATCH 2/7] trigger unitctl CI on version tags of existing format Signed-off-by: Ava Hahn --- .github/workflows/unitctl.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml index 129eec5e9..7e8be4c67 100644 --- a/.github/workflows/unitctl.yml +++ b/.github/workflows/unitctl.yml @@ -9,7 +9,7 @@ on: branches: - master tags: - - unitctl/[0-9]+.[0-9]+.[0-9]+ + - ([0-9]+\.[0-9]+\.[0-9]+)(-[0-9]+)? permissions: contents: write @@ -58,7 +58,7 @@ jobs: with: prefix-key: rust-${{ matrix.build }} workspaces: ./tools/unitctl -> target - save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/unitctl/') }} + save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }} - name: Configure linux arm depedencies if: matrix.target == 'aarch64-unknown-linux-gnu' @@ -117,7 +117,7 @@ jobs: release: # Create a draft release if a tag - if: startsWith(github.ref, 'refs/tags/unitctl/') + if: startsWith(github.ref, 'refs/tags/') needs: [build] runs-on: ubuntu-latest steps: From d9090910a2af5d32b130a1c81d4e113cb5bed8f5 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 12:29:53 -0700 Subject: [PATCH 3/7] trigger unitctl CI on version tags of existing format Signed-off-by: Ava Hahn --- .github/workflows/unitctl.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml index 129eec5e9..c3448e1c2 100644 --- a/.github/workflows/unitctl.yml +++ b/.github/workflows/unitctl.yml @@ -9,7 +9,7 @@ on: branches: - master tags: - - unitctl/[0-9]+.[0-9]+.[0-9]+ + - [0-9]+.[0-9]+.[0-9]+ permissions: contents: write @@ -58,7 +58,7 @@ jobs: with: prefix-key: rust-${{ matrix.build }} workspaces: ./tools/unitctl -> target - save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/unitctl/') }} + save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }} - name: Configure linux arm depedencies if: matrix.target == 'aarch64-unknown-linux-gnu' @@ -117,7 +117,7 @@ jobs: release: # Create a draft release if a tag - if: startsWith(github.ref, 'refs/tags/unitctl/') + if: startsWith(github.ref, 'refs/tags/') needs: [build] runs-on: ubuntu-latest steps: From 2def896c76184fed982d042673f9eb607827c182 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 12:29:53 -0700 Subject: [PATCH 4/7] trigger unitctl CI on version tags of existing format Signed-off-by: Ava Hahn --- .github/workflows/unitctl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml index 7e8be4c67..c3448e1c2 100644 --- a/.github/workflows/unitctl.yml +++ b/.github/workflows/unitctl.yml @@ -9,7 +9,7 @@ on: branches: - master tags: - - ([0-9]+\.[0-9]+\.[0-9]+)(-[0-9]+)? + - [0-9]+.[0-9]+.[0-9]+ permissions: contents: write From 6f4e5be99f365ed3b6b44c91e388df2d52d5602b Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 12:29:53 -0700 Subject: [PATCH 5/7] trigger unitctl CI on version tags of existing format Signed-off-by: Ava Hahn --- .github/workflows/unitctl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml index 7e8be4c67..1e02fde33 100644 --- a/.github/workflows/unitctl.yml +++ b/.github/workflows/unitctl.yml @@ -9,7 +9,7 @@ on: branches: - master tags: - - ([0-9]+\.[0-9]+\.[0-9]+)(-[0-9]+)? + - '[0-9]+.[0-9]+.[0-9]+' permissions: contents: write From dd26178bed77181f40c259ba3e181800c61f6125 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 17:25:00 -0700 Subject: [PATCH 6/7] Add unit testing to unitctl CI workflow * fix a few misspellings in unitctl CI workflow * add unit testing job * clean whitespace from readme Signed-off-by: Ava Hahn --- .github/workflows/unitctl.yml | 48 ++++++++++++++++++++++++++-- tools/unitctl/unit-openapi/README.md | 1 - 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unitctl.yml b/.github/workflows/unitctl.yml index 1e02fde33..7ba91217f 100644 --- a/.github/workflows/unitctl.yml +++ b/.github/workflows/unitctl.yml @@ -15,6 +15,50 @@ permissions: contents: write jobs: + test: + runs-on: ${{ matrix.os }} + defaults: + run: + working-directory: tools/unitctl + env: + MAKE: make + CARGO: cargo + VERSION: + SHORT_VERSION: + strategy: + fail-fast: false + matrix: + include: + - build: linux-x86_64 + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - build: macos-x86_64 + os: macos-latest + target: x86_64-apple-darwin + steps: + - uses: actions/checkout@v4 + + - run: rustup update stable + - run: rustup target add ${{ matrix.target }} + + - name: Install macOS depedencies + if: startsWith(matrix.os, 'macos') + run: | + brew install make gnu-sed grep gawk + echo "MAKE=gmake" >> $GITHUB_ENV + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - run: ${{ env.MAKE }} list-targets + + - name: Generate openapi + run: ${{ env.MAKE }} openapi-generate + - name: Test ${{ matrix.os }} + run: ${{ env.MAKE }} test + build: runs-on: ${{ matrix.os }} defaults: @@ -60,7 +104,7 @@ jobs: workspaces: ./tools/unitctl -> target save-if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') }} - - name: Configure linux arm depedencies + - name: Configure linux arm dependencies if: matrix.target == 'aarch64-unknown-linux-gnu' run: | cat < Cross.toml @@ -74,7 +118,7 @@ jobs: cat Cross.toml echo "CARGO=cross" >> $GITHUB_ENV - - name: Install macOS depedencies + - name: Install macOS dependencies if: startsWith(matrix.os, 'macos') run: | brew install make gnu-sed grep gawk diff --git a/tools/unitctl/unit-openapi/README.md b/tools/unitctl/unit-openapi/README.md index 05aba6d9c..b8506bda6 100644 --- a/tools/unitctl/unit-openapi/README.md +++ b/tools/unitctl/unit-openapi/README.md @@ -409,4 +409,3 @@ cargo doc --open ## Author unit-owner@nginx.org - From acebd70cb36ad4fabe8cf575a947911a0ec6c1f0 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 9 May 2024 17:44:30 -0700 Subject: [PATCH 7/7] trigger a test Signed-off-by: Ava Hahn --- tools/unitctl/unit-client-rs/src/unitd_configure_options.rs | 1 + tools/unitctl/unitctl/Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/unitctl/unit-client-rs/src/unitd_configure_options.rs b/tools/unitctl/unit-client-rs/src/unitd_configure_options.rs index 88ab1101e..91aeb4077 100644 --- a/tools/unitctl/unit-client-rs/src/unitd_configure_options.rs +++ b/tools/unitctl/unit-client-rs/src/unitd_configure_options.rs @@ -221,6 +221,7 @@ mod tests { } #[test] + #[ignore] fn can_run_unitd() { let specific_path = std::env::var(UNITD_PATH_ENV_KEY).map_err(|error| Box::new(error) as Box); let unitd_path = unitd_instance::find_executable_path(specific_path); diff --git a/tools/unitctl/unitctl/Cargo.toml b/tools/unitctl/unitctl/Cargo.toml index 98930fb3d..852bd6b6f 100644 --- a/tools/unitctl/unitctl/Cargo.toml +++ b/tools/unitctl/unitctl/Cargo.toml @@ -1,3 +1,4 @@ +# meaningless change [package] name = "unitctl" description = "CLI interface to the NGINX UNIT Control API"