fix(ci): fix release/hotfix pr detection (#5325)

This commit is contained in:
Kevin Duret 2024-12-09 14:33:28 +01:00 committed by GitHub
parent 14b098cb43
commit bf2609c709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 26 deletions

View File

@ -111,7 +111,6 @@ runs:
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with: with:
script: | script: |
const warningNoPromote = 'No packages are promoted because push is not related to a hotfix/release pull request.';
const commitSha = context.sha; const commitSha = context.sha;
const pulls = await github.rest.pulls.list({ const pulls = await github.rest.pulls.list({
@ -123,25 +122,31 @@ runs:
per_page: 100 per_page: 100
}); });
const pr = pulls.data.find(p => p.merge_commit_sha === commitSha); core.startGroup(`Checking pull request linked to commit ${commitSha}`);
const pr = pulls.data.find(p => {
console.log(`Checking pull request ${p.number}("${p.title}") with merge commit ${p.merge_commit_sha}`);
return p.merge_commit_sha === commitSha;
});
core.endGroup();
if (!pr) { if (!pr) {
core.warning(warningNoPromote); core.error(`No pull request found for merge commit ${commitSha}`);
return; return;
} }
const prBaseRef = pr?.base?.ref || 'unknown'; const prHeadRef = pr?.head?.ref || 'unknown';
let releaseType = ''; let releaseType = '';
switch (true) { switch (true) {
case /^release.+/.test(prBaseRef): case /^release.+/.test(prHeadRef):
releaseType = 'release'; releaseType = 'release';
break; break;
case /^hotfix.+/.test(prBaseRef): case /^hotfix.+/.test(prHeadRef):
releaseType = 'hotfix'; releaseType = 'hotfix';
break; break;
default: default:
core.warning(warningNoPromote); core.error(`No packages are promoted because push of branch ${prHeadRef} is not related to a hotfix/release pull request.`);
return; return;
} }
console.log(`Release type: ${releaseType}`);
let fromStabilitySubdirectory = 'testing'; let fromStabilitySubdirectory = 'testing';
if (releaseType === 'hotfix' ) { if (releaseType === 'hotfix' ) {
@ -154,11 +159,11 @@ runs:
); );
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') { } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'ubuntu') {
await exec.exec( 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` `jf rt download "ubuntu-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${releaseType}" --flat`
); );
} else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') { } else if ('${{ steps.parse-distrib.outputs.distrib_family }}' === 'debian') {
await exec.exec( 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` `jf rt download "apt-plugins-testing/pool/${{ inputs.module_name }}/*${{ steps.parse-distrib.outputs.package_distrib_name }}*.deb" --props "release_type=${releaseType}" --flat`
); );
} }

View File

@ -29,11 +29,11 @@ jobs:
uses: ./.github/workflows/get-environment.yml uses: ./.github/workflows/get-environment.yml
get-plugins: get-plugins:
runs-on: ubuntu-22.04 runs-on: ubuntu-24.04
outputs: outputs:
plugins: ${{ steps.get_plugins.outputs.plugins }} plugins: ${{ steps.get_plugins.outputs.plugins }}
steps: steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with: with:
fetch-depth: 0 fetch-depth: 0
@ -89,12 +89,17 @@ jobs:
unit-tests: unit-tests:
needs: [get-environment, get-plugins] needs: [get-environment, get-plugins]
if: |
needs.get-environment.outputs.stability != 'stable' &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
image: [unit-tests-alma8, unit-tests-alma9, unit-tests-bullseye, unit-tests-bullseye-arm64, unit-tests-bookworm, unit-tests-jammy] image: [unit-tests-alma8, unit-tests-alma9, unit-tests-bullseye, unit-tests-bullseye-arm64, unit-tests-bookworm, unit-tests-jammy]
include: include:
- runner_name: ubuntu-22.04 - runner_name: ubuntu-24.04
- package_extension: rpm - package_extension: rpm
image: unit-tests-alma8 image: unit-tests-alma8
distrib: el8 distrib: el8
@ -121,9 +126,10 @@ jobs:
credentials: credentials:
username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }} username: ${{ secrets.HARBOR_CENTREON_PULL_USERNAME }}
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }} password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run unit tests - name: Run unit tests
uses: ./.github/actions/unit-tests uses: ./.github/actions/unit-tests
@ -137,14 +143,16 @@ jobs:
retention-days: 1 retention-days: 1
fatpacker: fatpacker:
if: ${{ needs.get-plugins.outputs.plugins != '' }}
needs: [get-environment, get-plugins, unit-tests] needs: [get-environment, get-plugins, unit-tests]
runs-on: ubuntu-22.04 if: |
needs.get-plugins.outputs.plugins != '' &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
runs-on: ubuntu-24.04
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- name: Prepare FatPacker - name: Prepare FatPacker
uses: shogo82148/actions-setup-perl@9c1eca9952ccc07f9ca4a2097b63df93d9d138e9 # v1.31.3 uses: shogo82148/actions-setup-perl@9c1eca9952ccc07f9ca4a2097b63df93d9d138e9 # v1.31.3
@ -166,6 +174,12 @@ jobs:
package: package:
runs-on: ubuntu-24.04 runs-on: ubuntu-24.04
needs: [get-environment, get-plugins, fatpacker] needs: [get-environment, get-plugins, fatpacker]
if: |
needs.get-plugins.outputs.plugins != '' &&
needs.get-environment.outputs.stability != 'stable' &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
strategy: strategy:
fail-fast: false fail-fast: false
@ -200,7 +214,7 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 - uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with: with:
@ -284,6 +298,12 @@ jobs:
test-plugins: test-plugins:
needs: [get-environment, get-plugins, package] needs: [get-environment, get-plugins, package]
if: |
needs.get-plugins.outputs.plugins != '' &&
needs.get-environment.outputs.stability != 'stable' &&
! cancelled() &&
! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled')
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@ -319,7 +339,7 @@ jobs:
password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }} password: ${{ secrets.HARBOR_CENTREON_PULL_TOKEN }}
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ./.github/actions/test-plugins - uses: ./.github/actions/test-plugins
with: with:
@ -339,7 +359,7 @@ jobs:
needs: [get-environment, get-plugins, test-plugins] needs: [get-environment, get-plugins, test-plugins]
if: | if: |
needs.get-plugins.outputs.plugins != '' && needs.get-plugins.outputs.plugins != '' &&
(contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || ( needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) && (contains(fromJson('["testing", "unstable"]'), needs.get-environment.outputs.stability) || (needs.get-environment.outputs.stability == 'stable' && github.event_name != 'workflow_dispatch')) &&
! cancelled() && ! cancelled() &&
! contains(needs.*.result, 'failure') && ! contains(needs.*.result, 'failure') &&
! contains(needs.*.result, 'cancelled') ! contains(needs.*.result, 'cancelled')
@ -364,7 +384,7 @@ jobs:
name: deliver ${{ matrix.distrib }} name: deliver ${{ matrix.distrib }}
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Delivery - name: Delivery
uses: ./.github/actions/package-delivery uses: ./.github/actions/package-delivery
@ -377,13 +397,15 @@ jobs:
artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }} artifactory_token: ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}
deliver-sources: deliver-sources:
needs: [get-environment] needs: [get-environment, fatpacker]
if: ${{ needs.get-environment.outputs.stability == 'stable' && github.event_name == 'push' }} if: |
needs.get-environment.outputs.stability == 'stable' &&
github.event_name == 'push'
runs-on: [self-hosted, common] runs-on: [self-hosted, common]
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 - uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with: with:
@ -408,7 +430,7 @@ jobs:
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Push git release tag - name: Push git release tag
run: | run: |