Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: trigger GitLab deployment pipeline when pushing #186

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
command: |
poetry config virtualenvs.in-project true
poetry install
- run:
name: Save commit hash in a file
command: echo $CIRCLE_SHA1 > .git-commit
- save_cache:
key: << pipeline.parameters.cache-prefix >>-{{ arch }}-{{ checksum "poetry.lock" }}
paths:
Expand Down Expand Up @@ -85,27 +88,33 @@ jobs:
- attach_workspace:
at: .
- run:
name: Build a distributable package
name: Set the version number
command: |
# Set the version
if [[ $CIRCLE_TAG ]]; then
export VERSION=$CIRCLE_TAG
export PACKAGE_VERSION=$CIRCLE_TAG
elif [[ $CIRCLE_BRANCH == << pipeline.parameters.publish-branch >> ]]; then
# for main branches, can't add the commit hash since it's not a valid format for publishing
export VERSION=$(poetry version -s)$CIRCLE_BUILD_NUM
export PACKAGE_VERSION=$(poetry version -s)$CIRCLE_BUILD_NUM
else
# for feature branches, add the commit hash
export VERSION=$(poetry version -s)$CIRCLE_BUILD_NUM+${CIRCLE_SHA1:0:7}
export PACKAGE_VERSION=$(poetry version -s)$CIRCLE_BUILD_NUM+${CIRCLE_SHA1:0:7}
fi
# Display some debug info
echo "Building a wheel release with version $VERSION, build number: $CIRCLE_BUILD_NUM, commit hash: ${CIRCLE_SHA1:0:7}, tag: $CIRCLE_TAG."
echo "Building a wheel release with version $PACKAGE_VERSION, build number: $CIRCLE_BUILD_NUM, commit hash: ${CIRCLE_SHA1:0:7}, tag: $CIRCLE_TAG."
# Save the version number in a file
echo "export PACKAGE_VERSION=\"$PACKAGE_VERSION\"" >> .env_vars
- run:
name: Build a distributable package
command: |
# Get the version number
source .env_vars
# Build a wheel release
if [[ $CIRCLE_TAG ]]; then
# This is a tagged release, version has been handled upstream
poetry build
else
# Relies on a dev version like "1.2.1.dev" by default
poetry version $VERSION
poetry version $PACKAGE_VERSION
poetry build
fi
- store_artifacts:
Expand All @@ -126,6 +135,22 @@ jobs:
command: |
poetry publish --username "${PYPI_USERNAME}" --password "${PYPI_PASSWORD}" --no-interaction

deploy:
docker:
- image: cimg/python:<< pipeline.parameters.python-version >>
steps:
- attach_workspace:
at: .
- run:
name: Create a GitLab CI pipeline for deploying
command: | # https://docs.gitlab.com/ee/api/pipeline_triggers.html
source .env_vars
echo "Create a GitLab CI pipeline for deploying Hydra version $PACKAGE_VERSION on dev with tag light..."
curl --request POST \
--header "PRIVATE-TOKEN: ${GITLAB_PRIVATE_TOKEN}" \
--data '{ "ref": "main", "variables": [{"key": "SITE", "value": "dev" }, {"key": "APP", "value": "hydra"}, {"key": "TAGS", "value": "light" }, {"key": "PACKAGE_VERSION", "value": "$PACKAGE_VERSION" }] }' \
https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/pipeline

workflows:
build:
jobs:
Expand Down Expand Up @@ -164,3 +189,13 @@ workflows:
tags:
only: /v[0-9]+(\.[0-9]+)*/
context: org-global
- deploy:
requires:
- publish
filters:
branches:
only:
- main
tags:
only: /v[0-9]+(\.[0-9]+)*/
context: org-global
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- Add a `quiet` argument for `purge_check` and `purge_csv_table` CLIs [#184](https://github.com/datagouv/hydra/pull/184)
- Fix wrong resource status [#187](https://github.com/datagouv/hydra/pull/187)
- More informative error relative to check resource CLI [#188](https://github.com/datagouv/hydra/pull/188)
- Trigger GitLab deployment in CI when pushing on `main` [#186](https://github.com/datagouv/hydra/pull/186)

## 2.0.0 (2024-09-24)

Expand Down