Skip to content

Commit

Permalink
gh/vmtests: truncate artifacts if run was successful
Browse files Browse the repository at this point in the history
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://github.com/gitapi/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://github.com/gitapi/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
  • Loading branch information
kkourt committed Aug 10, 2022
1 parent 606aa5c commit 9dd0dc8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/vmtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ jobs:
name: tetragon-vmtests-${{ matrix.kernel }}-${{ matrix.group }}-results
path: go/src/github.com/cilium/tetragon/tests/vmtests/vmtests-results-*
retention-days: 5
post-test:
runs-on: ubuntu-latest
needs: [test]
if: success()
steps:
- name: Create truncated build file
run: |
touch /tmp/tetragon.tar
- name: Upload truncated file
uses: actions/upload-artifact@v3
with:
name: tetragon-build
path: /tmp/tetragon.tar
retention-days: 1

0 comments on commit 9dd0dc8

Please sign in to comment.