diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d5ac8c335d163..b2b3ccf5f9ef9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -272,6 +272,26 @@ jobs: -d ${{ matrix.distribution }} \ -n ${{ steps.min_package.outputs.name }} + # Cache OpenSearch plugins + - name: Get Opensearch Version + run: | + VERSION=$(bash build-scripts/upstream-version.sh) + echo "versionOpenSearch_inBuild=$VERSION" >> $GITHUB_OUTPUT + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Cache OpenSearch plugins + id: cache-opensearch-plugins + uses: actions/cache@v4 + with: + path: $HOME/.m2/repository/org/opensearch/plugin/performance-analyzer/${{ env.VERSION }}.0/ + key: ${{ runner.os }}-opensearch-${{ hashFiles('performance-analyzer**.xml') }} + restore-keys: | + ${{ runner.os }}-opensearch-performance-analyzer + + - if: ${{steps.cache-opensearch-plugins.cache-hit != 'true'}} + name: Cache OpenSearch plugins fail + run: echo "Failed to cache OpenSearch plugins. DIRECTORYY $HOME/.m2/repository/org/opensearch/plugin/performance-analyzer/${{ env.VERSION }}.0/ " + - name: Run `assemble.sh` run: | bash build-scripts/assemble.sh \ @@ -279,6 +299,20 @@ jobs: -d ${{ matrix.distribution }} \ -r ${{ inputs.revision }} + - name: Cache OpenSearch plugins POST + id: cache-opensearch-plugins-post + uses: actions/cache@v4 + with: + path: $HOME/.m2/repository/org/opensearch/plugin/performance-analyzer/${{ env.VERSION }}.0/ + key: ${{ runner.os }}-opensearch-${{ hashFiles('performance-analyzer**.xml') }} + restore-keys: | + ${{ runner.os }}-opensearch-performance-analyzer + + - if: ${{steps.cache-opensearch-plugins-post.cache-hit != 'true'}} + name: Cache OpenSearch plugins fail POST + run: | + ls $HOME/.m2/repository/org/opensearch/plugin/performance-analyzer/${{ env.VERSION }}.0/ >> $GITHUB_OUTPUT + - name: Test RPM package if: ${{ matrix.distribution == 'rpm' }} uses: addnab/docker-run-action@v3 diff --git a/build-scripts/assemble.sh b/build-scripts/assemble.sh index 154d12af1fa71..10cbb198c1034 100644 --- a/build-scripts/assemble.sh +++ b/build-scripts/assemble.sh @@ -227,8 +227,16 @@ function install_plugins() { echo "Installing OpenSearch plugins" local maven_repo_local="$HOME/.m2" for plugin in "${plugins[@]}"; do + echo "Plugin ${plugin}, version ${VERSION}" local plugin_from_maven="org.opensearch.plugin:${plugin}:${VERSION}.0" - mvn -Dmaven.repo.local="${maven_repo_local}" org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact="${plugin_from_maven}:zip" + + if [[ -f "${maven_repo_local}/org/opensearch/plugin/${plugin}/${VERSION}.0/${plugin}-${VERSION}.0.zip" ]]; then + echo "Plugin ${plugin} is already present, download omitted." + else + echo "Downloand ${plugin} plugin." + mvn -Dmaven.repo.local="${maven_repo_local}" org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact="${plugin_from_maven}:zip" + fi + OPENSEARCH_PATH_CONF=$PATH_CONF "${PATH_BIN}/opensearch-plugin" install --batch --verbose "file:${maven_repo_local}/org/opensearch/plugin/${plugin}/${VERSION}.0/${plugin}-${VERSION}.0.zip" done