Skip to content

Commit

Permalink
Merge pull request #699 from shogo82148/fix-issue-693
Browse files Browse the repository at this point in the history
fix #693
  • Loading branch information
shogo82148 committed Dec 31, 2022
2 parents 70b9ffd + 9c62192 commit df9d4fc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ jobs:

- run: npm ci
- run: npm run build

# reproduce https://github.com/shogo82148/actions-setup-redis/issues/693
- id: tmp
run: |
echo TEST_RUNNER_TOOL_CACHE="$(mktemp -d)" >> "$GITHUB_ENV"
- id: setup
name: use the action
uses: ./
Expand Down
27 changes: 22 additions & 5 deletions build-redis-with-openssl1.1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ export REDIS_VERSION=$1
: "${RUNNER_TEMP:=$ROOT/.work}"
: "${RUNNER_TOOL_CACHE:=$RUNNER_TEMP/dist}"
PREFIX=$RUNNER_TOOL_CACHE/redis/$REDIS_VERSION/x64
# shellcheck disable=SC2016
export LDFLAGS=-Wl,-rpath,'\$$ORIGIN/../lib'

# detect the number of CPU Core
JOBS=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu_max 2>/dev/null)
# configure rpath, and detect the number of CPU Core
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin)
LDFLAGS=-Wl,-rpath,'@executable_path/../lib'
JOBS=$(sysctl -n hw.logicalcpu_max 2>/dev/null)
;;
linux)
# shellcheck disable=SC2016
LDFLAGS=-Wl,-rpath,'\$$ORIGIN/../lib'
JOBS=$(nproc 2>/dev/null)
;;
esac
export LDFLAGS

# bundle OpenSSL for better reproducibility.
OPENSSL_VERSION=1_1_1s
Expand All @@ -38,7 +48,6 @@ echo "::group::build OpenSSL"
(
set -eux
TARGET=""
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin) TARGET="darwin64-x86_64-cc" ;;
linux) TARGET="linux-x86_64" ;;
Expand All @@ -48,6 +57,14 @@ echo "::group::build OpenSSL"
./Configure --prefix="$PREFIX" "$TARGET"
make "-j$JOBS"
make install_sw install_ssldirs

if [[ $OS = darwin ]]; then
install_name_tool -id "@rpath/libcrypto.1.1.dylib" "$PREFIX/lib/libcrypto.1.1.dylib"
install_name_tool -id "@rpath/libssl.1.1.dylib" "$PREFIX/lib/libssl.1.1.dylib"
install_name_tool -change "$PREFIX/lib/libcrypto.1.1.dylib" "@rpath/libcrypto.1.1.dylib" "$PREFIX/lib/libssl.1.1.dylib"
install_name_tool -change "$PREFIX/lib/libcrypto.1.1.dylib" "@rpath/libcrypto.1.1.dylib" "$PREFIX/bin/openssl"
install_name_tool -change "$PREFIX/lib/libssl.1.1.dylib" "@rpath/libssl.1.1.dylib" "$PREFIX/bin/openssl"
fi
)
echo "::endgroup::"

Expand Down
26 changes: 22 additions & 4 deletions build-redis-with-openssl3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ export REDIS_VERSION=$1
: "${RUNNER_TEMP:=$ROOT/.work}"
: "${RUNNER_TOOL_CACHE:=$RUNNER_TEMP/dist}"
PREFIX=$RUNNER_TOOL_CACHE/redis/$REDIS_VERSION/x64
# shellcheck disable=SC2016
export LDFLAGS=-Wl,-rpath,'\$$ORIGIN/../lib'

# detect the number of CPU Core
JOBS=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu_max 2>/dev/null)
# configure rpath, and detect the number of CPU Core
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
darwin)
LDFLAGS=-Wl,-rpath,'@executable_path/../lib'
JOBS=$(sysctl -n hw.logicalcpu_max 2>/dev/null)
;;
linux)
# shellcheck disable=SC2016
LDFLAGS=-Wl,-rpath,'\$$ORIGIN/../lib'
JOBS=$(nproc 2>/dev/null)
;;
esac
export LDFLAGS

# bundle OpenSSL for better reproducibility.
OPENSSL_VERSION=3.0.7
Expand Down Expand Up @@ -41,6 +51,14 @@ echo "::group::build OpenSSL"
./Configure --prefix="$PREFIX" --openssldir="$PREFIX" --libdir=lib
make "-j$JOBS"
make install_sw install_ssldirs

if [[ $OS = darwin ]]; then
install_name_tool -id "@rpath/libcrypto.3.dylib" "$PREFIX/lib/libcrypto.3.dylib"
install_name_tool -id "@rpath/libssl.3.dylib" "$PREFIX/lib/libssl.3.dylib"
install_name_tool -change "$PREFIX/lib/libcrypto.3.dylib" "@rpath/libcrypto.3.dylib" "$PREFIX/lib/libssl.3.dylib"
install_name_tool -change "$PREFIX/lib/libcrypto.3.dylib" "@rpath/libcrypto.3.dylib" "$PREFIX/bin/openssl"
install_name_tool -change "$PREFIX/lib/libssl.3.dylib" "@rpath/libssl.3.dylib" "$PREFIX/bin/openssl"
fi
)
echo "::endgroup::"

Expand Down
3 changes: 3 additions & 0 deletions src/setup-redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import * as starter from './starter';
import {promises as fs} from 'fs';

async function run(): Promise<void> {
if (process.env['TEST_RUNNER_TOOL_CACHE']) {
process.env['RUNNER_TOOL_CACHE'] = process.env['TEST_RUNNER_TOOL_CACHE'];
}
try {
const required = {required: true};
const version = core.getInput('redis-version', required);
Expand Down
25 changes: 20 additions & 5 deletions src/starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,23 @@ async function generateTestCerts(
): Promise<string> {
// search bundled openssl
const openssl = path.join(redisPath, 'openssl');
try {
await fs.stat(openssl);
} catch {
if (!(await exists(openssl))) {
// bundled openssl is not found, this version of redis might not support TLS.
// skip TLS configuration.
core.setOutput('redis-tls-dir', '');
return '';
}

process.env['LD_LIBRARY_PATH'] = path.join(redisPath, '..', 'lib');
process.env['DYLD_LIBRARY_PATH'] = path.join(redisPath, '..', 'lib');
// configure OPENSSL_CONF
// https://github.com/shogo82148/actions-setup-redis/issues/693
let conf = path.join(redisPath, '..', 'openssl.cnf');
if (await exists(conf)) {
process.env['OPENSSL_CONF'] = conf;
}
conf = path.join(redisPath, '..', 'ssl', 'openssl.cnf');
if (await exists(conf)) {
process.env['OPENSSL_CONF'] = conf;
}

const tlsPath = path.join(confPath, 'tls');
await io.mkdirP(tlsPath);
Expand Down Expand Up @@ -215,3 +221,12 @@ async function sleep(waitSec: number): Promise<void> {
setTimeout(() => resolve(), waitSec * 1000);
});
}

async function exists(filename: string): Promise<boolean> {
try {
await fs.stat(filename);
} catch {
return false;
}
return true;
}

0 comments on commit df9d4fc

Please sign in to comment.