Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ on:
- '**/Cargo.toml'
- '**/Cargo.lock'
- 'tests/**'
#- .github/workflows/ci.yml
- .github/workflows/ci.yml
- .github/workflows/test.yml
- .github/workflows/test-compat.yml

defaults:
run:
Expand Down
170 changes: 108 additions & 62 deletions .github/workflows/test-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,113 @@ defaults:
shell: bash

jobs:
build-matrix:
runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.matrix.outputs.matrix }}

steps:
- name: matrix
id: matrix
run: |
MATRIX=$(jq -c -r --null-input '
. as $_

| [
{
openresty: "1.19.9.1",
openssl: "1.1.1n",
cli: [
"v0.28"
]
},
{
openresty: "1.21.4.3",
openssl: "1.1.1w",
cli: [
"v0.29"
]
},
{
openresty: "1.25.3.2",
openssl: "1.1.1w",
cli: [
"v0.29"
]
},
{
openresty: "1.27.1.2",
openssl: "3.4.1",
cli: [
"v0.29",
"v0.30",
"v0.31",
"v0.32"
]
}
] as $RESTY_META

| reduce (
$RESTY_META[]
| .openresty as $openresty
| .openssl as $openssl
| {
$openresty,
$openssl,
cli: .cli[]
}
) as { $openresty, $openssl, $cli }
(
{
label: [],
include: [],
};

.
| "cli(\($cli)) - resty(\($openresty))" as $label
| .label += [$label]
| .include += [{
$label,
$openresty,
$openssl,
"resty-cli": $cli,
}]
)
'
)

echo "matrix=${MATRIX}" >> $GITHUB_OUTPUT
{
echo '# matrix'
echo '```json'
jq --indent 2 <<< "$MATRIX"
echo '```'
} >> $GITHUB_STEP_SUMMARY

compat:
name: resty-cli compat ${{ matrix.resty-cli }} / ${{ matrix.openresty }}
name: ${{ matrix.label }}
runs-on: ubuntu-latest
needs: [build-matrix]
strategy:
matrix:
include:
- openresty: 1.19.9.1
resty-cli: v0.28
openssl: 1.1.1n
openresty-opts: >
--with-compat
--with-pcre
--with-pcre-jit
--with-stream
--with-threads
--with-http_ssl_module
--with-stream_ssl_module
--with-stream_ssl_preread_module

- openresty: 1.21.4.3
resty-cli: v0.29
openssl: 1.1.1n
openresty-opts: >
--with-compat
--with-pcre
--with-pcre-jit
--with-stream
--with-threads
--with-http_ssl_module
--with-stream_ssl_module
--with-stream_ssl_preread_module

- openresty: 1.25.3.2
resty-cli: v0.30
openssl: 1.1.1w
openresty-opts: >
--with-compat
--with-pcre
--with-pcre-jit
--with-stream
--with-threads
--with-http_ssl_module
--with-stream_ssl_module
--with-stream_ssl_preread_module

- openresty: 1.27.1.1
resty-cli: v0.30
openssl: 3.0.15
openresty-opts: >
--with-compat
--with-pcre
--with-pcre-jit
--with-stream
--with-threads
--with-http_ssl_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
# don't cancel in-progress test if one matrix fails
fail-fast: false

matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}

env:
RESTY_CLI_COMPAT_VERSION: ${{ matrix.resty-cli }}
RESTY_BUILD_OPTS: >
--with-compat
--with-pcre
--with-pcre-jit
--with-stream
--with-threads
--with-http_ssl_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
RESTY_OPENSSL_VERSION: ${{ matrix.openssl }}
RESTY_VERSION: ${{ matrix.openresty }}

steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand All @@ -77,20 +127,16 @@ jobs:
sudo apt-get install -y gdb libpcre3
gdb --version

- name: set resty-cli compat env var
run: echo "RESTY_CLI_COMPAT_VERSION=${{ matrix.resty-cli }}" >> $GITHUB_ENV

- name: set OpenResty prefix
run: |
echo OPENRESTY_PREFIX=${GITHUB_WORKSPACE}/openresty/${{ matrix.openresty }} >> $GITHUB_ENV
echo OPENRESTY_PREFIX=${GITHUB_WORKSPACE}/openresty/${RESTY_VERSION:?} >> $GITHUB_ENV
echo PERL5LIB=${GITHUB_WORKSPACE}/work/lib/cpanm/lib/perl5 >> $GITHUB_ENV

- name: Store OpenResty build opts
run: |
> .resty-opts
echo '${{ matrix.openresty-opts }}' >> .resty-opts
echo '${{ matrix.resty-cli }}' >> .resty-opts
echo '${{ matrix.openssl }}' >> .resty-opts
echo "${RESTY_BUILD_OPTS:?}" >> .resty-opts
echo "${RESTY_OPENSSL_VERSION:?}" >> .resty-opts

- name: cache OpenResty
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
Expand All @@ -116,7 +162,7 @@ jobs:
openssl-version: ${{ matrix.openssl }}
test-nginx: true
debug: true
opt: ${{ matrix.openresty-opts }}
opt: ${{ env.RESTY_BUILD_OPTS }}

- name: Cleanup OpenResty build artifacts
if: steps.cache-openresty.outputs.cache-hit != 'true'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defaults:
run:
shell: bash


jobs:
cargo-test:
name: cargo test (${{ matrix.label }})
Expand Down
87 changes: 87 additions & 0 deletions scripts/add-new-test-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env bash

set -euo pipefail
shopt -s failglob

readonly VERSIONS=./tests/versions

FORCE=0

detect_last_version() {
local -r before=${1:?}

local -a versions=("$VERSIONS"/*)

# strip leading path components
versions=( "${versions[@]##*/}" )

local result
local ver
for ver in "${versions[@]}"; do
if [[ $ver < $before && $ver > ${result:-"v0.0"} ]]; then
result=$ver
fi
done

if [[ -n ${result:-} ]]; then
echo "last version before ${before}: ${result}"
declare -g REPLY="$result"
else
echo "failed getting the most recent version before ${before}"
return 1
fi
}

patches() {
local -r version=${1:?}
local -r last=${2:?}

mkdir -p "${VERSIONS}/${version}/patches"
echo "creating patches in ${VERSIONS}/${version}/patches"
ln \
--relative \
--symbolic \
"${VERSIONS}/${last}/patches"/* \
"${VERSIONS}/${version}/patches"
}

setup() {
local -r version=${1:?}

detect_last_version "$version"
local -r last=$REPLY

if (( FORCE )); then
rm -rf "${VERSIONS:?}/${version:?}"
fi

patches "$version" "$last"
}

main() {
local -a args=()
while [[ -n ${1:-} ]]; do
case $1 in
-f|--force)
FORCE=1
;;
*)
args+=("$1")
;;
esac
shift
done

set -- "${args[@]}"

local version=${1:?version is required}
version=v${version#v}

if ! [[ $version =~ ^v[0-9]+\.[0-9]+$ ]]; then
echo "error: invalid version: $version"
fi

setup "$version"
}

main "$@"
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl Action {
.http(http_conf(&mut user))
.lua(lua_loader)
.resty_compat_version(resty_compat_version)
.modules(user.modules)
.render(&mut file)
.and_then(|_| file.flush());

Expand Down Expand Up @@ -372,6 +373,7 @@ pub(crate) struct UserArgs {
pub(crate) main_conf: Vec<String>,
pub(crate) main_include: Vec<String>,
pub(crate) user_shdicts: Vec<Shdict>,
pub(crate) modules: Vec<String>,

pub(crate) stream_conf: Vec<String>,
pub(crate) no_stream: bool,
Expand Down Expand Up @@ -545,6 +547,10 @@ impl Action {
arg.push_to(&mut user.inline_lua, optarg)?;
}

"--load-module" => {
user.modules.push(arg.get_arg(optarg)?);
}

"--" => {
user.lua_file = optarg.take();
end_of_args = true;
Expand Down
16 changes: 16 additions & 0 deletions src/nginx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) struct ConfBuilder {
http: Option<Vec<String>>,
lua: Option<Vec<String>>,
resty_compat_version: Option<u64>,
modules: Vec<String>,
}

impl ConfBuilder {
Expand Down Expand Up @@ -73,6 +74,14 @@ impl ConfBuilder {
self
}

pub(crate) fn modules<T>(mut self, t: T) -> Self
where
T: IntoIterator<Item = String>,
{
self.modules = Vec::from_iter(t);
self
}

pub(crate) fn render<T>(self, buf: &mut T) -> io::Result<()>
where
T: io::Write,
Expand All @@ -93,6 +102,7 @@ impl From<ConfBuilder> for Conf {
http,
lua,
resty_compat_version,
modules,
} = cb;

Self {
Expand All @@ -103,6 +113,7 @@ impl From<ConfBuilder> for Conf {
http: http.unwrap_or_default(),
lua: lua.unwrap_or_default(),
resty_compat_version: resty_compat_version.unwrap_or_else(get_resty_compat_version),
modules,
}
}
}
Expand All @@ -114,6 +125,7 @@ struct Conf {
stream: Vec<String>,
http: Vec<String>,
lua: Vec<String>,
modules: Vec<String>,
resty_compat_version: u64,
}

Expand All @@ -138,6 +150,10 @@ impl Conf {
writeln!(buf, "# resty-cli compat: v0.{}", self.resty_compat_version)?;
writeln!(buf)?;

for modname in &self.modules {
writeln!(buf, "load_module {};", modname)?;
}

writeln!(buf, "daemon off;")?;
writeln!(buf, "master_process off;")?;
writeln!(buf, "worker_processes 1;")?;
Expand Down
Loading
Loading