Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

use wildcards in asset_path #47

Open
javixeneize opened this issue Apr 22, 2020 · 12 comments
Open

use wildcards in asset_path #47

javixeneize opened this issue Apr 22, 2020 · 12 comments

Comments

@javixeneize
Copy link

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

@bundabrg
Copy link

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.

@derTobsch
Copy link

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

@publicarray
Copy link

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

@konradpabjan
Copy link

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.

@derTobsch
Copy link

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

@eine
Copy link

eine commented May 15, 2020

@derTobsch, meanwhile, eine/tip might work for you. See actions/upload-artifact#21 (comment)

@catdad
Copy link

catdad commented Jul 15, 2020

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}`)
        });            
      }

@eine
Copy link

eine commented Jul 16, 2020

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

@catdad
Copy link

catdad commented Jul 16, 2020

@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.

@wildone
Copy link

wildone commented Aug 4, 2020

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

@gpiffaretti
Copy link

gpiffaretti commented Aug 19, 2020

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

@kmturley
Copy link

kmturley commented Sep 25, 2020

- 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}`)
          });
        }
      }

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

No branches or pull requests

10 participants