diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index 89d58ef..93976d5 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -1,21 +1,26 @@ name: 'wgetpaste test runner' on: [pull_request, push] jobs: - run-test: - name: 'Run test/test.sh' + run-tests: + strategy: + matrix: + test: [test, test_ansi] + name: "Run test/${{ matrix.test }}" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - run: test/test.sh - shell: bash - run-test-ansi: - name: 'Run test/test_ansi.sh' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: 'Install ansifilter' + - name: 'Checkout repository' + uses: actions/checkout@v4 + + - name: 'Install dependencies' run: | sudo apt-get update - sudo apt-get install ansifilter - - run: test/test_ansi.sh + sudo apt-get install meson ${{ matrix.test == 'test_ansi' && 'ansifilter' || '' }} + shell: bash + + - name: 'Build wgetpaste' + run: | + mkdir build + meson setup build --prefix="/" shell: bash + + - run: meson test -C ./build ${{ matrix.test }} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..d6fefb2 --- /dev/null +++ b/meson.build @@ -0,0 +1,45 @@ +project( + 'wgetpaste', + license: 'MIT', + license_files: 'LICENSE', + version: '2.35.0', + meson_version: '>=1.1.0', +) + +config_data = configuration_data() +config_data.set('WGETPASTE_SHEBANG', get_option('shebang')) +config_data.set('WGETPASTE_VERSION', meson.project_version()) +configure_file( + output: 'wgetpaste', + input: 'wgetpaste', + configuration: config_data, + install: true, + install_dir: get_option('bindir'), + install_mode: 'rwxr-xr-x' +) + +install_data( + '_wgetpaste', + install_dir: get_option('datadir') / get_option('zsh-completions-dir'), + install_mode: 'rw-r--r--' +) + +test_runner = find_program('test/test.sh') +test( + 'test', + test_runner, + timeout: 0, + env: [ + 'MESON_BUILD_ROOT=' + meson.project_build_root() + ] +) + +test_runner = find_program('test/test_ansi.sh') +test( + 'test_ansi', + test_runner, + timeout: 0, + env: [ + 'MESON_BUILD_ROOT=' + meson.project_build_root() + ] +) diff --git a/meson.options b/meson.options new file mode 100644 index 0000000..3157050 --- /dev/null +++ b/meson.options @@ -0,0 +1,11 @@ +option( + 'shebang', + type: 'string', + value: '/usr/bin/env bash', + description: 'Specify shebang line for wgetpaste script' +) +option('zsh-completions-dir', + type: 'string', + value: 'zsh/site-functions', + description: 'Specify location of zsh-completions directory (relative to datadir)' +) diff --git a/test/test.sh b/test/test.sh index 45c3624..3e0134f 100755 --- a/test/test.sh +++ b/test/test.sh @@ -6,6 +6,7 @@ # Don't assume the test is being run from the same directory as the script TEST_DIR="$(dirname "$0")" +WGETPASTE="${MESON_BUILD_ROOT}/wgetpaste" TEST_FILE="$TEST_DIR/test.txt" DL_DIR="$(mktemp -q --tmpdir -d wgetpaste_test.XXXXX)" # Services to hard skip @@ -30,7 +31,7 @@ echo "Using download directory: $DL_DIR" # Post test file into each service (if possible) # Download the resulting paste into /tmp/wgetpaste_test.XXXXX/.txt -for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do +for serv in $("$WGETPASTE" -S --completions); do # Hard skips for hs in "${!HARD_SKIPS[@]}"; do if [ "$serv" == "$hs" ]; then @@ -45,7 +46,7 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do # Log deleted at the end of each loop unless error other than 401 echo -n "Posting to $serv: " ERROR_LOG="$DL_DIR/$serv-error.log" - URL="$("$TEST_DIR"/../wgetpaste -r -s "$serv" -v "$TEST_FILE" 2>"$ERROR_LOG")" + URL="$("$WGETPASTE" -r -s "$serv" -v "$TEST_FILE" 2>"$ERROR_LOG")" STATUS="$?" # Skip failed posts (eg, not authorized for GitHub/GitLab, service error) diff --git a/test/test_ansi.sh b/test/test_ansi.sh index e1e95f0..fb14425 100755 --- a/test/test_ansi.sh +++ b/test/test_ansi.sh @@ -7,6 +7,7 @@ # Don't assume the test is being run from the same directory as the script TEST_DIR="$(dirname "$0")" +WGETPASTE="${MESON_BUILD_ROOT}/wgetpaste" ANSI_FILE="$TEST_DIR/red.txt" NOANSI_FILE="$TEST_DIR/red_no_ansi.txt" DL_DIR="$(mktemp -q --tmpdir -d wgetpaste_test_ansi.XXXXX)" @@ -30,7 +31,7 @@ fi echo "Using download directory: $DL_DIR" # Post test file into each service until one succeeds -for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do +for serv in $("$WGETPASTE" -S --completions); do # Hard skips for hs in "${!HARD_SKIPS[@]}"; do if [ "$serv" == "$hs" ]; then @@ -44,7 +45,7 @@ for serv in $("$TEST_DIR"/../wgetpaste -S --completions); do # Log deleted at the end of each loop unless error other than 401 echo -n "Posting to $serv: " ERROR_LOG="$DL_DIR/$serv-error.log" - URL="$("$TEST_DIR"/../wgetpaste -r -s "$serv" -v "$ANSI_FILE" 2>"$ERROR_LOG")" + URL="$("$WGETPASTE" -r -s "$serv" -v "$ANSI_FILE" 2>"$ERROR_LOG")" STATUS="$?" # Skip failed posts (eg, not authorized for GitHub/GitLab, service error) @@ -96,7 +97,7 @@ fi sleep 1 echo -n "Pasting command output with ANSI stripping (cat): " ERROR_LOG="$DL_DIR/command-noansi-error.log" -URL="$("$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")" +URL="$("$WGETPASTE" -N -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) @@ -118,7 +119,7 @@ fi sleep 1 echo -n "Pasting command output without ANSI stripping (cat): " ERROR_LOG="$DL_DIR/command-ansi-error.log" -URL="$("$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")" +URL="$("$WGETPASTE" -A -r -s "$WORKING" -v -c "cat $ANSI_FILE" 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) @@ -141,7 +142,7 @@ fi sleep 1 echo -n "Pasting stdin with ANSI stripping (cat | wgetpaste): " ERROR_LOG="$DL_DIR/stdin-noansi-error.log" -URL="$(cat "$ANSI_FILE" | "$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v 2>"$ERROR_LOG")" +URL="$(cat "$ANSI_FILE" | "$WGETPASTE" -N -r -s "$WORKING" -v 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) @@ -160,7 +161,7 @@ fi sleep 1 echo -n "Pasting stdin without ANSI stripping (cat | wgetpaste): " ERROR_LOG="$DL_DIR/stdin-ansi-error.log" -URL="$(cat "$ANSI_FILE" | "$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v 2>"$ERROR_LOG")" +URL="$(cat "$ANSI_FILE" | "$WGETPASTE" -A -r -s "$WORKING" -v 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) @@ -180,7 +181,7 @@ fi sleep 1 echo -n "Pasting a file with ANSI stripping: " ERROR_LOG="$DL_DIR/file-noansi-error.log" -URL="$("$TEST_DIR"/../wgetpaste -N -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")" +URL="$("$WGETPASTE" -N -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) @@ -199,7 +200,7 @@ fi sleep 1 echo -n "Pasting a file without ANSI stripping: " ERROR_LOG="$DL_DIR/file-ansi-error.log" -URL="$("$TEST_DIR"/../wgetpaste -A -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")" +URL="$("$WGETPASTE" -A -r -s "$WORKING" -v "$ANSI_FILE" 2>"$ERROR_LOG")" if [ $? -ne 0 ]; then echo "FAILED!" FAILED_PASTE=$((FAILED_PASTE + 1)) diff --git a/wgetpaste b/wgetpaste index f96ed08..eb0279c 100755 --- a/wgetpaste +++ b/wgetpaste @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +#!@WGETPASTE_SHEBANG@ # A Script that automates pasting to a number of pastebin services # relying only on bash, sed, coreutils (mktemp/sort/tr/wc/whoami/tee) and wget # Copyright (c) 2007-2016 Bo Ørsted Andresen -VERSION="2.33" +VERSION="@WGETPASTE_VERSION@" # don't inherit LANGUAGE from the env unset LANGUAGE