Skip to content

Commit

Permalink
AAE-7305 add action to auto promote Nexus staging repository (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemedeiros committed Jan 4, 2023
1 parent 120f6bb commit 3a9243f
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 1 deletion.
83 changes: 83 additions & 0 deletions .github/actions/nexus-close-staging/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Close Nexus staging repository
description: Close a Nexus Staging Repository
inputs:
wait-for-completion:
description: Whether the action should wait for the closure to complete before returning
required: false
default: 'true'
max-await-attempts:
description: Max attempts while waiting for the repository to close
required: false
default: '12'
await-sleep-time:
description: Time in seconds between two attempts to verify if the staging repository has been closed
required: false
default: '5'
version:
description: Version being released. Used to update the repository description while closing the staging repository
required: true
staging-repository:
description: The id of the staging repository to be closed
required: true
nexus-username:
description: The Nexus username
required: true
nexus-password:
description: The Nexus password
required: true
nexus-url:
description: The base URL to the Nexus server
required: false
default: "https://artifacts.alfresco.com/nexus"
runs:
using: composite
steps:
- name: Close staging repository
shell: bash
env:
WAIT_FOR_COMPLETION: ${{ inputs.wait-for-completion }}
MAX_AWAIT_ATTEMPTS: ${{ inputs.max-await-attempts }}
AWAIT_SLEEP_TIME: ${{ inputs.await-sleep-time }}
NEXUS_USERNAME: ${{ inputs.nexus-username }}
NEXUS_PASSWORD: ${{ inputs.nexus-password }}
NEXUS_URL: ${{ inputs.nexus-url }}
VERSION: ${{ inputs.version }}
STAGING_REPOSITORY_ID: ${{ inputs.staging-repository }}
run: |
CLOSE_STAGING_PAYLOAD_CONTENT=$(envsubst < $GITHUB_ACTION_PATH/close-payload-template.json)
curl -f -u "${NEXUS_USERNAME}":"${NEXUS_PASSWORD}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "$CLOSE_STAGING_PAYLOAD_CONTENT" \
"${NEXUS_URL}"/service/local/staging/bulk/close
wait_until_true () {
local attempt_counter=0
until "$@"
do
if [ ${attempt_counter} -eq ${MAX_AWAIT_ATTEMPTS} ]
then
echo "Max attempts reached. Exiting..."
exit 1
fi
attempt_counter=$((attempt_counter+1))
echo "Condition not reached yet. Attempt $attempt_counter out of $MAX_AWAIT_ATTEMPTS. Retrying..."
sleep $AWAIT_SLEEP_TIME
done
}
staging_repo_is_closed () {
curl -f -u "${NEXUS_USERNAME}":"${NEXUS_PASSWORD}" \
-X GET "${NEXUS_URL}"/service/local/staging/profile_repositories \
| yq -p=xml e '.stagingRepositories.data.stagingProfileRepository[]| select (.repositoryId == env(STAGING_REPOSITORY_ID)) | .type ' \
| grep closed > /dev/null 2>&1
}
if [[ "$WAIT_FOR_COMPLETION" == "true" ]]
then
echo "Waiting for staging repository $STAGING_REPOSITORY_ID to get closed.
MAX_AWAIT_ATTEMPTS: $MAX_AWAIT_ATTEMPTS, AWAIT_SLEEP_TIME: $AWAIT_SLEEP_TIME ..."
wait_until_true staging_repo_is_closed
echo "Repository $STAGING_REPOSITORY_ID successfully closed!"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"data": {
"description": "Closing $VERSION",
"stagedRepositoryIds": [
"$STAGING_REPOSITORY_ID"
]
}
}
2 changes: 1 addition & 1 deletion .github/actions/nexus-create-staging/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ runs:
run: |
echo "Checking repository to be used for $STAGING_DESCRIPTION"
NEXUS_STAGING_REPOSITORY=$(curl -u "${NEXUS_USERNAME}":"${NEXUS_PASSWORD}" \
-X GET https://artifacts.alfresco.com/nexus/service/local/staging/profile_repositories \
-X GET "${NEXUS_URL}"/service/local/staging/profile_repositories \
| yq -p=xml e '.stagingRepositories.data.stagingProfileRepository[]| select (.description == env(STAGING_DESCRIPTION)) | .repositoryId')
if [ -z "$NEXUS_STAGING_REPOSITORY" ];
Expand Down
78 changes: 78 additions & 0 deletions .github/actions/nexus-release-staging/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Release Nexus staging repository
description: Release a Nexus Staging Repository. The stage repository should be in the closed status.
inputs:
wait-for-completion:
description: Whether the action should wait for the release to complete before returning
required: false
default: 'true'
max-await-attempts:
description: Max attempts while waiting for the repository to release
required: false
default: '12'
await-sleep-time:
description: Time in seconds between two attempts to verify if the staging repository has been released
required: false
default: '5'
version:
description: Version being released. Used to update the repository description while closing and releasing
required: true
staging-repository:
description: The id of the staging repository to be promoted
required: true
nexus-username:
description: The Nexus username
required: true
nexus-password:
description: The Nexus password
required: true
nexus-url:
description: The base URL to the Nexus server
required: false
default: "https://artifacts.alfresco.com/nexus"
runs:
using: composite
steps:
- name: Release staging repository
shell: bash
env:
WAIT_FOR_COMPLETION: ${{ inputs.wait-for-completion }}
MAX_AWAIT_ATTEMPTS: ${{ inputs.max-await-attempts }}
AWAIT_SLEEP_TIME: ${{ inputs.await-sleep-time }}
NEXUS_USERNAME: ${{ inputs.nexus-username }}
NEXUS_PASSWORD: ${{ inputs.nexus-password }}
NEXUS_URL: ${{ inputs.nexus-url }}
VERSION: ${{ inputs.version }}
STAGING_REPOSITORY_ID: ${{ inputs.staging-repository }}
run: |
PROMOTE_PAYLOAD_CONTENT=$(envsubst < $GITHUB_ACTION_PATH/promote-payload-template.json)
curl -f -u "${NEXUS_USERNAME}":"${NEXUS_PASSWORD}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "$PROMOTE_PAYLOAD_CONTENT" \
"${NEXUS_URL}"/service/local/staging/bulk/promote
wait_until_released () {
local attempt_counter=0
until [ -z "$(curl -f -u "${NEXUS_USERNAME}":"${NEXUS_PASSWORD}" \
-X GET "${NEXUS_URL}"/service/local/staging/profile_repositories \
| yq -p=xml e '.stagingRepositories.data.stagingProfileRepository[]| select (.repositoryId == env(STAGING_REPOSITORY_ID))')" ]
do
if [ ${attempt_counter} -eq ${MAX_AWAIT_ATTEMPTS} ]
then
echo "Max attempts reached. Exiting..."
exit 1
fi
attempt_counter=$((attempt_counter+1))
echo "Condition not reached yet. Attempt $attempt_counter out of $MAX_AWAIT_ATTEMPTS. Retrying..."
sleep $AWAIT_SLEEP_TIME
done
}
if [[ "$WAIT_FOR_COMPLETION" == "true" ]]
then
echo "Waiting for staging repository $STAGING_REPOSITORY_ID to get released.
MAX_AWAIT_ATTEMPTS: $MAX_AWAIT_ATTEMPTS, AWAIT_SLEEP_TIME: $AWAIT_SLEEP_TIME ..."
wait_until_released
echo "Repository $STAGING_REPOSITORY_ID successfully released!"
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"data": {
"autoDropAfterRelease": true,
"description": "Releasing $VERSION",
"stagedRepositoryIds": [
"$STAGING_REPOSITORY_ID"
]
}
}
28 changes: 28 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Here follows the list of GitHub Actions topics available in the current document
- [maven-release](#maven-release)
- [maven-update-pom-version](#maven-update-pom-version)
- [nexus-create-staging](#nexus-create-staging)
- [nexus-close-staging](#nexus-close-staging)
- [nexus-release-staging](#nexus-release-staging)
- [pre-commit](#pre-commit)
- [pre-commit-default](#pre-commit-default)
- [rancher](#rancher)
Expand Down Expand Up @@ -636,6 +638,32 @@ The resulting staging repository will be available in the output named `staging-
nexus-password: "${{ secrets.NEXUS_PASSWORD }}"
```

### nexus-close-staging

Closes the specified staging repository on Nexus.

```yaml
- uses: Alfresco/alfresco-build-tools/.github/actions/nexus-close-staging@ref
with:
version: ${{ inputs.version }}
staging-repository: ${{ inputs.staging-repository}}
nexus-username: ${{ secrets.NEXUS_USERNAME }}
nexus-password: ${{ secrets.NEXUS_PASSWORD }}
```

### nexus-release-staging

Releases the specified staging repository on Nexus. The repository should be in the closed status before.

```yaml
- uses: Alfresco/alfresco-build-tools/.github/actions/nexus-release-staging@ref
with:
version: ${{ inputs.version }}
staging-repository: ${{ inputs.staging-repository}}
nexus-username: ${{ secrets.NEXUS_USERNAME }}
nexus-password: ${{ secrets.NEXUS_PASSWORD }}
```

### pre-commit

Executes a pre-commit step.
Expand Down

0 comments on commit 3a9243f

Please sign in to comment.