Skip to content

Commit

Permalink
use merge-artifacts action in perl-cpan-libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
a-eljazouly committed Feb 6, 2024
1 parent e4e5d8e commit e9f4582
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
65 changes: 65 additions & 0 deletions .github/actions/merge-artifacts/action.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 42 additions & 2 deletions .github/workflows/perl-cpan-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit e9f4582

Please sign in to comment.