-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
159 lines (138 loc) · 6.36 KB
/
Copy pathaction.yml
File metadata and controls
159 lines (138 loc) · 6.36 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: "deb-delivery"
description: "Package deb packages"
inputs:
module_name:
description: "The package module name"
required: true
distrib:
description: "The distribution used for packaging"
required: true
version:
description: "Centreon packaged major version"
required: true
cache_key:
description: "The cached package key"
required: true
stability:
description: "The package stability (stable, testing, unstable)"
required: true
artifactory_token:
description: "Artifactory token"
required: true
release_type:
description: "Type of release (hotfix, release)"
required: true
is_cloud:
description: "Release context (cloud or not cloud)"
required: true
runs:
using: "composite"
steps:
- name: Use cache DEB files
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ./*.deb
key: ${{ inputs.cache_key }}
fail-on-cache-miss: true
- uses: jfrog/setup-jfrog-cli@ff5cb544114ffc152db9cea1cd3d5978d5074946 # v4.5.11
env:
JF_URL: https://packages.centreon.com
JF_ACCESS_TOKEN: ${{ inputs.artifactory_token }}
- name: Parse distrib name
id: parse-distrib
uses: ./.github/actions/parse-distrib
with:
distrib: ${{ inputs.distrib }}
- name: Store list of restored DEB packages in text file
if: inputs.stability == 'testing'
shell: bash
run: |
ls ./*.deb > deb_packages.txt
- name: Publish DEBs
id: publish-debs
shell: bash
run: |
FILES="*.deb"
# DEBUG
echo "[DEBUG] - Version: ${{ inputs.version }}"
echo "[DEBUG] - Distrib: ${{ inputs.distrib }}"
echo "[DEBUG] - module_name: ${{ inputs.module_name }}"
echo "[DEBUG] - is_cloud: ${{ inputs.is_cloud }}"
echo "[DEBUG] - release_type: ${{ inputs.release_type }}"
echo "[DEBUG] - stability: ${{ inputs.stability }}"
# Make sure all required inputs are NOT empty
if [[ -z "${{ inputs.module_name }}" || -z "${{ inputs.distrib }}" || -z ${{ inputs.stability }} || -z ${{ inputs.version }} || -z "${{ inputs.is_cloud }}" ]]; then
echo "::error::some mandatory inputs are empty, please check the logs."
exit 1
fi
if [[ "${{ inputs.stability }}" != "testing" && "${{ inputs.stability }}" != "unstable" ]]; then
echo "::error::stability must be one of: testing, unstable (got '${{ inputs.stability }}')"
exit 1
fi
ROOT_REPO_PATH_PREFIX=""
if [[ "${{ steps.parse-distrib.outputs.distrib_family }}" == "debian" ]]; then
ROOT_REPO_PATH_PREFIX="apt-"
elif [[ "${{ steps.parse-distrib.outputs.distrib_family }}" == "ubuntu" ]]; then
ROOT_REPO_PATH_PREFIX="ubuntu-"
else
echo "::error::Unsupported distribution family: ${{ steps.parse-distrib.outputs.distrib_family }}"
exit 1
fi
ROOT_REPO_PATH_SUFFIX=""
if [[ "${{ inputs.is_cloud }}" == "true" ]]; then
ROOT_REPO_PATH_SUFFIX="-internal"
fi
ROOT_REPO_PATH="${ROOT_REPO_PATH_PREFIX}kdu${ROOT_REPO_PATH_SUFFIX}"
echo "root_repo_path=$ROOT_REPO_PATH" >> $GITHUB_OUTPUT
# Cleanup (equivalent to --sync-deletes done with RPMs)
# This is a workaround the fact that jfrog cli does not allow upload
# of multiple artifacts at once to an APT repository
# For each local artifact
for file in $FILES; do
# build a search pattern using ARTIFACT_BASENAME+OS_DISTRIB+ARCH
VERSION=${{ inputs.major_version }}
BASENAME=$(echo "$file" | cut -d '_' -f 1)
OS_DISTRIB=""
ARCH=$(echo $file | cut -d '_' -f3 | cut -d '.' -f1)
if [[ "${{ steps.parse-distrib.outputs.distrib_family }}" == "ubuntu" ]]; then
OS_DISTRIB=$(echo "$file" | sed -nE 's/.*(ubuntu\.[0-9]{2}\.[0-9]{2}).*/\1/p')
elif [[ "${{ steps.parse-distrib.outputs.distrib_family }}" == "debian" ]]; then
OS_DISTRIB=$(echo "$file" | sed -nE 's/.*(\+deb[0-9]+).*/\1/p')
else
echo "Distrib ${{ inputs.distrib }} is not supported as OS_DISTRIB."
fi
# debug
echo "[DEBUG] - Version: $VERSION"
echo "[DEBUG] - Basename: $BASENAME"
echo "[DEBUG] - OS_distrib: $OS_DISTRIB"
echo "[DEBUG] - Arch: $ARCH"
if [[ "${{ inputs.release_type }}" == "hotfix" || "${{ inputs.release_type }}" == "release" ]]; then
POOL_SUBPATH="${{ inputs.version }}/${{ inputs.stability }}/${{ inputs.release_type }}/${{ inputs.module_name }}"
DEB_PROP="${{ inputs.distrib }}-${{ inputs.version }}-${{ inputs.stability }}-${{ inputs.release_type }}/main/$ARCH"
else
POOL_SUBPATH="${{ inputs.version }}/${{ inputs.stability }}/${{ inputs.module_name }}"
DEB_PROP="${{ inputs.distrib }}-${{ inputs.version }}-${{ inputs.stability }}/main/$ARCH"
fi
SEARCH_PATH="$ROOT_REPO_PATH/pool/${POOL_SUBPATH}/${BASENAME}_*${OS_DISTRIB}*${ARCH}*.deb"
# search and delete all remote artifacts matching this pattern
echo "Searching and deleting $SEARCH_PATH"
jf rt delete "$SEARCH_PATH"
# upload local artifact
echo "Uploading $file"
jf rt upload "$file" "$ROOT_REPO_PATH/pool/${POOL_SUBPATH}/" --flat --deb "${DEB_PROP}" --detailed-summary
done
curl -H "Authorization: Bearer ${{ inputs.artifactory_token }}" -X POST "https://centreon.jfrog.io/artifactory/api/deb/reindex/$ROOT_REPO_PATH?async=0"
- name: Compare list of files with delivered files
if: inputs.stability == 'testing'
shell: bash
run: |
DELIVERED_PACKAGES=$(jf rt search "${{ steps.publish-debs.outputs.root_repo_path }}/pool/${{ inputs.version }}/${{ inputs.stability }}/${{ inputs.release_type }}/${{ inputs.module_name }}/*.deb" | jq -r '.[].path | split("/") | last')
ORIGINAL_PACKAGES=$(cat deb_packages.txt)
MISSING_PACKAGES=0
for PACKAGE in $ORIGINAL_PACKAGES; do
if ! echo "$DELIVERED_PACKAGES" | grep -q "$(basename "$PACKAGE")"; then
echo "::error::[${{ github.job }}] Package $PACKAGE was not successfully delivered or found in repository."
MISSING_PACKAGES=1
fi
done
[[ $MISSING_PACKAGES -eq 0 ]] || exit 1