upload-release-asset icon indicating copy to clipboard operation
upload-release-asset copied to clipboard

use wildcards in asset_path

Open javixeneize opened this issue 4 years ago • 12 comments

Hi

Im trying to use the action, and looks like i can't use wildcards.

i would like to do is upload any *.whl file in that dist folder using this:

asset_path: dist/*.whl

But i have an error as the file is not found. Looks like I need to specify the asset_path with the full name:

asset_path: dist/whatthefuzz-0.1.2-py3-none-any.whl

Is there any way of upload the content using wildcards as i am trying to do?

Thanks

javixeneize avatar Apr 22 '20 15:04 javixeneize

In a similar fashion (possible exactly the same scenario as OP) I have an asset with a version appended to the filename. It would be easier to use a wildcard in place of grabbing the version.

bundabrg avatar Apr 28 '20 05:04 bundabrg

see #9 and #24 - sadly nothing is happening here :/

derTobsch avatar Apr 28 '20 12:04 derTobsch

Hi @konradpabjan thanks on your recent v2 on your artifact actions. Would it be possible for you to use some of the code from https://github.com/actions/upload-artifact to this repo too? softprops/action-gh-release is a common alternative but I think the official version could use some love

publicarray avatar Apr 30 '20 13:04 publicarray

Hi @publicarray the v2 upload artifact action uses @actions/glob to handle wildcard search behind the scenes to handle wildcards. It should be possible to easily use this with any other actions.

Upload releases is not my cup of tea unfortunately and I haven't worked with this action before. I can try to ping the necessary parties to see if this could maybe get some love.

konradpabjan avatar Apr 30 '20 14:04 konradpabjan

Hey @konradpabjan, do you maybe have some information for us? :)

derTobsch avatar May 15 '20 17:05 derTobsch

@derTobsch, meanwhile, eine/tip might work for you. See https://github.com/actions/upload-artifact/issues/21#issuecomment-628995879

eine avatar May 15 '20 20:05 eine

This isn't entirely what was asked, and I still think support for wildcards is needed, but I wanted to point folks in the direction of actions/github-script as well, in case anyone is stuck waiting for a solution here. Effectively, you can easily do anything that you can do with the rest API and a Node script.

I had the same issue of wanting to upload artifacts where the names are dynamic, and solved it with this action:

- name: Create Release
  uses: actions/github-script@v2
  with:
    github-token: ${{secrets.GITHUB_TOKEN}}
    script: |
      console.log('environment', process.versions);
      
      const fs = require('fs').promises;
      
      const { repo: { owner, repo }, sha } = context;
      console.log({ owner, repo, sha });

      const release = await github.repos.createRelease({
        owner, repo,
        tag_name: process.env.GITHUB_REF,
        draft: true,
        target_commitish: sha
      });

      console.log('created release', { release });
  
      for (let file of await fs.readdir('.')) {
        // do whatever filtering you want here, I'm just uploading all the files
        console.log('uploading', file);

        await github.repos.uploadReleaseAsset({
          owner, repo,
          release_id: release.data.id,
          name: file,
          data: await fs.readFile(`./${file}`)
        });            
      }

catdad avatar Jul 15 '20 23:07 catdad

@catdad does github-scripts allow defining arbitrary npm packages as dependencies or is it limited to a fixed set?

eine avatar Jul 16 '20 00:07 eine

@eine Best I can tell, no dependencies are available by default, but you can install anything you want in a previous step of the same job.

catdad avatar Jul 16 '20 02:07 catdad

as a workaround can this work?

 - name: Get Name of Artifact
    run: |
      ARTIFACT_PATHNAME=$(ls target/*.jar | head -n 1)
      ARTIFACT_NAME=$(basename $ARTIFACT_PATHNAME)
      echo ::set-env name=ARTIFACT_NAME::${ARTIFACT_NAME}
      echo ::set-env name=ARTIFACT_PATHNAME::${ARTIFACT_PATHNAME}
  - name: upload release asset ${{ env.GITHUB_TAG }}
    id: upload-release-asset
    uses: actions/[email protected]
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    with:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
      asset_path: ${{ env.ARTIFACT_PATHNAME }}
      asset_name: ${{ env.ARTIFACT_NAME }}
      asset_content_type: application/java-archive

wildone avatar Aug 04 '20 11:08 wildone

I solved my problem with this workaround, I save the filename to the step output, and then retrieve it in a later stage. For this I had to add an ID to my step as shown below. I needed a regular expression because I didn't know the name of the file that npm pack will create, but I did know the filename prefix. With this solution I just extract the name from the output and save it. Used some more actions but didn't include in the code snippet for clarity: actions/checkout@v2 actions/setup-node@v1 actions/create-release@v1

- name: Pack tarball 
  id: pack_tarball
  run: |
    PACK_NAME=$(npm pack | tail -n 1)
    echo "::set-output name=tar_filename::$PACK_NAME"
- name: Upload Release Asset
  id: upload-release-asset 
  uses: actions/upload-release-asset@v1
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps 
    asset_path: ./${{ steps.pack_tarball.outputs.tar_filename }}
    asset_name: ${{ steps.pack_tarball.outputs.tar_filename }}
    asset_content_type: application/gzip

gpiffaretti avatar Aug 19 '20 18:08 gpiffaretti

- name: Create Release
  uses: actions/github-script@v2
  with:
    github-token: ${{secrets.GITHUB_TOKEN}}
    script: |
      console.log('environment', process.versions);
      
      const fs = require('fs').promises;
      
      const { repo: { owner, repo }, sha } = context;
      console.log({ owner, repo, sha });

      const release = await github.repos.createRelease({
        owner, repo,
        tag_name: process.env.GITHUB_REF,
        draft: true,
        target_commitish: sha
      });

      console.log('created release', { release });
  
      for (let file of await fs.readdir('.')) {
        // do whatever filtering you want here, I'm just uploading all the files
        console.log('uploading', file);

        await github.repos.uploadReleaseAsset({
          owner, repo,
          release_id: release.data.id,
          name: file,
          data: await fs.readFile(`./${file}`)
        });            
      }

One bug I found with this solution is when referring to needs/steps within the async/await functions and loops, you get an error needs not defined or steps not defined and seems to lose variable scope.

This can be fixed by adding the values needs to variables within the script scope. For example:

- name: Upload
  uses: actions/github-script@v3
  with:
    github-token: ${{secrets.GITHUB_TOKEN}}
    script: |
      const path = require('path');
      const fs = require('fs');
      const release_id = '${{ needs.create_release.outputs.id }}';
      for (let file of await fs.readdirSync('./')) {
        if (path.extname(file) === '.zip') {
          console.log('uploadReleaseAsset', file);
          await github.repos.uploadReleaseAsset({
            owner: context.repo.owner,
            repo: context.repo.repo,
            release_id: release_id,
            name: file,
            data: await fs.readFileSync(`./${file}`)
          });
        }
      }

kmturley avatar Sep 25 '20 05:09 kmturley