Github action-build: Error when executing /usr/bin/sudo

I wanted to try the snapcore Github action-build to automate building of my private repositories. Since I have a little bit of a complicated repository configuration and the snapcraft.yaml is actually in another repository, I need to clone it first. I thought this wouldn’t make any difference as long as I use the correct project path. However, I’m getting the following error during the “Run snapcore/action-build@v1”:

Installing LXD…
/usr/bin/sudo snap install lxd
lxd 4.0.0 from Canonical* installed
/usr/bin/sudo lxd init --auto
Installing Snapcraft…
/usr/bin/sudo snap install --classic snapcraft
snapcraft 3.11 from Canonical* installed
/usr/bin/sudo --preserve-env=SNAPCRAFT_BUILD_ENVIRONMENT,SNAPCRAFT_BUILD_INFO,SNAPCRAFT_IMAGE_INFO snapcraft
##[error]There was an error when attempting to execute the process ‘/usr/bin/sudo’. This may indicate the process failed to start. Error: spawn /usr/bin/sudo ENOENT

I’m not sure if this is caused by my configuration or something else. This is my action workflow:

name: snapcraft

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Clone my private repo 
      run: |
        mkdir -p ~/tc_ws/src
        cd ~/tc_ws/src
        git clone https://${{ secrets.TOKEN }}@github.com/organization/myRepo.git
        // Replacing some Github URLs in my rosinstall file
        sed -i 's|git@github\.com:|https://${{ secrets.TOKEN }}@github\.com/|g' ~/tc_ws/src/myRepo/snap/local/snap.rosinstall
    - uses: snapcore/action-build@v1
      with:
        path: ~/tc_ws/src/myRepo

The snapcraft.yaml is located at ~/tc_ws/src/myRepo/snap/snapcraft.yaml.

I’m sorry that I can’t provide any minimal example to test this. Any ideas @jamesh?

It is a bit hard to tell without seeing a log, but my guess is that the problem is the path parameter passed to the action:

    - uses: snapcore/action-build@v1
      with:
        path: ~/tc_ws/src/myRepo

Presumably nothing is expanding the ~ in the path. This means we have an invalid path giving the ENOENT error. It probably wouldn’t be too difficult to add manual tilde expansion into the action, although this is a fairly niche use case: the normal workflow would be to check out your repo into $GITHUB_WORKSPACE.

Until the action is updated, here are two work arounds:

  1. Pass the full path repository path in the path parameter. Looking at the docs, it looks like you could replace ~ with /github/home.

  2. Check out your project to $GITHUB_WORKSPACE (i.e. the current working directory your job is running in). Unless you’ve got a good reason to do otherwise, I would suggest using the actions/checkout@v2 action to do this. You can configure it to use an alternative access token through it’s token parameter, as described in its documentation.

1 Like

I’ve filed a bug report so I don’t forget about this:

This didn’t work. I’m not sure if this tilde is even supported by Github actions?

This did the job.

As far as Github Actions runner is concerned, input parameters to actions are just strings. As I said before, tilde expansion is not a kernel feature (since the kernel has no concept of home directories). It’s something that individual applications might choose to implement.

And I agreed that it would be a good idea for this action to implement it for the path input parameter.