Skip to content

Commit

Permalink
test(ci): test token usage for delivery action
Browse files Browse the repository at this point in the history
  • Loading branch information
kduret committed Dec 5, 2024
1 parent 3227104 commit c00b004
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 235 deletions.
184 changes: 22 additions & 162 deletions .github/actions/package-delivery/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,88 +26,19 @@ inputs:
runs:
using: "composite"
steps:
- name: Validate inputs
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
if ('${{ inputs.module_name }}' === '') {
throw new Error('module_name input must be defined');
}
if (! ['stable', 'testing', 'unstable'].includes('${{ inputs.stability }}')) {
throw new Error(`Stability ${{ inputs.stability }} should not deliver packages`);
}
if ('${{ inputs.stability }}' === 'testing' && ! ['release', 'hotfix'].includes('${{ inputs.release_type }}')) {
throw new Error('release_type input must be defined when stability is testing');
}
- name: Parse distrib name
id: parse-distrib
uses: ./.github/actions/parse-distrib
with:
distrib: ${{ inputs.distrib }}

- name: Get repository stability path
id: get_repository_stability_path
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
let stabilitySubdirectory = '${{ inputs.stability }}';
if ('${{ inputs.stability }}' === 'testing' && '${{ inputs.release_type }}' === 'hotfix') {
stabilitySubdirectory = '${{ inputs.stability }}-${{ inputs.release_type }}';
}
let repositoryStabilityPath = '';
if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
repositoryStabilityPath = `rpm-plugins/${{ inputs.distrib }}/${stabilitySubdirectory}`;
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') {
repositoryStabilityPath = `ubuntu-plugins-${{ inputs.stability }}`;
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') {
repositoryStabilityPath = `apt-plugins-${{ inputs.stability }}`;
} else {
throw new Error(`Repository cannot be find for distribution: ${{ inputs.distrib }}`);
}
core.setOutput(
'repository_stability_path',
repositoryStabilityPath,
);
- if: ${{ inputs.stability != 'stable' }}
name: Restore packages from cache
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ./*.${{ steps.parse-distrib.outputs.package_extension }}
key: ${{ inputs.cache_key }}
fail-on-cache-miss: true

- uses: jfrog/setup-jfrog-cli@9fe0f98bd45b19e6e931d457f4e98f8f84461fb5 # v4.4.1
with:
disable-job-summary: true
disable-auto-build-publish: true
env:
JF_URL: https://centreon.jfrog.io
JF_ACCESS_TOKEN: ${{ inputs.artifactory_token }}

- if: ${{ inputs.stability == 'testing' }}
name: Clean existing testing packages
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
await exec.exec(
`jf rt del "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/*/${{ inputs.module_name }}/*.rpm" --exclusions "*/RPMS/*" --quiet`
);
} else if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'deb') {
await exec.exec(
`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 }}"`
);
}
- name: Check workflow statuses and display token usage
run: |
echo "github token rate usage:"
curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ github.token }}" https://api.github.com/rate_limit
echo ""
echo ""
echo "anonymous rate usage:"
curl -s -H "Accept: application/vnd.github+json" https://api.github.com/rate_limit
echo ""
echo ""
shell: bash

- name: Download packages from testing
if: ${{ inputs.stability == 'stable' && github.event_name == 'push' && inputs.distrib != 'jammy' }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
Expand All @@ -118,85 +49,14 @@ runs:
q: `${commitSha} type:pr is:merged`
});
if (items.length === 0) {
core.warning(warningNoPromote);
return;
}
const prNumber = items[0].number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const prBaseRef = pr.data?.base?.ref || 'unknown';
let releaseType = '';
switch (true) {
case /^release.+/.test(prBaseRef):
releaseType = 'release';
break;
case /^hotfix.+/.test(prBaseRef):
releaseType = 'hotfix';
break;
default:
core.warning(warningNoPromote);
return;
}
let fromStabilitySubdirectory = 'testing';
if (releaseType === 'hotfix' ) {
fromStabilitySubdirectory = `testing-${releaseType}`;
}
if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'el') {
await exec.exec(
`jf rt download "rpm-plugins/${{ inputs.distrib }}/${fromStabilitySubdirectory}/*/${{ inputs.module_name }}/*.rpm" --flat`
);
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') {
await exec.exec(
`jf rt download "ubuntu-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${{ inputs.release_type }}" --flat`
);
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') {
await exec.exec(
`jf rt download "apt-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${{ inputs.release_type }}" --flat`
);
}
- name: Publish packages to ${{ inputs.stability }}
if: |
contains(fromJson('["testing", "unstable"]'), inputs.stability) ||
(inputs.stability == 'stable' && github.event_name == 'push' && inputs.distrib != 'jammy')
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const path = require('path');
const globber = await glob.create('*.${{ steps.parse-distrib.outputs.package_extension }}');
const debTargetProps = '${{ inputs.stability }}' == 'testing' ? '--target-props "release_type=${{ inputs.release_type }}"' : '';
for await (const file of globber.globGenerator()) {
const fileName = path.basename(file);
if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'rpm') {
let arch = 'noarch';
if (/x86_64/.test(fileName)) {
arch = 'x86_64';
}
await exec.exec(
`jf rt upload "${fileName}" "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/${arch}/${{ inputs.module_name }}/" --flat`
);
} else if ('${{ steps.parse-distrib.outputs.package_extension }}' === 'deb') {
let arch = 'all';
const matches = fileName.match(/_([^_]+)\.deb/);
if (matches !== null && matches.length > 1) {
arch = matches[1];
}
if ('${{ inputs.arch }}' === '' || '${{ inputs.arch }}' === arch) {
await exec.exec(
`jf rt upload "${fileName}" "${{ steps.get_repository_stability_path.outputs.repository_stability_path }}/pool/${{ inputs.module_name }}/" --deb "${{ inputs.distrib }}/main/${arch}" ${debTargetProps} --flat`
);
}
}
}
- name: Check workflow statuses and display token usage
run: |
echo "github token rate usage:"
curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ github.token }}" https://api.github.com/rate_limit
echo ""
echo ""
echo "anonymous rate usage:"
curl -s -H "Accept: application/vnd.github+json" https://api.github.com/rate_limit
echo ""
echo ""
shell: bash
75 changes: 2 additions & 73 deletions .github/workflows/connector-vmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- 'connectors/vmware/src/**'
- 'connectors/vmware/packaging/**'
- '**'
push:
branches:
- develop
Expand All @@ -24,85 +23,15 @@ jobs:
with:
version_file: connectors/vmware/src/centreon/script/centreon_vmware.pm

package:
needs: [get-environment]
if: ${{ needs.get-environment.outputs.stability != 'stable' }}
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- package_extension: rpm
image: packaging-plugins-alma8
distrib: el8
- package_extension: rpm
image: packaging-plugins-alma9
distrib: el9
- package_extension: deb
image: packaging-plugins-bullseye
distrib: bullseye
- package_extension: deb
image: packaging-plugins-bookworm
distrib: bookworm
- package_extension: deb
image: packaging-plugins-jammy
distrib: jammy

container:
image: ${{ vars.DOCKER_INTERNAL_REGISTRY_URL }}/${{ matrix.image }}
credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}

name: package ${{ matrix.distrib }}

steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Package
uses: ./.github/actions/package-nfpm
with:
nfpm_file_pattern: "connectors/vmware/packaging/centreon-plugin-virtualization-vmware-daemon.yaml"
distrib: ${{ matrix.distrib }}
package_extension: ${{ matrix.package_extension }}
version: ${{ needs.get-environment.outputs.version }}
release: 1
commit_hash: ${{ github.sha }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
rpm_gpg_key: ${{ secrets.RPM_GPG_SIGNING_KEY }}
rpm_gpg_signing_key_id: ${{ secrets.RPM_GPG_SIGNING_KEY_ID }}
rpm_gpg_signing_passphrase: ${{ secrets.RPM_GPG_SIGNING_PASSPHRASE }}
stability: ${{ needs.get-environment.outputs.stability }}
- name: Upload apt/dnf packages as artifacts if asked
if: ${{ contains(github.event.pull_request.labels.*.name, 'upload-artifacts') }}
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: vmware-connector-daemon-${{ matrix.distrib }}
path: centreon-plugin*
retention-days: 1

deliver-packages:
needs: [get-environment, package]
if: |
(contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || ( needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
needs: [get-environment]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- distrib: el8
package_extension: rpm
- distrib: el9
package_extension: rpm
- distrib: bullseye
package_extension: deb
- distrib: bookworm
package_extension: deb
- distrib: jammy
package_extension: deb

name: deliver ${{ matrix.distrib }}
steps:
Expand Down

0 comments on commit c00b004

Please sign in to comment.