Ming Di Leom 2023-01-27 11:05:34 +00:00
parent 22d1b7e8f5
commit 391fa177f6
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 47 additions and 4 deletions

View File

@ -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}"

View File

@ -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