Search code examples
github-actionsgithub-pagesemscripten

actions/upload-pages-artifact fails at actions/upload-artifact with "No files were found with the provided path"


I would like to create a GitHub Workflow that builds a C++ application using emscripten and cmake, and deploys it to GitHub Pages. My Workflow job looks like this.

environment:
  name: github-pages
  url: ${{steps.deployment.outputs.page_url}}

runs-on: ubuntu-latest

container:
  image: emscripten/emsdk
  
steps:
- uses: actions/checkout@v3
- run: cmake -B $GITHUB_WORKSPACE/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DEMSCRIPTEN=ON
- run: cmake --build $GITHUB_WORKSPACE/build --config ${{env.BUILD_TYPE}}

# actions/upload-pages-artifact uses this directory, but it doesn't exist in the image
- run: mkdir -p ${{runner.temp}}

- uses: actions/configure-pages@v1
- uses: actions/upload-pages-artifact@v1
  with:
    path: $GITHUB_WORKSPACE/build
- id: deployment
  uses: actions/deploy-pages@v1  

upload-pages-artifact runs tar and lists all the files to be deployed in the log. When running upload-artifact the log reads Warning: No files were found with the provided path: /__w/_temp/artifact.tar. No artifacts will be uploaded..

Note that the path in the warning is different from the one provided as a parameter to upload-artifact (path: /home/runner/work/_temp/artifact.tar).

upload-pages-artifact works as expected when running without the emscripten container.

I would have to either get upload-pages-artifact working inside the container, or somehow share the build with a second job running outside the container.


Solution

  • Split up the job into two jobs, one for building and one for deploying. Use actions/upload-artifact and actions/download-artifact to pass the build from one job to the next. Don't use $GITHUB_WORKSPACE, as it might not point to the right directory in your image.

    jobs:
      build:
        runs-on: ubuntu-latest
        container:
          image: emscripten/emsdk
          
        steps:
        - uses: actions/checkout@v3
        - run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DEMSCRIPTEN=ON
        - run: cmake --build build --config ${{env.BUILD_TYPE}}
        - uses: actions/upload-artifact@master
          with:
            name: page
            path: build
            if-no-files-found: error
        
      deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
          name: github-pages
          url: ${{steps.deployment.outputs.page_url}}
          
        steps:
        - uses: actions/download-artifact@master
          with:
            name: page
            path: .
        - uses: actions/configure-pages@v1
        - uses: actions/upload-pages-artifact@v1
          with:
            path: .
        - id: deployment
          uses: actions/deploy-pages@main