From 8e215f4cbdb402b009550e56040b05e732019196 Mon Sep 17 00:00:00 2001 From: Shinsuke Sugaya Date: Sat, 10 Feb 2024 12:19:37 +0900 Subject: [PATCH] Refactor GitHub Actions for Improved Efficiency and Maintenance (#2805) --- .github/workflows/codeql-analysis.yml | 50 +++++---------------------- .github/workflows/maven.yml | 10 +++--- src/test/resources/before_script.sh | 48 +++++++++++++++---------- src/test/resources/run.sh | 5 +-- 4 files changed, 45 insertions(+), 68 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index cbf0c35e1..c13c36e5b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,8 +1,3 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. name: "CodeQL" on: @@ -16,73 +11,44 @@ on: - "*.x" schedule: - cron: '36 4 * * 2' + workflow_dispatch: jobs: analyze: name: Analyze runs-on: ubuntu-latest + timeout-minutes: 20 strategy: fail-fast: false matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] language: ['java', 'javascript'] - # Learn more... - # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: - # We must fetch at least the immediate parents so that if this is - # a pull request then we can checkout the head. fetch-depth: 2 - # If this run was triggered by a pull request event, then checkout - # the head of the pull request instead of the merge commit. - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - #- name: Autobuild - # uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - uses: actions/checkout@v2 - name: Set up JDK 21 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v4 with: - path: ~/.m2 + path: ~/.m2/repository key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Build with Maven run: mvn -B package --file pom.xml - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v3 + diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e5dc3f778..5b0c5eb25 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -12,20 +12,20 @@ on: branches: - master - "*.x" + workflow_dispatch: jobs: build: - runs-on: ubuntu-latest - + timeout-minutes: 15 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 21 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/src/test/resources/before_script.sh b/src/test/resources/before_script.sh index 432788fe0..019fb4649 100644 --- a/src/test/resources/before_script.sh +++ b/src/test/resources/before_script.sh @@ -1,26 +1,36 @@ #!/bin/bash +set -xuo pipefail -TMP_FILE=/tmp/fess-build.$$ -unzip target/releases/fess-*.zip 2>&1 > $TMP_FILE -tail $TMP_FILE +temp_log_file=/tmp/fess-build.$$ +unzip target/releases/fess-*.zip > ${temp_log_file} 2>&1 +tail ${temp_log_file} -./fess-*/bin/fess 2>&1 > $TMP_FILE & +./fess-*/bin/fess > ${temp_log_file} 2>&1 & -pushd /tmp -git clone https://github.com/codelibs/fess-testdata.git -popd - -tail $TMP_FILE -touch `ls -d ./fess-*/logs`/fess-crawler.log -tail -f ./fess-*/logs/*.log & - -counter=0 -ret=1 -while [ $ret != 0 -a $counter != 180 ] ; do - echo "Ping Fess... $counter" - curl -v "localhost:8080/json/?type=ping" - ret=$? +temp_json_file=/tmp/fess-log.$$ +touch ${temp_json_file} +error_count=0 +while true ; do + status=$(curl -w '%{http_code}\n' -s -o ${temp_json_file} "http://localhost:8080/api/v1/health") + cat ${temp_json_file} + if [[ x"${status}" = x200 ]] ; then + break + else + error_count=$((error_count + 1)) + fi + if [[ ${error_count} -ge 60 ]] ; then + echo "Fess is not available." + cat ${temp_log_file} ./fess-*/logs/*.log + exit 1 + fi sleep 1 - counter=$((counter + 1)) done +pushd /tmp >/dev/null +git clone https://github.com/codelibs/fess-testdata.git +popd >/dev/null + +cat ${temp_log_file} ./fess-*/logs/*.log +curl -s "http://localhost:9201/_cat/indices?v" +curl -s "http://localhost:8080/" + diff --git a/src/test/resources/run.sh b/src/test/resources/run.sh index ea131a71f..ab2b053e4 100644 --- a/src/test/resources/run.sh +++ b/src/test/resources/run.sh @@ -1,8 +1,9 @@ #!/bin/bash -tail -f ./fess-*/logs/fess-crawler.log & +touch $(ls -d ./fess-*/logs)/fess-crawler.log +tail -f ./fess-*/logs/*.log & -mvn test -P integrationTests -Dtest.fess.url="http://127.0.0.1:8080" -Dtest.search_engine.url="http://127.0.0.1:9201" +mvn test -P integrationTests -Dtest.fess.url="http://localhost:8080" -Dtest.search_engine.url="http://localhost:9201" ret=$? if [ $ret != 0 ] ; then