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

Differentiating between Artifacts that are downloaded using dawidd6/action-download-artifact #308

Open
AmieteeF opened this issue Sep 20, 2024 · 2 comments

Comments

@AmieteeF
Copy link

Description

I have 3 workflows: A build.yml workflow that "builds" and uploads an artifact. This is called by another workflow dev-branch.yml which is triggered by a push event for branches starting with dev/

build.yml

on:
  workflow_call:

jobs:
  build:
    runs-on: [ macos-latest ]
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v3
      with:
        ref: ${{ github.event.ref }}
    
    - name: Build Artifact
      run: |
        echo "Hello, world!" | cat > hello_world.txt
        
    - name: Upload Artifact
      uses: actions/upload-artifact@v3
      with:
        name: helloWorld
        path: ./

dev-branch.yml

on:
  push:
    branches:
      - dev/*
  
  workflow_dispatch:

jobs:
  build:
    uses: ./.github/workflows/build.yml
  deploy-dev:
    runs-on: [ macos-latest ]
    needs: build
    steps:
    - name: Deploy Dev
      run: echo "Dev is being deployed"

Lastly, I have a delete-dev.yml workflow. It uses dawidd6/action-download-artifact@v6 to download the artifact uploaded in the build.yml workflow (used by dev-branch.yml) to use the artifact for subsequent steps.

delete-dev.yml

on:
  delete:
    branches:
      - dev/*
  
  workflow_dispatch:

jobs:
  download-artifact:
    runs-on: [ macos-latest ]
    steps:
    - name: Download Artifact
      uses: dawidd6/action-download-artifact@v6
      with:
        workflow: dev-branch.yml
        workflow_conclusion: success
        commit: ${{ github.event.before }}
        name: helloWorld
        path: ./
        search_artifacts: true

  delete-dev-infra:
    runs-on: [ macos-latest ]
    needs: download-artifact
    steps:
    - name: Delete Dev Infra
      run: echo "This Dev Infra is being deleted..."

Question

How do you configure the dawidd6/action-download-artifact@v6 action so that two branches do not download the same artifact?

I've tested this use case in my repo by creating two branches dev/br-1 and dev/br-2. I make new commits so that each writes its contents to hello_world_one.txt and hello_world_two.txt respectively. This push event triggers dev-branch.yml and the artifacts are unique at this point.

However when I delete both branches, which triggers the delete-dev.yml workflow, both branches download the same artifact. Specifically the artifact that was uploaded last. I even added the commit and search_artifacts parameters in attempt to differentiate the artifacts per this issue: #130

It seems like the file is being overwritten but how is that possible when the files have two different paths? What I expect is for the jobs to download the artifacts they each originally uploaded.

Output (exactly the same for both branches)

Run dawidd6/action-download-artifact@v6
  with:
    workflow: dev-branch.yml
    workflow_conclusion: success
    name: helloWorld
    path: ./
    search_artifacts: true
    github_token: ***
    workflow_search: false
    repo: AmieteeF/sandbox-repo
    name_is_regexp: false
    allow_forks: false
    check_artifacts: false
    skip_unpack: false
    if_no_artifact_found: fail
==> Repository: AmieteeF/sandbox-repo
==> Artifact name: helloWorld
==> Local path: ./
==> Workflow name: dev-branch.yml
==> Workflow conclusion: success
==> Allow forks: false
==> (found) Run ID: 109650073[2](https://github.com/AmieteeF/sandbox-repo/actions/runs/10965041224/job/30449968546#step:2:2)4
==> (found) Run date: 2024-09-20T19:15:[4](https://github.com/AmieteeF/sandbox-repo/actions/runs/10965041224/job/30449968546#step:2:4)6Z
==> Artifact: 1959809692
==> Downloading: helloWorld.zip ([6](https://github.com/AmieteeF/sandbox-repo/actions/runs/10965041224/job/30449968546#step:2:6)4 B)
==> Extracting: helloWorld.zip
    inflating: hello_world_two.txt
    inflating: README.md

Also, why is the commit ID not showing up in the output? Thanks.

@dawidd6
Copy link
Owner

dawidd6 commented Sep 21, 2024

Are you sure github.event.before is not empty?

Looking at https://docs.github.com/en/webhooks/webhook-events-and-payloads#delete, I don't see before in the event payload.

Commit should show up in the output when it's set to non empty string.

@AmieteeF
Copy link
Author

Any advice for how to pass the commitId from the workflow that uploads the artifact to the workflow that downloads the same artifact?

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

No branches or pull requests

2 participants