|
| 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 |
0 commit comments