lukka / run-vcpkg

The GitHub Action to setup vcpkg for your C++ based projects. Stores built ports using Binary Caching backed onto GH Cache.
MIT License
196 stars 26 forks source link

run-vcpkg@v11 requires manually setting environment variables for caching to work #195

Closed akrieger closed 1 year ago

akrieger commented 1 year ago

Using vcpkg in manifest mode, our workflow which worked on v10 emits this output and doesn't cache.

         "D:\a\Cataclysm-DDA\b\vcpkg\vcpkg.exe" install "--host-triplet=x64-windows-static" --x-wait-for-lock --triplet "x64-windows-static" --vcpkg-root "D:\a\Cataclysm-DDA\b\vcpkg\\" "--x-manifest-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\\" "--x-install-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\vcpkg_installed\x64-windows-static\\" --clean-after-build
         "D:\a\Cataclysm-DDA\b\vcpkg\vcpkg.exe" install "--host-triplet=x64-windows-static" --x-wait-for-lock --triplet "x64-windows-static" --vcpkg-root "D:\a\Cataclysm-DDA\b\vcpkg\\" "--x-manifest-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\\" "--x-install-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\vcpkg_installed\x64-windows-static\\" --clean-after-build
     3>D:\a\Cataclysm-DDA\b\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets(183,5): warning : warning: Embedding `vcpkg-configuration` in a manifest file is an EXPERIMENTAL feature. [D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\Cataclysm-lib-vcpkg-static.vcxproj]
         The GHA binary source requires the ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL environment variables to be set. See https://learn.microsoft.com/en-us/vcpkg/users/binarycaching#gha for details.
     3>D:\a\Cataclysm-DDA\b\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets(183,5): error MSB3073: The command ""D:\a\Cataclysm-DDA\b\vcpkg\vcpkg.exe" install "--host-triplet=x64-windows-static" --x-wait-for-lock --triplet "x64-windows-static" --vcpkg-root "D:\a\Cataclysm-DDA\b\vcpkg\\" "--x-manifest-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\\" "--x-install-root=D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\vcpkg_installed\x64-windows-static\\" --clean-after-build" exited with code 1. [D:\a\Cataclysm-DDA\Cataclysm-DDA\msvc-full-features\Cataclysm-lib-vcpkg-static.vcxproj]
lukka commented 1 year ago

@akrieger good question, I need to add explicitly this info to the run-vcpkg@v11 documentation. I imagine you have a workflow that does this:

     uses: run-vcpkg@v11. # <= Succeeds
     run: vcpkg.exe install <rest of cmd line> # <= Fails with missing env var error

When running vcpkg yourself (i.e. when it is not run by the action), you need to add the following variables, like it is done in the C++ project template:

      - uses: actions/github-script@v6
        with:
          script: |
            core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
            core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

I see two fixes here:

akrieger commented 1 year ago

Our workflow file uses run-vcpkg and then manually invokes vcpkg via manifest mode. I will test with setting the env vars manually like you showed.

    - name: Restore artifacts, or run vcpkg, build and cache artifacts
      uses: lukka/run-vcpkg@v11
      id: runvcpkg
      with:
        # run-vcpkg tries to hash vcpkg.json but complans if it finds more than one.
        # That said, we also have our custom vcpkg_triplets to hash, so we keep everything the same.
        appendedCacheKey: ${{ hashFiles( 'msvc-full-features/vcpkg.json', 'msvc-object_creator/vcpkg.json', '.github/vcpkg_triplets/**', '.github/vckg_ports/**' ) }}
        # Rev this value to drop cache without changing vcpkg commit
        prependedCacheKey: v1-x64-full
        vcpkgDirectory: '${{ runner.workspace }}/b/vcpkg'
        # Caching happens as a post-action which runs at the end of the whole workflow
        vcpkgGitCommitId: '5b1214315250939257ef5d62ecdcbca18cf4fb1c'

    - name: Integrate vcpkg
      run: |
        vcpkg integrate install --vcpkg-root '${{ runner.workspace }}\b\vcpkg'

        ...

    - name: Build <-- vcokg invoked by msbuild here
      run: |
          msbuild -m -p:Configuration=Release -p:Platform=x64 "-target:Cataclysm-vcpkg-static;Cataclysm-test-vcpkg-static;JsonFormatter-vcpkg-static" msvc-full-features/Cataclysm-vcpkg-static.sln
          msbuild -m -p:Configuration=Release -p:Platform=x64 "-target:ObjectCreator-vcpkg-static" msvc-object_creator/ObjectCreator-vcpkg-static.sln
akrieger commented 1 year ago

Setting the env vars seemed to suppress that output. I found the job failing is caused by a changed portfile, so I'll edit the issue title appropriately.

lukka commented 1 year ago

@akrieger fixed with release https://github.com/lukka/run-vcpkg/releases/tag/v11.1, let me know!

akrieger commented 1 year ago
     Attempting to fetch 19 package(s) from GHA
     ...
     Restored 19 package(s) from GHA in 9.5 s. Use --debug to see more details.

Seems like it worked! I removed the logic which set the env vars myself, vcpkg seemed to restore from its own cache correctly.

lukka commented 1 year ago

@akrieger let me know if anything else needs to be fixed, thanks!