canonical / action-publish

A Github action for publishing snaps
MIT License
35 stars 12 forks source link

`'.' is not a valid file` #43

Closed postmodern closed 6 months ago

postmodern commented 6 months ago

I copy/pasted the example from the README into my GitHub Actions workflow, and the artifact appears to be downloaded, but I get an odd error '.' is not a valid file.

name: Snapcraft

on: [ push ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: snapcore/action-build@v1
      id: build-snap
    - run: |
        sudo snap install --devmode --dangerous ${{ steps.build-snap.outputs.snap }}
    - uses: actions/upload-artifact@v3
      with:
        name: ronin.snap
        path: ${{ steps.build-snap.outputs.snap }}

  publish:
    if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    needs: build
    steps:
    - uses: actions/download-artifact@v3
      with:
        name: ronin.snap
        path: .
    - uses: snapcore/action-publish@v1
      env:
        SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
      with:
        snap: ${{needs.build.outputs.snap-file}}
        release: ${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge'}}
2024-04-18T22:40:46.2074660Z Current runner version: '2.315.0'
2024-04-18T22:40:46.2096350Z ##[group]Operating System
2024-04-18T22:40:46.2096993Z Ubuntu
2024-04-18T22:40:46.2097294Z 22.04.4
2024-04-18T22:40:46.2097726Z LTS
2024-04-18T22:40:46.2098061Z ##[endgroup]
2024-04-18T22:40:46.2098409Z ##[group]Runner Image
2024-04-18T22:40:46.2098937Z Image: ubuntu-22.04
2024-04-18T22:40:46.2099336Z Version: 20240414.1.0
2024-04-18T22:40:46.2100364Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20240414.1/images/ubuntu/Ubuntu2204-Readme.md
2024-04-18T22:40:46.2101918Z Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20240414.1
2024-04-18T22:40:46.2102764Z ##[endgroup]
2024-04-18T22:40:46.2103192Z ##[group]Runner Image Provisioner
2024-04-18T22:40:46.2103771Z 2.0.361.1
2024-04-18T22:40:46.2104129Z ##[endgroup]
2024-04-18T22:40:46.2106497Z ##[group]GITHUB_TOKEN Permissions
2024-04-18T22:40:46.2108096Z Actions: write
2024-04-18T22:40:46.2108812Z Attestations: write
2024-04-18T22:40:46.2109318Z Checks: write
2024-04-18T22:40:46.2109746Z Contents: write
2024-04-18T22:40:46.2110134Z Deployments: write
2024-04-18T22:40:46.2110510Z Discussions: write
2024-04-18T22:40:46.2110962Z Issues: write
2024-04-18T22:40:46.2111366Z Metadata: read
2024-04-18T22:40:46.2111715Z Packages: write
2024-04-18T22:40:46.2112182Z Pages: write
2024-04-18T22:40:46.2112575Z PullRequests: write
2024-04-18T22:40:46.2112994Z RepositoryProjects: write
2024-04-18T22:40:46.2113479Z SecurityEvents: write
2024-04-18T22:40:46.2113909Z Statuses: write
2024-04-18T22:40:46.2114283Z ##[endgroup]
2024-04-18T22:40:46.2117300Z Secret source: Actions
2024-04-18T22:40:46.2117856Z Prepare workflow directory
2024-04-18T22:40:46.2748182Z Prepare all required actions
2024-04-18T22:40:46.2973325Z Getting action download info
2024-04-18T22:40:46.5079431Z Download action repository 'actions/download-artifact@v3' (SHA:9bc31d5ccc31df68ecc42ccf4149144866c47d8a)
2024-04-18T22:40:46.9979381Z Download action repository 'snapcore/action-publish@v1' (SHA:214b86e5ca036ead1668c79afb81e550e6c54d40)
2024-04-18T22:40:47.5695327Z Complete job name: publish
2024-04-18T22:40:47.6778586Z ##[group]Run actions/download-artifact@v3
2024-04-18T22:40:47.6779375Z with:
2024-04-18T22:40:47.6779729Z   name: ronin.snap
2024-04-18T22:40:47.6780161Z   path: .
2024-04-18T22:40:47.6780613Z ##[endgroup]
2024-04-18T22:40:47.7950064Z Starting download for ronin.snap
2024-04-18T22:40:48.3313191Z Directory structure has been setup for the artifact
2024-04-18T22:40:48.3314828Z Total number of files that will be downloaded: 1
2024-04-18T22:40:48.5643749Z Artifact ronin.snap was downloaded to /home/runner/work/snap/snap
2024-04-18T22:40:48.5644819Z Artifact download has finished successfully
2024-04-18T22:40:48.5940505Z ##[group]Run snapcore/action-publish@v1
2024-04-18T22:40:48.5941029Z with:
2024-04-18T22:40:48.5941342Z   release: edge
2024-04-18T22:40:48.5941733Z env:
2024-04-18T22:40:48.6105815Z   SNAPCRAFT_STORE_CREDENTIALS: ***
2024-04-18T22:40:48.6106387Z ##[endgroup]
2024-04-18T22:40:48.7391660Z Publishing snap ""...
2024-04-18T22:40:48.7440986Z Installing Snapcraft...
2024-04-18T22:40:48.7524698Z [command]/usr/bin/sudo snap install --classic snapcraft
2024-04-18T22:41:10.9565264Z snapcraft 8.0.5 from Canonical** installed
2024-04-18T22:41:10.9623218Z [command]/snap/bin/snapcraft upload  --release edge
2024-04-18T22:41:12.7266923Z Starting Snapcraft 8.0.5
2024-04-18T22:41:12.7271336Z Logging execution to '/home/runner/.local/state/snapcraft/log/snapcraft-20240418-224112.725365.log'
2024-04-18T22:41:12.7291491Z '.' is not a valid file
2024-04-18T22:41:12.8418129Z ##[error]The process '/snap/bin/snapcraft' failed with exit code 1
2024-04-18T22:41:12.8613253Z Cleaning up orphan processes
mr-cal commented 6 months ago

I think the problem is that this variable is empty: snap: ${{needs.build.outputs.snap-file}}

snapcraft upload produces the same error with an empty snap name:

> snapcraft upload ""
'.' is not a valid file

What if you change it to snap: ronin.snap?

This line of the log:

2024-04-18T22:41:10.9623218Z [command]/snap/bin/snapcraft upload  --release edge

Should be something like:

2024-04-18T22:41:10.9623218Z [command]/snap/bin/snapcraft upload ronin.snap --release edge
postmodern commented 6 months ago

@mr-cal getting closer. It's now claiming ronin.snap is not a valid file, despite the previous snapcore/action-download downloading the built snap to ronin.snap and snapcore/action-upload also uploading ronin.snap.

    - uses: snapcore/action-publish@v1
      env:
        SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
      with:
        snap: ronin.snap # <---- the line changed
        release: ${{ startsWith(github.ref, 'refs/tags/') && 'candidate' || 'edge'}}
2024-04-19T19:33:29.9936992Z Current runner version: '2.315.0'
2024-04-19T19:33:29.9971509Z ##[group]Operating System
2024-04-19T19:33:29.9972504Z Ubuntu
2024-04-19T19:33:29.9973089Z 22.04.4
2024-04-19T19:33:29.9973857Z LTS
2024-04-19T19:33:29.9974455Z ##[endgroup]
2024-04-19T19:33:29.9975236Z ##[group]Runner Image
2024-04-19T19:33:29.9975924Z Image: ubuntu-22.04
2024-04-19T19:33:29.9976576Z Version: 20240414.1.0
2024-04-19T19:33:29.9978594Z Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20240414.1/images/ubuntu/Ubuntu2204-Readme.md
2024-04-19T19:33:29.9981082Z Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20240414.1
2024-04-19T19:33:29.9982527Z ##[endgroup]
2024-04-19T19:33:29.9983379Z ##[group]Runner Image Provisioner
2024-04-19T19:33:29.9984240Z 2.0.361.1
2024-04-19T19:33:29.9984875Z ##[endgroup]
2024-04-19T19:33:29.9988840Z ##[group]GITHUB_TOKEN Permissions
2024-04-19T19:33:29.9991110Z Actions: write
2024-04-19T19:33:29.9992217Z Attestations: write
2024-04-19T19:33:29.9993026Z Checks: write
2024-04-19T19:33:29.9993781Z Contents: write
2024-04-19T19:33:29.9994493Z Deployments: write
2024-04-19T19:33:29.9995146Z Discussions: write
2024-04-19T19:33:29.9996027Z Issues: write
2024-04-19T19:33:29.9996726Z Metadata: read
2024-04-19T19:33:29.9997398Z Packages: write
2024-04-19T19:33:29.9998185Z Pages: write
2024-04-19T19:33:29.9998889Z PullRequests: write
2024-04-19T19:33:29.9999633Z RepositoryProjects: write
2024-04-19T19:33:30.0000565Z SecurityEvents: write
2024-04-19T19:33:30.0001356Z Statuses: write
2024-04-19T19:33:30.0002023Z ##[endgroup]
2024-04-19T19:33:30.0006369Z Secret source: Actions
2024-04-19T19:33:30.0007260Z Prepare workflow directory
2024-04-19T19:33:30.0672106Z Prepare all required actions
2024-04-19T19:33:30.0827778Z Getting action download info
2024-04-19T19:33:30.2432206Z Download action repository 'actions/download-artifact@v3' (SHA:9bc31d5ccc31df68ecc42ccf4149144866c47d8a)
2024-04-19T19:33:30.5458252Z Download action repository 'snapcore/action-publish@v1' (SHA:214b86e5ca036ead1668c79afb81e550e6c54d40)
2024-04-19T19:33:30.9003202Z Complete job name: publish
2024-04-19T19:33:31.0081462Z ##[group]Run actions/download-artifact@v3
2024-04-19T19:33:31.0082122Z with:
2024-04-19T19:33:31.0082505Z   name: ronin.snap
2024-04-19T19:33:31.0083046Z   path: .
2024-04-19T19:33:31.0083387Z ##[endgroup]
2024-04-19T19:33:31.2385165Z Starting download for ronin.snap
2024-04-19T19:33:31.3501392Z Directory structure has been setup for the artifact
2024-04-19T19:33:31.3520913Z Total number of files that will be downloaded: 1
2024-04-19T19:33:31.3929534Z Artifact ronin.snap was downloaded to /home/runner/work/snap/snap
2024-04-19T19:33:31.3930906Z Artifact download has finished successfully
2024-04-19T19:33:31.4226574Z ##[group]Run snapcore/action-publish@v1
2024-04-19T19:33:31.4227253Z with:
2024-04-19T19:33:31.4227629Z   snap: ronin.snap
2024-04-19T19:33:31.4228017Z   release: edge
2024-04-19T19:33:31.4228464Z env:
2024-04-19T19:33:31.4529252Z   SNAPCRAFT_STORE_CREDENTIALS: ***
2024-04-19T19:33:31.4529838Z ##[endgroup]
2024-04-19T19:33:31.5923690Z Publishing snap "ronin.snap"...
2024-04-19T19:33:31.6019013Z Installing Snapcraft...
2024-04-19T19:33:31.6020856Z [command]/usr/bin/sudo snap install --classic snapcraft
2024-04-19T19:33:47.8101365Z snapcraft 8.0.5 from Canonical** installed
2024-04-19T19:33:47.8152193Z [command]/snap/bin/snapcraft upload ronin.snap --release edge
2024-04-19T19:33:49.5704175Z Starting Snapcraft 8.0.5
2024-04-19T19:33:49.5705708Z Logging execution to '/home/runner/.local/state/snapcraft/log/snapcraft-20240419-193349.568827.log'
2024-04-19T19:33:49.5714370Z 'ronin.snap' is not a valid file
2024-04-19T19:33:49.6874397Z ##[error]The process '/snap/bin/snapcraft' failed with exit code 1
2024-04-19T19:33:49.7103948Z Cleaning up orphan processes
mr-cal commented 6 months ago

I suspect something is still misconfigured with the upload/download actions but I'm not sure what. This doubly-nested snap dir is suspicious: 2024-04-19T19:33:31.3929534Z Artifact ronin.snap was downloaded to /home/runner/work/snap/snap

Can you try some debugging steps before the snapcore/action-publish@v1 step?

Something like this would be a good start:

- name: troubleshooting
    run: |
       pwd
       ls -al
postmodern commented 6 months ago

@mr-cal ah ha, it's using a unique name with the version and arch embedding in it. I assume GitHub Actions has a special variable for this file name?

2024-04-19T19:57:35.6579148Z ##[endgroup]
2024-04-19T19:57:35.6731819Z /home/runner/work/snap/snap
2024-04-19T19:57:35.6754285Z total 24
2024-04-19T19:57:35.6765460Z drwxr-xr-x 2 runner docker  4096 Apr 19 19:57 .
2024-04-19T19:57:35.6766554Z drwxr-xr-x 3 runner docker  4096 Apr 19 19:57 ..
2024-04-19T19:57:35.6767937Z -rw-r--r-- 1 runner docker 16384 Apr 19 19:57 ronin_2.0.5_amd64.snap
2024-04-19T19:57:35.6901930Z ##[group]Run snapcore/action-publish@v1
2024-04-19T19:57:35.6902523Z with:
2024-04-19T19:57:35.6902805Z   snap: ronin.snap
2024-04-19T19:57:35.6903174Z   release: edge
2024-04-19T19:57:35.6903590Z env:
2024-04-19T19:57:35.7060338Z   SNAPCRAFT_STORE_CREDENTIALS: ***
2024-04-19T19:57:35.7060883Z ##[endgroup]
2024-04-19T19:57:35.9413935Z Publishing snap "ronin.snap"...
2024-04-19T19:57:36.7553402Z Installing Snapcraft...
2024-04-19T19:57:37.2580918Z [command]/usr/bin/sudo snap install --classic snapcraft
2024-04-19T19:57:54.0298241Z snapcraft 8.0.5 from Canonical** installed
2024-04-19T19:57:54.0389552Z [command]/snap/bin/snapcraft upload ronin.snap --release edge
2024-04-19T19:57:55.8918432Z Starting Snapcraft 8.0.5
2024-04-19T19:57:55.8920519Z Logging execution to '/home/runner/.local/state/snapcraft/log/snapcraft-20240419-195755.889630.log'
2024-04-19T19:57:55.8928984Z 'ronin.snap' is not a valid file
2024-04-19T19:57:56.0516053Z ##[error]The process '/snap/bin/snapcraft' failed with exit code 1
2024-04-19T19:57:56.0834219Z Cleaning up orphan processes
postmodern commented 6 months ago

@mr-cal I suspect ${{ steps.build.outputs.snap }} is blank, because it's only populated in the build job. The example GitHub Actions file I used had two separate jobs for build and publish, with a branch check on publish to prevent other branches from being published.

postmodern commented 6 months ago

This is the tutorial I followed: https://ubuntu.com/robotics/docs/build-and-publish-a-ros-snap-with-github-actions

It appears to contain some mistakes, such as ${{needs.build.outputs.snap-file}} instead of ${{needs.build.outputs.snap}}; although that won't work either, since it appears that variables are not shared between separate jobs.

postmodern commented 6 months ago

@mr-cal I figured it out! I was missing a key piece of configuration in their top example.

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      snap-file: ${{ steps.build-snap.outputs.snap }}
...

The build.outputs.snap-file variable needs to be explicitly defined in order for ${{ needs.build.outputs.snap-file }} to be populated.

mr-cal commented 6 months ago

Great, glad you got it working!!