Skip to content
Snippets Groups Projects

Add CI/CD pipeline to build and deploy package

Merged Matthew K Defenderfer requested to merge mdefende/gpfs-policy:enh-add-cicd into main
3 files
+ 91
31
Compare changes
  • Side-by-side
  • Inline
Files
3
.gitlab-ci.yml 0 → 100644
+ 50
0
default:
image: python:3.12
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PIP_INDEX_URL: "https://__token__:${CI_JOB_TOKEN}@gitlab.com/api/v4/projects/$CI_PROJECT_ID/packages/pypi/simple"
PIP_EXTRA_INDEX_URL: "https://pypi.org/simple"
REPO_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
PACKAGE_NAME: "rc-gpfs"
stages:
- release
- cleanup
release:
stage: release
only:
- main
- tags
before_script:
- python3 --version ; python3 -m pip --version # For debugging
- pip install --upgrade pip
- pip install poetry
- poetry self add "poetry-dynamic-versioning[plugin]"
- poetry install
script:
- export POETRY_DYNAMIC_VERSIONING_DEBUG=1
- export VERSION=$(poetry version -s) # Get version from poetry
- echo "Creating release for version $VERSION"
- poetry config repositories.gitlab ${REPO_URL}
- poetry publish --username gitlab-ci-token --password ${CI_JOB_TOKEN} --repository gitlab --build
cleanup_old_packages:
stage: cleanup
script:
- echo "Fetching package versions..."
- |
PACKAGE_VERSIONS=$(curl --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages?package_name=${PACKAGE_NAME}" | jq -r '.[].version')
echo "All versions: $PACKAGE_VERSIONS"
- |
VERSIONS_TO_DELETE=$(echo "$PACKAGE_VERSIONS" | sort -r | tail -n +3)
echo "Versions to delete: $VERSIONS_TO_DELETE"
- |
for VERSION in $VERSIONS_TO_DELETE; do
echo "Deleting version $VERSION..."
curl --request DELETE --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "${REPO_URL}/${PACKAGE_NAME}/$VERSION"
done
only:
- schedules
Loading