From 3781211817e1caf8a50a536bd310ac8ad3f6710e Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Thu, 19 Sep 2024 17:01:56 +0500 Subject: [PATCH] Initial commit --- .github/dependabot.yml | 8 +++ .github/workflows/ci.yml | 93 ++++++++++++++++++++++++++ .gitignore | 1 + README.md | 56 +++++++++++++++- action.yml | 21 ++++++ scripts/setup.bash | 139 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 action.yml create mode 100755 scripts/setup.bash diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ac1560a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7cc7973 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +name: CI + +on: + push: + branches: [main] + paths-ignore: ['**.md'] + pull_request: + branches: [main] + paths-ignore: ['**.md'] + workflow_dispatch: + +jobs: + ci: + strategy: + matrix: + os: [ubuntu-latest, macos-13, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + + defaults: + run: + shell: bash + + steps: + - name: Checkout [${{ github.repository }}] + uses: actions/checkout@v4 + + - name: Create setup script + if: ${{ runner.os == 'Linux' }} + env: + SCRIPTS_DIR: ${{ runner.temp }}/scripts + run: | + pwd + mkdir "$SCRIPTS_DIR" + cd "$SCRIPTS_DIR" + cat >init.sql </dev/null; then + break + fi + sleep 1s + done + if grep 'ERROR' /tmp/oracledb.log >/dev/null; then + echo "[ERR] Something went wrong!" + echo "[ERR] See above logs for more details." + exit 1 + fi + + - name: Set up Oracle Instant Client + id: setup + uses: ./ + + - name: Check output parameter [install-path] + run: echo '${{ steps.setup.outputs.install-path }}' + + - name: Check sqlplus version + run: sqlplus -V + + - name: Run SQL queries on Linux runner + if: ${{ runner.os == 'Linux' }} + run: | + sqlplus -s test/test@localhost:1521/FREEPDB1 < + +branding: + icon: download + color: red + +outputs: + install-path: + description: Absolute install path of Oracle Instant Client + value: ${{ steps.setup.outputs.install-path }} + +runs: + using: composite + + steps: + - name: Setup + id: setup + shell: bash + run: $GITHUB_ACTION_PATH/scripts/setup.bash diff --git a/scripts/setup.bash b/scripts/setup.bash new file mode 100755 index 0000000..c69b44f --- /dev/null +++ b/scripts/setup.bash @@ -0,0 +1,139 @@ +#!/bin/bash + +set -eo pipefail + +echo "[INF] Installing Oracle Instant Client..." + +echo "[INF] - RUNNER_ENVIRONMENT: $RUNNER_ENVIRONMENT" +echo "[INF] - RUNNER_OS: $RUNNER_OS" +echo "[INF] - RUNNER_ARCH: $RUNNER_ARCH" + +INSTALL_PATH= + +if [[ $RUNNER_OS == "Linux" ]]; then + URLS=() + if [[ $RUNNER_ARCH == "X86" ]]; then + URLS=( + https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linux.zip + https://download.oracle.com/otn_software/linux/instantclient/instantclient-sqlplus-linux.zip + ) + elif [[ $RUNNER_ARCH == "X64" ]]; then + URLS=( + https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linuxx64.zip + https://download.oracle.com/otn_software/linux/instantclient/instantclient-sqlplus-linuxx64.zip + ) + elif [[ $RUNNER_ARCH == "ARM64" ]]; then + URLS=( + https://download.oracle.com/otn_software/linux/instantclient/instantclient-basic-linux-arm64.zip + https://download.oracle.com/otn_software/linux/instantclient/instantclient-sqlplus-linux-arm64.zip + ) + else + echo "[ERR] Unsupported architecture! [$RUNNER_ARCH]" + exit 1 + fi + + cd "$RUNNER_TEMP" + + for URL in "${URLS[@]}"; do + echo "[INF] Downloading... [$URL]" + wget --quiet "$URL" + done + + for ZIP in instantclient-*.zip; do + echo "[INF] Extracting... [$ZIP]" + unzip -q -o "$ZIP" + done + + rm -rf "$RUNNER_TEMP"/*.zip + + INSTALL_PATH="$(realpath "$RUNNER_TEMP"/instantclient_*)" + + echo "[INF] Running ldconfig..." + echo "$INSTALL_PATH" | sudo tee /etc/ld.so.conf.d/oracle-instantclient.conf + sudo ldconfig +elif [[ $RUNNER_OS == "macOS" ]]; then + URLS=() + if [[ $RUNNER_ARCH == "X86" || $RUNNER_ARCH == "X64" ]]; then + URLS=( + https://download.oracle.com/otn_software/mac/instantclient/instantclient-basic-macos.dmg + https://download.oracle.com/otn_software/mac/instantclient/instantclient-sqlplus-macos.dmg + ) + elif [[ $RUNNER_ARCH == "ARM64" ]]; then + URLS=( + https://download.oracle.com/otn_software/mac/instantclient/instantclient-basic-macos-arm64.dmg + https://download.oracle.com/otn_software/mac/instantclient/instantclient-sqlplus-macos-arm64.dmg + ) + else + echo "[ERR] Unsupported architecture! [$RUNNER_ARCH]" + exit 1 + fi + + cd "$RUNNER_TEMP" + + for URL in "${URLS[@]}"; do + echo "[INF] Downloading... [$URL]" + wget --quiet "$URL" + done + + for DMG in instantclient-*.dmg; do + echo "[INF] Installing... [$DMG]" + cd "$RUNNER_TEMP" + hdiutil mount -quiet "$DMG" + cd /Volumes/instantclient-* + ./install_ic.sh >/dev/null + hdiutil unmount -force -quiet /Volumes/instantclient-* + done + + rm -rf "$RUNNER_TEMP"/*.dmg + + INSTALL_PATH="$(realpath /Users/"$USER"/Downloads/instantclient_*)" +elif [[ $RUNNER_OS == "Windows" ]]; then + URLS=() + if [[ $RUNNER_ARCH == "X86" ]]; then + URLS=( + https://download.oracle.com/otn_software/nt/instantclient/instantclient-basic-nt.zip + https://download.oracle.com/otn_software/nt/instantclient/instantclient-sqlplus-nt.zip + ) + elif [[ $RUNNER_ARCH == "X64" ]]; then + URLS=( + https://download.oracle.com/otn_software/nt/instantclient/instantclient-basic-windows.zip + https://download.oracle.com/otn_software/nt/instantclient/instantclient-sqlplus-windows.zip + ) + else + echo "[ERR] Unsupported architecture! [$RUNNER_ARCH]" + exit 1 + fi + + echo "[INF] Installing wget..." + if ! choco install wget --no-progress >/dev/null; then + echo "[ERR] Failed to install wget!" + exit 1 + fi + + cd "$RUNNER_TEMP" + + for URL in "${URLS[@]}"; do + echo "[INF] Downloading... [$URL]" + wget --quiet "$URL" + done + + for ZIP in instantclient-*.zip; do + echo "[INF] Extracting... [$ZIP]" + unzip -q -o "$ZIP" + done + + rm -rf "$RUNNER_TEMP"/*.zip + + INSTALL_PATH="$(realpath "$RUNNER_TEMP"/instantclient_*)" +else + echo "[ERR] Unsupported OS! [$RUNNER_OS]" + exit 1 +fi + +echo "[INF] Setting PATH... [$INSTALL_PATH]" +echo "$INSTALL_PATH" >>"$GITHUB_PATH" + +echo "[INF] Setting output parameter... [install-path]" +echo "install-path=$INSTALL_PATH" >>"$GITHUB_OUTPUT" + +echo "[INF] Installed successfully!"