From e9f4582045dd13a5e7747d01fbe810e31ac6e100 Mon Sep 17 00:00:00 2001 From: a-eljazouly Date: Tue, 6 Feb 2024 08:27:44 +0100 Subject: [PATCH] use merge-artifacts action in perl-cpan-libraries --- .github/actions/merge-artifacts/action.yml | 65 ++++++++++++++++++++++ .github/workflows/perl-cpan-libraries.yml | 44 ++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 .github/actions/merge-artifacts/action.yml diff --git a/.github/actions/merge-artifacts/action.yml b/.github/actions/merge-artifacts/action.yml new file mode 100644 index 000000000..4717619fd --- /dev/null +++ b/.github/actions/merge-artifacts/action.yml @@ -0,0 +1,65 @@ +name: 'Merge Artifacts' +description: 'Merge Artifacts' +inputs: + target_name: + description: 'The name of the result artifact' + required: true + source_paths: + description: 'The path to the files that will be uplaoded' + required: true + source_name_pattern: + description: "Artifact's pattern to be merged" + required: true + github_token: + description: 'The Github Token to use' + required: true + +runs: + using: 'composite' + steps: + - name: Download ${{ matrix.type_of_report }} Artifacts + uses: actions/download-artifact@f44cd7b40bfd40b6aa1cc1b9b5b7bf03d3c67110 # v4.1.0 + with: + pattern: ${{ inputs.source_name_pattern }}* + path: ${{ inputs.target_name }} + merge-multiple: true + + - name: Upload the Regrouped Artifact + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 + with: + name: ${{ inputs.target_name }} + path: | + ${{ inputs.source_paths }} + retention-days: 1 + + - name: Delete ${{ matrix.type_of_report }} Artifacts + run: | + artifact_pattern="${{ inputs.source_name_pattern }}" + TOKEN="${{ inputs.github_token }}" + artifact_exists=true + while [ "$artifact_exists" = true ]; do + artifact_exists=false + artifacts_response=$(curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${{ github.repository }}/actions/artifacts?per_page=100") + artifacts=$(echo $artifacts_response | jq -c '.artifacts[]') + echo "Those are the artifacts : $artifacts" + while read row; do + artifact_name=$(echo "$row" | jq -r '.name') + if [[ "$artifact_name" =~ ^.*"$artifact_pattern".* ]]; then + artifact_exists=true + echo "Deleting : $artifact_name" + artifact_id=$(echo "$row" | jq -r '.id') + curl -L \ + -X DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${artifact_id}" + fi + done <<< "$artifacts" + done + echo "End of Deleting" + shell: bash diff --git a/.github/workflows/perl-cpan-libraries.yml b/.github/workflows/perl-cpan-libraries.yml index 19f4f2640..b8c19d512 100644 --- a/.github/workflows/perl-cpan-libraries.yml +++ b/.github/workflows/perl-cpan-libraries.yml @@ -202,10 +202,30 @@ jobs: - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 with: - name: packages-${{ matrix.package_extension }}-${{ matrix.distrib }} + name: packages-${{ matrix.package_extension }}-${{ matrix.distrib }}-${{ matrix.name }} path: ./*.${{ matrix.package_extension }} retention-days: 1 + merge-package-rpm-artifacts: + needs: [package-rpm] + + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + distrib: [el8, el9] + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Merging Artifacts + uses: ./.github/actions/merge-artifacts + with: + target_name: packages-rpm-${{ matrix.distrib }} + source_paths: packages-rpm-${{ matrix.distrib }}/*.rpm + source_name_pattern: packages-rpm-${{ matrix.distrib }}- + github_token: ${{ secrets.GITHUB_TOKEN }} + package-deb: needs: [get-environment] if: ${{ needs.get-environment.outputs.stability != 'stable' }} @@ -347,10 +367,30 @@ jobs: - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 with: - name: packages-${{ matrix.package_extension }}-${{ matrix.distrib }} + name: packages-${{ matrix.package_extension }}-${{ matrix.distrib }}-${{ matrix.name }} path: ./*.${{ matrix.package_extension }} retention-days: 1 + merge-package-deb-artifacts: + needs: [package-deb] + + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + distrib: [bullseye, bookworm, jammy] + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Merging Artifacts + uses: ./.github/actions/merge-artifacts + with: + target_name: packages-deb-${{ matrix.distrib }} + source_paths: packages-deb-${{ matrix.distrib }}/*.deb + source_name_pattern: packages-deb-${{ matrix.distrib }}- + github_token: ${{ secrets.GITHUB_TOKEN }} + sign-rpm: needs: [package-rpm]