Compare commits

..

2 commits

Author SHA1 Message Date
Skyler Grey a5b34ea356 fix: Correct output path with failed builds
Previously, if a build failed to produce any output we would try to
write "None" to the output file. This doesn't work, causing the job to
error. Instead, we should skip writing the output and preserve the
original "failed" status.
2024-09-11 20:54:03 +00:00
Skyler Grey 46800094bb feat!: Update output path writing
- Allow pull requests to create output paths

Previously, it was not possible to get unmerged pull request outputs. I
would like to access these (e.g. for hosting a preview version of a
website in a similar way to https://docs.netlify.com/site-deploys/deploy-previews/
or https://vercel.com/docs/deployments/preview-deployments)

These are now surfaced under `{owner}/{repo}/pulls/{pr number}`

- Fix repository attribute name conflicts

Previously there was no difference between samely-named attributes in
different repositories.

This has been changed so outputs are under `{owner}/{repo}/{branch}`

- Allow full attribute names, still stripping path traversal

Previously, presumably to prevent path traversal, if your attribute name
contained slashes buildbot-nix would only take the last segment as an
output.

This has been replaced by interpreting slashes as subdirectories and
refusing any segments which don't descend into a subdirectory (i.e. are
attempting path traversal)

- Still create outputs on skipped builds

Previously when something was skipped, for example a build that was
completed in a pull request, the output wouldn't be updated. This made
the outputs directory quite unreliable.

Outputs will now always be updated, no matter whether a build was
actually executed.

BREAKING-CHANGE: This stops old output locations being outputted. If you rely on these locations, you will need to update whatever relies on them.
2024-07-28 09:06:51 +00:00

View file

@ -339,6 +339,11 @@ class UpdateBuildOutput(steps.BuildStep):
if not pr and props.getProperty("branch") != self.project.default_branch: if not pr and props.getProperty("branch") != self.project.default_branch:
return util.SKIPPED return util.SKIPPED
out_path = props.getProperty("out_path")
if not out_path: # if, e.g., the build fails and doesn't produce an output
return util.SKIPPED
owner = Path(props.getProperty("owner")) owner = Path(props.getProperty("owner"))
repo = Path(props.getProperty("repository_name")) repo = Path(props.getProperty("repository_name"))
@ -355,11 +360,11 @@ class UpdateBuildOutput(steps.BuildStep):
file.parent.mkdir(parents=True, exist_ok=True) file.parent.mkdir(parents=True, exist_ok=True)
out_path = props.getProperty("out_path")
file.write_text(out_path) file.write_text(out_path)
return util.SUCCESS return util.SUCCESS
# GitHub somtimes fires the PR webhook before it has computed the merge commit # GitHub somtimes fires the PR webhook before it has computed the merge commit
# This is a workaround to fetch the merge commit and checkout the PR branch in CI # This is a workaround to fetch the merge commit and checkout the PR branch in CI
class GitLocalPrMerge(steps.Git): class GitLocalPrMerge(steps.Git):