Skip to content

Commit 1cb16f6

Browse files
committed
Add a CI with multiple OpenSSL versions
1 parent 67f3786 commit 1cb16f6

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

.github/workflows/ci.yml

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Test the bindings using various OpenSSL versions
2+
#
3+
# For Linux / Windows, we cannot rely on the package manager,
4+
# as each new release will come with a specific OpenSSL version,
5+
# and we don't have control over this.
6+
#
7+
# Instead, this workflow installs an explicit version, builds it,
8+
# and test the tls package with it.
9+
name: CI
10+
11+
on: [push, pull_request]
12+
13+
jobs:
14+
deps:
15+
strategy:
16+
matrix:
17+
os: [ ubuntu-latest ]
18+
openssl:
19+
- version: 1.0.2u
20+
link: https://www.openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
21+
- version: 1.1.0l
22+
link: https://www.openssl.org/source/old/1.1.0/openssl-1.1.0l.tar.gz
23+
- version: 1.1.1o
24+
link: https://www.openssl.org/source/openssl-1.1.1o.tar.gz
25+
- version: 3.0.3
26+
link: https://www.openssl.org/source/openssl-3.0.3.tar.gz
27+
28+
runs-on: ${{ matrix.os }}
29+
timeout-minutes: 15
30+
31+
# Build the OpenSSL version if not already cached
32+
steps:
33+
- name: 'Looking up cache'
34+
id: cache-openssl
35+
uses: actions/cache@v1
36+
with:
37+
path: ${{ github.workspace }}/openssl/
38+
key: ${{ runner.os }}-${{ runner.arch }}-${{ matrix.openssl.version }}
39+
40+
- name: 'Download and build OpenSSL ${{ matrix.openssl.version }}'
41+
if: steps.cache-openssl.outputs.cache-hit != 'true'
42+
run: |
43+
mkdir -p ${{ github.workspace }}/openssl/
44+
pushd ${{ github.workspace }}/openssl/
45+
wget -O download.tar.gz ${{ matrix.openssl.link }}
46+
tar -xf download.tar.gz
47+
pushd openssl-${{ matrix.openssl.version }}/
48+
./config --prefix=${{ github.workspace }}/openssl/install/
49+
make install
50+
echo "OpenSSL ${{ matrix.openssl.version }} has been installed in: ${{ github.workspace }}/openssl/install/"
51+
52+
# The previous job was separated to avoid a build once per matrix row,
53+
# as opposed to once per platform / version as we want.
54+
test:
55+
needs: deps
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
os: [ ubuntu-latest ]
60+
dc:
61+
- dmd-latest
62+
- ldc-latest
63+
openssl:
64+
- version: 1.0.2u
65+
lib-dir: lib
66+
- version: 1.1.0l
67+
lib-dir: lib
68+
- version: 1.1.1o
69+
lib-dir: lib
70+
- version: 3.0.3
71+
lib-dir: lib64
72+
73+
runs-on: ${{ matrix.os }}
74+
timeout-minutes: 60
75+
76+
steps:
77+
- uses: actions/checkout@v2
78+
79+
- name: Prepare compiler
80+
uses: dlang-community/setup-dlang@v1
81+
with:
82+
compiler: ${{ matrix.dc }}
83+
84+
# Restore or install build openssl version
85+
- name: 'Restore openssl from cache'
86+
id: lookup-openssl
87+
uses: actions/cache@v1
88+
with:
89+
path: ${{ github.workspace }}/openssl/
90+
key: ${{ matrix.os }}-${{ matrix.openssl.version }}
91+
92+
- name: 'Make sure OpenSSL was loaded from cache'
93+
if: steps.lookup-openssl.outputs.cache-hit != 'true'
94+
run: exit 1
95+
96+
- name: 'Remove OpenSSL package, export env variables'
97+
run: |
98+
sudo apt-get remove -y libssl-dev
99+
echo "PKG_CONFIG_PATH=${{ github.workspace }}/openssl/install/${{ matrix.openssl.lib-dir }}/pkgconfig/" >> $GITHUB_ENV
100+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${{ github.workspace }}/openssl/install/${{ matrix.openssl.lib-dir }}/" >> $GITHUB_ENV
101+
102+
- name: 'Run tests'
103+
run: |
104+
echo "pkg-config uses: $(pkg-config --modversion openssl)"
105+
if [ `pkg-config --modversion openssl` != "${{ matrix.openssl.version }}" ]; then
106+
echo "Expected version '${{ matrix.openssl.version }}' but got `pkg-config --modversion openssl`"
107+
exit 1
108+
fi
109+
cd examples/sslecho/
110+
${{ github.workspace }}/openssl/install/bin/openssl req -batch -newkey rsa:4096 -x509 -sha256 -days 3650 -subj "/C=GB/CN=localhost" -nodes -out cert.pem -keyout key.pem
111+
dub build
112+
# TODO: FIXME: This currently does not work because certificate verification fails (works on my machine).
113+
# But at least it links, which is a good starting point.
114+
#$DC -run test.d

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/*-test-library
88

99
/examples/sslecho/sslecho
10+
/examples/sslecho/test

examples/sslecho/test.d

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// Runs the server and the client in a fork for CI
2+
module test;
3+
4+
import core.thread;
5+
import core.time;
6+
7+
import std.process;
8+
import std.stdio;
9+
10+
int main ()
11+
{
12+
auto serverPid = spawnProcess([ "./sslecho", "s" ]);
13+
writeln("Server has been spawned");
14+
Thread.sleep(3.seconds);
15+
auto clientPid = spawnShell(`echo "Hello World\nkill" | ./sslecho c localhost`);
16+
writeln("Client has been spawned");
17+
Thread.sleep(3.seconds);
18+
19+
if (auto res = clientPid.wait())
20+
return res;
21+
if (auto res = serverPid.wait())
22+
return res;
23+
24+
return 0;
25+
}

0 commit comments

Comments
 (0)