Skip to content

Commit 6918e9e

Browse files
committed
Reuse action for searching an artifact
Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
1 parent 7d83104 commit 6918e9e

4 files changed

Lines changed: 75 additions & 51 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: "Search and get artifact information"
2+
description: "Searches all non-expired artifacts with name <name-arch-version-hash>. If it is found it returns the workflow run ID, download_url and other info"
3+
inputs:
4+
name:
5+
description: 'Name of the artifact'
6+
required: true
7+
token:
8+
description: 'Github token for requests to Github API'
9+
required: false
10+
outputs:
11+
name:
12+
description: "The artifact name"
13+
value: ${{ steps.get-artifact.outputs.name }}
14+
exists:
15+
description: "True if the artifact was found, false otherwise"
16+
value: ${{ steps.get-artifact.outputs.exists }}
17+
run_id:
18+
description: "The run id of the workflow that generated the artifact"
19+
value: ${{ steps.get-artifact.outputs.run_id }}
20+
download_url:
21+
description: "The download url of the respective artifact"
22+
value: ${{ steps.get-artifact.outputs.download_url }}
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Get valid artifacts
27+
id: get-artifact
28+
shell: bash
29+
run: |
30+
ALL_ARTIFACTS=$(curl -s \
31+
-H "Accept: application/vnd.github.v3+json" \
32+
-H "Authorization: Bearer ${{ inputs.token }}" \
33+
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success" \
34+
| jq -r '.workflow_runs[].artifacts_url' \
35+
| xargs -I {} curl -s \
36+
-H "Accept: application/vnd.github.v3+json" \
37+
-H "Authorization: Bearer ${{ inputs.token }}" {} \
38+
)
39+
40+
echo $ALL_ARTIFACTS
41+
42+
MATCH=$(echo "$ALL_ARTIFACTS" \
43+
| jq -r --arg TARGET "${{ inputs.name }}" \
44+
'.artifacts[]? | select(.name == $TARGET and .expired == false)' \
45+
)
46+
47+
echo $MATCH
48+
49+
echo "name=${{ inputs.name }}" >> $GITHUB_OUTPUT
50+
if [[ -z "$MATCH" ]]
51+
then
52+
echo "No artifact with name ${{ inputs.name }} was found"
53+
echo "exists=false" >> $GITHUB_OUTPUT
54+
echo "run_id=" >> $GITHUB_OUTPUT
55+
echo "download_url=" >> $GITHUB_OUTPUT
56+
else
57+
RUN_ID=$(echo "$MATCH" | jq -r '.workflow_run.id' | head -n 1)
58+
DOWNLOAD_URL=$(echo "$MATCH" | jq -r '.archive_download_url' | head -n 1)
59+
echo "Found artifact: ${{ inputs.name }} at run with ID: $RUN_ID and download url; $DOWNLOAD_URL"
60+
echo "exists=true" >> $GITHUB_OUTPUT
61+
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
62+
echo "download_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
63+
fi

.github/workflows/qemu_build.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,15 @@ jobs:
4646
QEMU_ARM64_CONFIG=$( sort qemu/arm64.config )
4747
QEMU_IGNORE_LIST=$( sort qemu/unnecessary_files.txt )
4848
QEMU_FILES_HASH=$( echo $QEMU_AMD64_CONFIG $QEMU_ARM64_CONFIG $QEMU_IGNORE_LIST | md5sum | cut -d ' ' -f 1)
49-
echo "exists=true" >> $GITHUB_OUTPUT
5049
echo "hash=${QEMU_FILES_HASH}" >> $GITHUB_OUTPUT
5150
echo "full=qemu-${{ matrix.arch }}-${{ inputs.qemu_version }}-${QEMU_FILES_HASH}" >> $GITHUB_OUTPUT
5251
5352
- name: Check if Qemu artifacts exist
5453
id: check
55-
run: |
56-
ARTIFACTS=$(curl -s -H "Accept: application/vnd.github.v3+json" \
57-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
58-
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success" \
59-
| jq -r '.workflow_runs[].artifacts_url' \
60-
| xargs -I {} curl -s -H "Accept: application/vnd.github.v3+json" {} \
61-
| jq -r '.artifacts[].name')
62-
if echo "$ARTIFACTS" | grep -q "${{ steps.name.outputs.full }}"
63-
then
64-
echo "Qemu artifacts already exist! Skipping build."
65-
echo "exists=true" >> $GITHUB_OUTPUT
66-
else
67-
echo "Qemu artifacts do not exist! Let's build them"
68-
echo "exists=false" >> $GITHUB_OUTPUT
69-
fi
54+
uses: ./.github/actions/get-artifact-info/
55+
with:
56+
name: "${{ steps.name.outputs.full }}"
57+
token: ${{ secrets.GITHUB_TOKEN }}
7058

7159
- name: Install base dependencies
7260
if: ${{ steps.check.outputs.exists == 'false' }}

.github/workflows/solo5_build.yaml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ on:
1818
type: string
1919
required: false
2020
default: '{"amd64":"ubuntu-22.04", "arm64":"ubuntu-22.04-arm"}'
21-
workflow_dispatch:
2221

2322
jobs:
2423
build-Solo5:
@@ -41,24 +40,10 @@ jobs:
4140

4241
- name: Check if Solo5 artifacts exist
4342
id: check
44-
run: |
45-
EXPECTED_HVT_ARTIFACT="solo5-hvt-${{ matrix.arch }}-${{ inputs.solo5_version }}"
46-
EXPECTED_SPT_ARTIFACT="solo5-spt-${{ matrix.arch }}-${{ inputs.solo5_version }}"
47-
ARTIFACTS=$(curl -s -H "Accept: application/vnd.github.v3+json" \
48-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
49-
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success" \
50-
| jq -r '.workflow_runs[].artifacts_url' \
51-
| xargs -I {} curl -s -H "Accept: application/vnd.github.v3+json" {} \
52-
| jq -r '.artifacts[].name')
53-
if echo "$ARTIFACTS" | grep -q "$EXPECTED_HVT_ARTIFACT" && \
54-
echo "$ARTIFACTS" | grep -q "$EXPECTED_SPT_ARTIFACT"
55-
then
56-
echo "Solo5 artifacts already exist! Skipping build."
57-
echo "exists=true" >> $GITHUB_OUTPUT
58-
else
59-
echo "Solo5 artifacts do not exist! Let's build them"
60-
echo "exists=false" >> $GITHUB_OUTPUT
61-
fi
43+
uses: ./.github/actions/get-artifact-info/
44+
with:
45+
name: "solo5-hvt-${{ matrix.arch }}-${{ inputs.solo5_version }}"
46+
token: ${{ secrets.GITHUB_TOKEN }}
6247

6348
- name: Install base dependencies
6449
if: ${{ steps.check.outputs.exists == 'false' }}

.github/workflows/virtiofsd_build.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,10 @@ jobs:
4040

4141
- name: Check if Virtiofsd artifacts exist
4242
id: check
43-
run: |
44-
EXPECTED_VIRTIOFSD_ARTIFACT="virtiofsd-${{ matrix.arch }}-${{ inputs.virtiofsd_version }}"
45-
ARTIFACTS=$(curl -s -H "Accept: application/vnd.github.v3+json" \
46-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
47-
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success" \
48-
| jq -r '.workflow_runs[].artifacts_url' \
49-
| xargs -I {} curl -s -H "Accept: application/vnd.github.v3+json" {} \
50-
| jq -r '.artifacts[].name')
51-
if echo "$ARTIFACTS" | grep -q "$EXPECTED_VIRTIOFSD_ARTIFACT"
52-
then
53-
echo "Virtiofsd artifact already exists! Skipping build."
54-
echo "exists=true" >> $GITHUB_OUTPUT
55-
else
56-
echo "Virtiofsd artifact does not exist! Let's build them"
57-
echo "exists=false" >> $GITHUB_OUTPUT
58-
fi
43+
uses: ./.github/actions/get-artifact-info/
44+
with:
45+
name: "virtiofsd-${{ matrix.arch }}-${{ inputs.virtiofsd_version }}"
46+
token: ${{ secrets.GITHUB_TOKEN }}
5947

6048
- name: Map arch names
6149
id: arch_map

0 commit comments

Comments
 (0)