centreon-plugins/.github/actions/rpm-delivery/action.yml

144 lines
4.4 KiB
YAML

name: "rpm-delivery"
description: "rpm delivery"
inputs:
module_name:
description: "The package module name"
required: true
distrib:
description: "The distribution used for packaging"
required: true
cache_key:
description: "The cached package key"
required: true
yum_repo_url:
description: "The legacy yum repo url"
required: true
update_repo_path:
description: "The update repo script path"
required: true
cloudfront_id:
description: "The cloudfront ID for repo url"
required: true
yum_repo_address:
description: "The legacy yum repo address"
required: true
yum_repo_key:
description: "The repo key"
required: true
stability:
description: "The package stability (stable, testing, unstable)"
required: true
artifactory_token:
description: "token for artifactory"
required: true
runs:
using: "composite"
steps:
- name: Use cache RPM files
uses: actions/cache@v3
with:
path: ./*.rpm
key: ${{ inputs.cache_key }}
- uses: jfrog/setup-jfrog-cli@v3
env:
JF_URL: https://centreon.jfrog.io
JF_ACCESS_TOKEN: ${{ inputs.artifactory_token }}
- name: Publish RPMs to plugins repository
run: |
FILES="*.rpm"
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
if [ -z "${{ inputs.module_name }}" ]; then
echo "module name is required"
exit 1
fi
if [ -z "${{ inputs.distrib }}" ]; then
echo "distrib is required"
exit 1
fi
mkdir noarch x86_64
for FILE in $FILES; do
echo "[DEBUG] - File: $FILE"
ARCH=$(echo $FILE | grep -oP '(x86_64|noarch)')
echo "[DEBUG] - Arch: $ARCH"
cp "$FILE" "$ARCH"
done
for ARCH in "noarch" "x86_64"; do
if [ "$(ls -A $ARCH)" ]; then
if [ "${{ inputs.stability }}" == "stable" ]; then
jf rt upload "$ARCH/*.rpm" "rpm-plugins/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/" --flat
else
jf rt upload "$ARCH/*.rpm" "rpm-plugins/${{ inputs.distrib }}/${{ inputs.stability }}/$ARCH/${{ inputs.module_name }}/" --flat
fi
fi
done
shell: bash
- name: Setup awscli
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo unzip -q awscliv2.zip
sudo ./aws/install
shell: bash
- name: Publish RPMs to standard repositories
run: |
FILES="*.rpm"
REPOTYPE="${{ inputs.stability }}"
PROJECT_PATH="standard"
DISTRIB="${{ inputs.distrib }}"
ARCH="noarch"
eval `ssh-agent`
ssh-add - <<< "${{ inputs.yum_repo_key }}"
for MAJOR in "21.10" "22.04" "22.10"; do
echo "::group::Delivering to $MAJOR $REPOTYPE"
if [ "$REPOTYPE" == "stable" ]; then
TARGET="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/RPMS"
else
TARGET="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/${{ inputs.module_name }}"
PROJECT_LOCATION="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/${{ inputs.module_name }}"
fi
echo "[DEBUG] - Target : $TARGET"
echo "[DEBUG] - PROJECT_LOCATION : $PROJECT_LOCATION"
ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" mkdir -p "$TARGET"
scp -o StrictHostKeyChecking=no ./*.rpm "${{ inputs.yum_repo_address }}:$TARGET"
# Update repository metadata
METADATAS="/srv/centreon-yum/yum.centreon.com/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH"
ssh -o StrictHostKeyChecking=no "${{ inputs.yum_repo_address }}" "sh "${{ inputs.update_repo_path }}" $METADATAS" 2>&-
# Invalidate cloudfront cache
ID="${{ inputs.cloudfront_id }}"
PATHS="/$PROJECT_PATH/$MAJOR/$DISTRIB/$REPOTYPE/$ARCH/*"
ITERATIONS=1
until aws cloudfront create-invalidation --distribution-id "$ID" --paths "$PATHS"; do
if [ ${ITERATIONS} -eq 10 ]; then
return 0
fi
echo "couldn't invalidate cache, AWS quota might have been reached, retrying in 30 seconds..."
sleep 30s
ITERATIONS=$((ITERATIONS+1))
done
echo "::endgroup::"
done
shell: bash