-
Notifications
You must be signed in to change notification settings - Fork 10
/
.gitlab-ci.yml
115 lines (109 loc) · 3.63 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
variables:
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/"
PACKAGE_NAME: "standalone-python"
# This is a magic request parameter to get the file attribute of the package,
# See: https://docs.gitlab.com/ee/user/packages/generic_packages/index.html#publish-a-package-file
GET_FILE_ATTR_MAGIC: "select=package_file"
stages:
- build
- generate_release_tag
- upload
- generate_release_note
- release
build:
stage: build
before_script:
- (sudo apt-get update -y && sudo apt-get install -y gzip) || true
script:
- docker build -t release-${PACKAGE_NAME}:${version}-${architecture} ./${version}/${architecture}/ 1>${version}-${architecture}.log 2>&1
- docker save release-${PACKAGE_NAME}:${version}-${architecture} > release-${version}-${architecture}.tar
- bash ci/packing_release_tar.sh release-${version}-${architecture}.tar
- gzip -9 build/release-${version}-${architecture}.tar
artifacts:
paths: ["build/release-${version}-${architecture}.tar.gz", "${version}-${architecture}.log"]
parallel:
matrix:
- version: ["3.12", "3.11", "3.10"]
architecture: ["x86_64", "x86"]
tags: [shell]
rules:
- if: $CI_COMMIT_TAG == null
generate_release_tag:
stage: generate_release_tag
script:
- echo release-$(date '+%Y-%m-%d') > .release_tag
- git config --global user.email "[email protected]"
- git config --global user.name "CI"
- git remote set-url origin "https://gitlab-ci-token:${GIT_TOKEN}@${CI_REPOSITORY_URL#*@}"
- (git tag $(cat .release_tag)) || true
- git push origin --tags
artifacts:
paths: [".release_tag"]
tags: [shell]
rules:
- if: $CI_COMMIT_TAG == null
upload:
stage: upload
needs: [build]
script:
- export PACKAGE_VERSION=$(date '+%Y-%m-%d')
- |
curl \
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file build/release-${version}-${architecture}.tar.gz \
"${PACKAGE_REGISTRY_URL}${PACKAGE_NAME}/${PACKAGE_VERSION}/release-${version}-${architecture}.tar.gz?${GET_FILE_ATTR_MAGIC}" >> ${version}-${architecture}-result.txt
parallel:
matrix:
- version: ["3.12", "3.11", "3.10"]
architecture: ["x86_64", "x86"]
artifacts:
paths: ["*-result.txt"]
tags: [shell]
rules:
- if: $CI_COMMIT_TAG == null
generate_release_note:
stage: generate_release_note
needs:
- job: upload
artifacts: true
- job: generate_release_tag
artifacts: true
before_script:
- (sudo apt-get update -y && sudo apt-get install jq -y) || true
script:
- |
export TAG_NAME="$(cat .release_tag)"
echo "TAG_NAME=${TAG_NAME}"
cat *-result.txt
for res in $(ls *-result.txt); do
url=$(cat $res | jq -r '.file.url')
echo && echo "url=${url}"
filename=$(echo "$url" | sed -n "s|.*\(release.*\).tar.gz|\1|p");
file_id=$(echo "$url" | sed -n 's/.*\/files\/\([0-9]\+\)\/.*/\1/p');
echo "- [🐍 $filename](/../../package_files/${file_id}/download)" >> generated_release_notes.txt
done
echo >> generated_release_notes.txt
artifacts:
paths: ["generated_release_notes.txt"]
tags: [shell]
rules:
- if: $CI_COMMIT_TAG == null
release:
stage: release
needs:
- job: generate_release_note
artifacts: true
- job: generate_release_tag
artifacts: true
image: registry.gitlab.com/gitlab-org/release-cli:latest
script:
- |
export TAG_NAME="$(cat .release_tag)"
echo "TAG_NAME=${TAG_NAME}"
- |
release-cli create --name "${PACKAGE_NAME}" \
--ref "${CI_COMMIT_REF_NAME}" \
--tag-name "${TAG_NAME}" \
--description generated_release_notes.txt
rules:
- if: $CI_COMMIT_TAG == null