Open biltongza opened 1 year ago
I have run into the same issue. I am deploying the Hugo app cstate
(https://github.com/cstate/cstate), which gets the last-modified info from git history for displaying incident history.
As @biltongza says, since the container is mounting the git directory from outside, it really needs to run the git command to trust the directory as the first step in its containerized workflow.
I forgot I logged this issue, but I also found a workaround. It turns out that you can specify pre build commands via an environment variable. You can add this to your workflow:
env:
PRE_BUILD_COMMAND: git config --global --add safe.directory /github/workspace
Not sure where the "public" documentation for static web apps on this is, but since it uses Oryx under the hood, this is at least mentioned here: https://github.com/microsoft/Oryx/blob/d37b2225a252ab2c04b4726024d047cf01ea1318/doc/runtimes/nodejs.md?plain=1#L45
Describe the bug
I have some code to get the current commit hash and time in my build process. Specifically, I am using SvelteKit and I fetch the commit details in the
vite.config.js
file.For a while, this has been silently broken on my site and I have not been able to reproduce the issue locally. After adding some logging to my build process I found that the git commands to fetch these details do not execute successfully because the
Azure/static-web-apps-deploy@v1
is getting mounted in the build container (which seems to mess up directory ownership) and the directory is not marked as a safe directory in git.I think an easy way to fix it would be for the container to run
git config --global --add safe.directory /github/workspace
before actually running the build.Github workflow file:
To Reproduce Steps to reproduce the behavior:
vite.config.js
file with the following:// Get current tag/commit and last commit date from git const pexec = promisify(exec); const promises = ( await Promise.allSettled([ pexec('git describe --tags || git rev-parse --short HEAD'), pexec('git log -1 --format=%cd --date=format:"%Y-%m-%d %H:%M"'), ]) ); console.log('VITE CONFIG: promises', promises);
const [version, lastmod] = promises.map(v => JSON.stringify(v.value?.stdout.trim())); console.log(
VITE CONFIG: commit hash
, version); console.log(VITE CONFIG: commit time
, lastmod);/* @type {import('vite').UserConfig} / const config = { plugins: [sveltekit({})], server: { port: 5000 }, define: { VERSION: version, LASTMOD: lastmod, }, };
export default config;
VITE CONFIG: promises [ { status: 'rejected', reason: Error: Command failed: git describe --tags || git rev-parse --short HEAD fatal: detected dubious ownership in repository at '/github/workspace' To add an exception for this directory, call:
}, { status: 'rejected', reason: Error: Command failed: git log -1 --format=%cd --date=format:"%Y-%m-%d %H:%M" fatal: detected dubious ownership in repository at '/github/workspace' To add an exception for this directory, call:
} ] VITE CONFIG: commit hash undefined VITE CONFIG: commit time undefined