Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat req] add option to overwrite existing artifacts #471

Open
sni opened this issue Dec 15, 2023 · 15 comments
Open

[feat req] add option to overwrite existing artifacts #471

sni opened this issue Dec 15, 2023 · 15 comments
Labels
enhancement New feature or request

Comments

@sni
Copy link

sni commented Dec 15, 2023

What would you like to be added?

It would be nice to have a option to allow overwrite existing artifacts like it was possible in v3.

Why is this needed?

I have an optional workflow step to sign artifacts, it downloads an artifact, signs it and uploads it with the same name again. Worked perfectly fine with actions/upload-artifact@v3.
I tried to use geekyeggo/delete-artifact@v2 but even that doesn't work.
Since this step is not applicable for pull requests, it would make things quite complicated to continue with separate artifact names.

@sni sni added the enhancement New feature or request label Dec 15, 2023
@robherley
Copy link
Contributor

robherley commented Dec 15, 2023

👋 If you need to delete an artifact, you can do it with @actions/github-script.

Here's a full example:

name: Delete Artifact Example
on:
  workflow_dispatch:

permissions:
  actions: write # required permission to delete artifact

jobs:
  upload-and-delete:
    runs-on: ubuntu-latest
    steps:
    - name: Create a File
      run: echo "hello world" > hello.txt
    - name: Upload Artifact
      id: artifact-upload
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact
        path: hello.txt
    - name: Delete Artifact
      uses: actions/github-script@v7
      with:
        script: |
          github.rest.actions.deleteArtifact({
            owner: context.repo.owner,
            repo: context.repo.repo,
            artifact_id: ${{ steps.artifact-upload.outputs.artifact-id }}
          });
    - name: Upload Artifact (again)
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact
        path: hello.txt

Make sure you have the correct permissions set for the GITHUB_TOKEN, as noted above:

permissions:
  actions: write

I'm not sure if we're going to have an official "overwrite" at this time, since artifacts become immediately available in the public API in v4, unlike in v3 where you had to wait until the end of the run. But thanks for the feedback and I'll bring it up with the team!

@sni
Copy link
Author

sni commented Dec 16, 2023

thanks for the workaround. For now, i just keep using v3 while hoping there will be a option to overwrite again in the future. If there are any implications, you could mention this in the docs and leave the decision to the user?

@onedr0p
Copy link

onedr0p commented Dec 16, 2023

I would like to see this feature added too, I saw the workaround but I will keep using v3 until this is addressed as well.

@zdgeorgiev
Copy link

@robherley I guess that will not work in matrix

@robherley
Copy link
Contributor

@zdgeorgiev It still works fine in a matrix:

name: Delete Artifact Matrix Example
on:
  workflow_dispatch:

permissions:
  actions: write # required permission to delete artifact

jobs:
  upload-and-delete:
    strategy:
      matrix:
        example: ['foo', 'bar']
    runs-on: ubuntu-latest
    steps:
    - name: Create a File
      run: echo "hello world" > hello.txt
    - name: Upload Artifact
      id: artifact-upload
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact-${{ matrix.example }}
        path: hello.txt
    - name: Delete Artifact
      uses: actions/github-script@v7
      with:
        script: |
          github.rest.actions.deleteArtifact({
            owner: context.repo.owner,
            repo: context.repo.repo,
            artifact_id: ${{ steps.artifact-upload.outputs.artifact-id }}
          });
    - name: Upload Artifact (again)
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact-${{ matrix.example }}
        path: hello.txt

You can even use the list artifacts API in octokit to list/filter/reduce on the artifact names and pass them to delete artifact.

@Borda
Copy link

Borda commented Dec 19, 2023

I'm not sure if we're going to have an official "overwrite" at this time

TBH, that would be great as you would have easier interaction among jobs, not when a simple way to pass artifact-id from jon foo to job bar so this with aggregating artifacts may not work :(

TylerHelmuth added a commit to open-telemetry/opentelemetry-collector-contrib that referenced this issue Dec 19, 2023
**Description:** 
I think v4 is broken (or the way we are using the action is no longer
supported in v4). Switching back to v3 for now to fix our CI.

**Link to tracking Issue:** <Issue number if applicable>

I think actions/upload-artifact#471

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
codeboten pushed a commit to codeboten/opentelemetry-go-contrib that referenced this issue Dec 21, 2023
We saw similar failures in the collector repositories. See an example of a failure: https://github.com/open-telemetry/opentelemetry-go-contrib/actions/runs/7292851552/job/19874703538?pr=4741

There's an open issue around this: actions/upload-artifact#471

Signed-off-by: Alex Boten <aboten@lightstep.com>
MrAlias pushed a commit to open-telemetry/opentelemetry-go-contrib that referenced this issue Dec 21, 2023
We saw similar failures in the collector repositories. See an example of a failure: https://github.com/open-telemetry/opentelemetry-go-contrib/actions/runs/7292851552/job/19874703538?pr=4741

There's an open issue around this: actions/upload-artifact#471

Signed-off-by: Alex Boten <aboten@lightstep.com>
@onedr0p
Copy link

onedr0p commented Dec 24, 2023

I'm not sure if we're going to have an official "overwrite" at this time

@robherley that's unfortunate, I hope by looking at the number of issues/pr linked that will change. It seems like most are downgrading due to this not being a feature in v4.

@robherley
Copy link
Contributor

@onedr0p 👋 I agree. Going to bring this back to the team considering how likely it'll be required. Thanks for the feedback!

nslaughter pushed a commit to nslaughter/opentelemetry-collector-contrib that referenced this issue Dec 27, 2023
**Description:** 
I think v4 is broken (or the way we are using the action is no longer
supported in v4). Switching back to v3 for now to fix our CI.

**Link to tracking Issue:** <Issue number if applicable>

I think actions/upload-artifact#471

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
nslaughter pushed a commit to nslaughter/opentelemetry-collector-contrib that referenced this issue Dec 27, 2023
**Description:** 
I think v4 is broken (or the way we are using the action is no longer
supported in v4). Switching back to v3 for now to fix our CI.

**Link to tracking Issue:** <Issue number if applicable>

I think actions/upload-artifact#471

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
@sni
Copy link
Author

sni commented Jan 10, 2024

@robherley: were you able to address the issue with the team?

cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this issue Jan 10, 2024
**Description:** 
I think v4 is broken (or the way we are using the action is no longer
supported in v4). Switching back to v3 for now to fix our CI.

**Link to tracking Issue:** <Issue number if applicable>

I think actions/upload-artifact#471

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
@robherley
Copy link
Contributor

👋 @sni If all goes well, we should have this ready by tomorrow! I have a toolkit PR open to delete artifacts, once that is merged and published I'll add an input to overwrite which will delete the previous artifact before uploading the next

@robherley
Copy link
Contributor

👋 This is now possible! Check out the example in the readme: https://github.com/actions/upload-artifact#overwriting-an-artifact

@yury-s
Copy link

yury-s commented Jan 23, 2024

Is this rolled out yet? we are seeing the following error on this workflow:

Run actions/upload-artifact@v4
  with:
    name: pull-request-number
    path: pull_request_number.txt
    overwrite: true
    if-no-files-found: warn
    compression-level: 6
  env:
    FORCE_COLOR: 1
    FLAKINESS_CONNECTION_STRING: 
    ELECTRON_SKIP_BINARY_DOWNLOAD: 1
    PWTEST_BOT_NAME: chromium-ubuntu-22.04-node20
With the provided path, there will be 1 file uploaded
Artifact name is valid!
Root directory input is valid!
Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run

@melloware
Copy link

Me too seeing this issue in v4. Downgrading to v3 fixes it for me.

@harry-s-grewal
Copy link

👋 This is now possible! Check out the example in the readme: https://github.com/actions/upload-artifact#overwriting-an-artifact

This worked for me! Thanks for adding this

@SimonCockx
Copy link

Is this rolled out yet? we are seeing the following error on this workflow:

I'm having the same issue. Even with overwrite: true I'm seeing the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants