Debian Codegraph @

.github/actions/package-delivery/action.yml

raw
1 name: "package-delivery"
2 description: "Deliver packages"
3 inputs:
4 module_name:
5 description: "The package module name"
6 required: true
7 distrib:
8 description: "The distribution used for packaging"
9 required: true
10 arch:
11 description: "The target distribution architecture"
12 required: false
13 cache_key:
14 description: "The cached package key"
15 required: true
16 stability:
17 description: "The package stability (stable, testing, unstable)"
18 required: true
19 release_type:
20 description: "Type of release (hotfix, release)"
21 required: true
22 artifactory_token:
23 description: "token for artifactory"
24 required: true
25
26 runs:
27 using: "composite"
28 steps:
29 - name: Validate inputs
30 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
31 with:
32 script: |
33 if ('${{ inputs.module_name }}' === '') {
34 throw new Error('module_name input must be defined');
35 }
36
37 if (! ['stable', 'testing', 'unstable'].includes('${{ inputs.stability }}')) {
38 throw new Error(`Stability ${{ inputs.stability }} should not deliver packages`);
39 }
40
41 if ('${{ inputs.stability }}' === 'testing' && ! ['release', 'hotfix'].includes('${{ inputs.release_type }}')) {
42 throw new Error('release_type input must be defined when stability is testing');
43 }
44
45 - name: Parse distrib name
46 id: parse-distrib
47 uses: ./.github/actions/parse-distrib
48 with:
49 distrib: ${{ inputs.distrib }}
50
51 - name: Get repository stability path
52 id: get_repository_stability_path
53 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
54 with:
55 script: |
56 let stabilitySubdirectory = '${{ inputs.stability }}';
57
58 if ('${{ inputs.stability }}' === 'testing' && '${{ inputs.release_type }}' === 'hotfix') {
59 stabilitySubdirectory = '${{ inputs.stability }}-${{ inputs.release_type }}';
60 }
61
62 let repositoryStabilityPath = '';
63 if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
64 repositoryStabilityPath = `rpm-plugins/${{ inputs.distrib }}/${stabilitySubdirectory}`;
65 } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') {
66 repositoryStabilityPath = `ubuntu-plugins-${{ inputs.stability }}`;
67 } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') {
68 repositoryStabilityPath = `apt-plugins-${{ inputs.stability }}`;
69 } else {
70 throw new Error(`Repository cannot be find for distribution: ${{ inputs.distrib }}`);
71 }
72
73 core.setOutput(
74 'repository_stability_path',
75 repositoryStabilityPath,
76 );
77
78 - if: ${{ inputs.stability != 'stable' }}
79 name: Restore packages from cache
80 uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
81 with:
82 path: ./*.${{ steps.parse-distrib.outputs.package_extension }}
83 key: ${{ inputs.cache_key }}
84 fail-on-cache-miss: true
85
86 - uses: jfrog/setup-jfrog-cli@9fe0f98bd45b19e6e931d457f4e98f8f84461fb5 # v4.4.1
87 with:
88 disable-job-summary: true
89 disable-auto-build-publish: true
90 env:
91 JF_URL: https://centreon.jfrog.io
92 JF_ACCESS_TOKEN: ${{ inputs.artifactory_token }}
93
94 - if: ${{ inputs.stability == 'testing' }}
95 name: Clean existing testing packages
96 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
97 with:
98 script: |
99 if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
100 await exec.exec(
101 `jf rt del "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/*/${{ inputs.module_name }}/*.rpm" --exclusions "*/RPMS/*" --quiet`
102 );
103 } else if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'deb') {
104 await exec.exec(
105 `jf rt del "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --quiet --props "release_type=${{ inputs.release_type }}"`
106 );
107 }
108
109 - name: Download packages from testing
110 if: ${{ inputs.stability == 'stable' && github.event_name == 'push' && inputs.distrib != 'jammy' }}
111 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
112 with:
113 script: |
114 const commitSha = context.sha;
115
116 const pulls = await github.rest.pulls.list({
117 owner: context.repo.owner,
118 repo: context.repo.repo,
119 sort: 'updated',
120 direction: 'desc',
121 state: 'closed',
122 per_page: 100
123 });
124
125 core.startGroup(`Checking pull request linked to commit ${commitSha}`);
126 const pr = pulls.data.find(p => {
127 console.log(`Checking pull request ${p.number}("${p.title}") with merge commit ${p.merge_commit_sha}`);
128 return p.merge_commit_sha === commitSha;
129 });
130 core.endGroup();
131 if (!pr) {
132 core.error(`No pull request found for merge commit ${commitSha}`);
133 return;
134 }
135
136 const prHeadRef = pr?.head?.ref || 'unknown';
137 let releaseType = '';
138 switch (true) {
139 case /^release.+/.test(prHeadRef):
140 releaseType = 'release';
141 break;
142 case /^hotfix.+/.test(prHeadRef):
143 releaseType = 'hotfix';
144 break;
145 default:
146 core.error(`No packages are promoted because push of branch ${prHeadRef} is not related to a hotfix/release pull request.`);
147 return;
148 }
149 console.log(`Release type: ${releaseType}`);
150
151 let fromStabilitySubdirectory = 'testing';
152 if (releaseType === 'hotfix' ) {
153 fromStabilitySubdirectory = `testing-${releaseType}`;
154 }
155
156 if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
157 await exec.exec(
158 `jf rt download "rpm-plugins/${{ inputs.distrib }}/${fromStabilitySubdirectory}/*/${{ inputs.module_name }}/*.rpm" --flat`
159 );
160 } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') {
161 await exec.exec(
162 `jf rt download "ubuntu-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${releaseType}" --flat`
163 );
164 } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') {
165 await exec.exec(
166 `jf rt download "apt-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${releaseType}" --flat`
167 );
168 }
169
170 - name: Publish packages to ${{ inputs.stability }}
171 if: |
172 contains(fromJson('["testing", "unstable"]'), inputs.stability) ||
173 (inputs.stability == 'stable' && github.event_name == 'push' && inputs.distrib != 'jammy')
174 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
175 with:
176 script: |
177 const path = require('path');
178 const globber = await glob.create('*.${{ steps.parse-distrib.outputs.package_extension }}');
179
180 let stableRpmSubdirectory = '';
181 if ('${{ inputs.stability }}' === 'stable') {
182 stableRpmSubdirectory = 'RPMS/';
183 }
184
185 const debTargetProps = '${{ inputs.stability }}' == 'testing' ? '--target-props "release_type=${{ inputs.release_type }}"' : '';
186
187 for await (const file of globber.globGenerator()) {
188 const fileName = path.basename(file);
189
190 if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'rpm') {
191 let arch = 'noarch';
192 if (/x86_64/.test(fileName)) {
193 arch = 'x86_64';
194 }
195 await exec.exec(
196 `jf rt upload "${fileName}" "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/${arch}/${stableRpmSubdirectory}${{ inputs.module_name }}/" --flat`
197 );
198 } else if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'deb') {
199 let arch = 'all';
200 const matches = fileName.match(/_([^_]+)\.deb/);
201 if (matches !== null && matches.length > 1) {
202 arch = matches[1];
203 }
204 if ('${{ inputs.arch }}' === '' || '${{ inputs.arch }}' === arch) {
205 await exec.exec(
206 `jf rt upload "${fileName}" "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/pool/${{ inputs.module_name }}/" --deb "${{ inputs.distrib }}/main/${arch}" ${debTargetProps} --flat`
207 );
208 }
209 }
210 }