Skip to content
Snippets Groups Projects
Commit ea736249 authored by Matthew K Defenderfer's avatar Matthew K Defenderfer
Browse files

update the CI to hopefully improve readability for new users

parent d4d8d955
No related branches found
No related tags found
No related merge requests found
Pipeline #12067 failed with stages
in 3 minutes and 26 seconds
default:
image: python:3.12-slim
.install_dependencies:
before_script:
- pip install --upgrade pip
- pip install setuptools wheel build twine
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_COMMIT_BRANCH == "main"'
variables:
PACKAGE_NAME: "pak"
REPO_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
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"
stages:
- build
- test
- publish
variables:
PACKAGE_NAME: "pak"
build_package:
stage: build
extends: .install_dependencies
script:
- pip install --upgrade pip
- pip install setuptools wheel build
- python -m build
artifacts:
paths:
- dist/*
cache:
paths:
- ${PIP_CACHE_DIR}
test_package:
stage: test
script:
- pip install . # Install the package
- pip install .
- pip install pytest
- pytest # Run tests
- pytest
publish_pip:
stage: publish
extends: .install_dependencies
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"
script:
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
- pip install twine
- twine upload -u gitlab-ci-token -p ${CI_JOB_TOKEN} --repository-url ${REPO_URL} dist/*
build_and_push_docker_image:
stage: publish
image: docker:26.0.1
image: docker:latest
services:
- docker:26.0.1-dind
- docker:dind
variables:
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE/$PACKAGE_NAME:$CI_COMMIT_REF_SLUG
DOCKER_IMAGE_NAME: ${CI_REGISTRY_IMAGE}/${PACKAGE_NAME}
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- echo "${CI_REGISTRY_PASSWORD}" | docker login -u "${CI_REGISTRY_USER}" --password-stdin ${CI_REGISTRY}
script:
- docker build --pull -t "$DOCKER_IMAGE_NAME" .
- docker push "$DOCKER_IMAGE_NAME"
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest"
docker push "$CI_REGISTRY_IMAGE:latest"
fi
only:
- main # Only run on the main branch
- echo "Building docker image and tagging as latest"
- docker pull ${DOCKER_IMAGE_NAME}:latest || true
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ${DOCKER_IMAGE_NAME}:latest -t ${DOCKER_IMAGE_NAME}:latest .
- docker push ${DOCKER_IMAGE_NAME}:latest
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment