diff --git a/maven/await-artifact/README.md b/maven/await-artifact/README.md index 1fae5a45..3be9e3c9 100644 --- a/maven/await-artifact/README.md +++ b/maven/await-artifact/README.md @@ -4,19 +4,24 @@ [![test-maven-await-artifact](https://github.com/elastic/oblt-actions/actions/workflows/test-elastic-active-branches.yml/badge.svg?branch=main)](https://github.com/elastic/oblt-actions/actions/workflows/test-maven-await-artifact.yml) -Waits for an artifact to be available on maven central +Waits for an artifact to be available on maven central or the sonatype proxy maven central. +With default values, we just wait for the publication to complete on `sonatype`, but the actual availability in maven central might not be ready yet. +With `true`, we wait for the artifact to be published in maven central, this should be used when building other artifacts by downloading from maven central, which is for example quite common for docker images. NOTE: this action does not timeout, hence you need to configure your GitHub workflow accordingly. See https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes + ## Inputs -| Name | Description | Required | Default | -|---------------|-------------------------------------|----------|---------| -| `artifact-id` | Maven artifact-ID of the artifact | `true` | ` ` | -| `group-id` | Maven group-ID of the artifact | `true` | ` ` | -| `version` | Version of the artifact to wait for | `true` | ` ` | +| Name | Description | Required | Default | +|--------------------|--------------------------------------------------------------------------------------|----------|---------| +| `artifact-id` | Maven artifact-ID of the artifact | `true` | ` ` | +| `group-id` | Maven group-ID of the artifact | `true` | ` ` | +| `version` | Version of the artifact to wait for | `true` | ` ` | +| `sonatype-central` | Whether to wait for the artifact to be available in the sonatype central repository. | `false` | `true` | +| `maven-central` | Whether to wait for the artifact to be available in the maven central repository. | `false` | `false` | diff --git a/maven/await-artifact/action.yml b/maven/await-artifact/action.yml index 54d46928..dc9169cf 100644 --- a/maven/await-artifact/action.yml +++ b/maven/await-artifact/action.yml @@ -1,6 +1,8 @@ name: maven/await-artifact description: | - Waits for an artifact to be available on maven central + Waits for an artifact to be available on maven central or the sonatype proxy maven central. + With default values, we just wait for the publication to complete on `sonatype`, but the actual availability in maven central might not be ready yet. + With `true`, we wait for the artifact to be published in maven central, this should be used when building other artifacts by downloading from maven central, which is for example quite common for docker images. inputs: artifact-id: description: 'Maven artifact-ID of the artifact' @@ -11,17 +13,44 @@ inputs: version: description: 'Version of the artifact to wait for' required: true + sonatype-central: + description: 'Whether to wait for the artifact to be available in the sonatype central repository.' + default: true + required: false + maven-central: + description: 'Whether to wait for the artifact to be available in the maven central repository.' + default: false + required: false runs: using: "composite" steps: - - name: Wait for artifact to be available on maven central + - name: Wait for artifact to be available on proxy sonatype maven central + if: ${{ inputs.sonatype-central == 'true' }} shell: bash run: | + TIME=30 full_url="https://oss.sonatype.org/service/local/artifact/maven/redirect?r=releases&g=${GROUP_ID}&a=${ARTIFACT_ID}&v=${VERSION}" until curl -fs -I -L "${full_url}" > /dev/null do - echo "Artifact ${GROUP_ID}:${ARTIFACT_ID}:${VERSION} not found on maven central. Sleeping 30 seconds, retrying afterwards" - sleep 30s + echo "Artifact ${GROUP_ID}:${ARTIFACT_ID}:${VERSION} not found on proxy maven central. Sleeping ${WAIT_SECONDS} seconds, retrying afterwards" + sleep ${WAIT_SECONDS}s + done + env: + ARTIFACT_ID: ${{ inputs.artifact-id }} + GROUP_ID: ${{ inputs.group-id }} + VERSION: ${{ inputs.version }} + + - name: Wait for artifact to be available on maven central + if: ${{ inputs.maven-central == 'true' }} + shell: bash + run: | + TIME=30 + GROUP_FOLDER="${GROUP_ID//.//}" + full_url="https://repo.maven.apache.org/maven2/${GROUP_FOLDER}/${ARTIFACT_ID}/${VERSION}" + until curl -fs -I -L "${full_url}" > /dev/null + do + echo "Artifact ${GROUP_ID}:${ARTIFACT_ID}:${VERSION} not found on maven central. Sleeping ${WAIT_SECONDS} seconds, retrying afterwards" + sleep ${WAIT_SECONDS}s done env: ARTIFACT_ID: ${{ inputs.artifact-id }}