diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cde48f8..4cf4e91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,15 @@ image: python:slim variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + PACKAGE_VERSION: $CI_COMMIT_TAG + ADDON_PACKAGE: "malware_filter-${PACKAGE_VERSION}.tar.gz" + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${PACKAGE_VERSION}" + +stages: + - test + - build + - upload + - release lint: stage: test @@ -31,3 +40,27 @@ build: paths: - malware_filter-*.tar.gz expire_in: 30 days + +upload: + stage: upload + image: curlimages/curl:latest + rules: + - if: $CI_COMMIT_TAG + script: + - | + curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file ${ADDON_PACKAGE} ${PACKAGE_REGISTRY_URL}/${ADDON_PACKAGE} + +release_job: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + rules: + - if: $CI_COMMIT_TAG # Run this job when a tag is created manually + script: + - echo "Running the release job." + release: + tag_name: $CI_COMMIT_TAG + description: $CI_COMMIT_TAG + assets: + links: + - name: ${ADDON_PACKAGE} + url: "${PACKAGE_REGISTRY_URL}/${ADDON_PACKAGE}" diff --git a/build.py b/build.py index 4eb0da0..2386971 100644 --- a/build.py +++ b/build.py @@ -16,10 +16,20 @@ def version(): """ commit_sha = ( - # gitlab - environ.get("CI_COMMIT_SHORT_SHA") - # github - or environ.get("GITHUB_SHA", "")[0:8] + ( + # gitlab + environ.get("CI_COMMIT_TAG") + or environ.get("CI_COMMIT_SHORT_SHA") + # github + or ( + environ.get("GITHUB_REF_NAME") + if environ.get("GITHUB_REF_TYPE") == "tag" + else None + ) + or environ.get("GITHUB_SHA", "")[0:8] + ) + if environ.get("CI") == "true" + else None ) if commit_sha: return commit_sha