Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Publish a directory declaration as a tree

4f8a3da8f7801735ab7ab719b3fda3f39cb7e070 · Keenan Nemetz · 19d ago · parent 5f2a0b0a

Publish a directory declaration as a tree

A workflow artifact path with no glob that names a directory now publishes every
regular file under it, relative to that directory. `dist` gives
`apt/Packages` and `yum/repodata/repomd.xml`; `dist/apt` gives `Packages`. A
glob keeps the static-root rule, and `.` is refused so a declaration cannot
accidentally publish the whole checkout.

This matches `vole release attach <tag> <dir>` and removes the need for
depth-specific globs or a staging copy when a build already has a package tree.

Refs: 01M7BPH6RRPK2934FCHVJPQNGY

ci/agent/agent.go +32−8

@@ -1594,6 +1594,20 @@ func checkArtifactLimits(work string, files []artifactFile) error {
1594 1594 }
1595 1595
1596 1596 func collectArtifactFiles(root string, patterns []string) ([]artifactFile, error) {
1597 // A declaration with no glob may name a directory: publish the regular files
1598 // under it relative to that directory. Resolve the roots before the walk so a
1599 // directory is not confused with a literal filename on every file.
1600 dirs := make([]string, len(patterns))
1601 for i, pat := range patterns {
1602 if strings.ContainsAny(pat, "*?[") {
1603 continue
1604 }
1605 clean := path.Clean(pat)
1606 if info, err := os.Stat(filepath.Join(root, filepath.FromSlash(clean))); err == nil && info.IsDir() {
1607 dirs[i] = clean
1608 }
1609 }
1610
1597 1611 matched := make([]int, len(patterns))
1598 1612 var files []artifactFile
1599 1613 byName := map[string]string{}
@@ -1613,8 +1627,17 @@ func collectArtifactFiles(root string, patterns []string) ([]artifactFile, error
1613 1627 }
1614 1628 rel = filepath.ToSlash(rel)
1615 1629 for i, pat := range patterns {
1616 if ok, err := path.Match(pat, rel); err != nil || !ok {
1617 continue
1630 var name string
1631 if dir := dirs[i]; dir != "" {
1632 if !strings.HasPrefix(rel, dir+"/") {
1633 continue
1634 }
1635 name = strings.TrimPrefix(rel, dir+"/")
1636 } else {
1637 if ok, err := path.Match(pat, rel); err != nil || !ok {
1638 continue
1639 }
1640 name = artifactTarget(pat, rel)
1618 1641 }
1619 1642 matched[i]++
1620 1643 info, err := d.Info()
@@ -1624,7 +1647,6 @@ func collectArtifactFiles(root string, patterns []string) ([]artifactFile, error
1624 1647 if !info.Mode().IsRegular() {
1625 1648 return nil // a symlink or device: not an artifact
1626 1649 }
1627 name := artifactTarget(pat, rel)
1628 1650 if err := metadata.ValidArtifactPath(name); err != nil {
1629 1651 return fmt.Errorf("artifact %s would be published as %q: %w", rel, name, err)
1630 1652 }
@@ -1650,17 +1672,19 @@ func collectArtifactFiles(root string, patterns []string) ([]artifactFile, error
1650 1672 return files, nil
1651 1673 }
1652 1674
1653 // artifactTarget is the path a declaration publishes a matched file under. It is
1654 // the file path relative to the segments before the declaration's first glob, so
1655 // every existing flat pattern keeps its base name:
1675 // artifactTarget is the path a glob declaration publishes a matched file under.
1676 // It is the file path relative to the segments before the declaration's first
1677 // glob, so every existing flat pattern keeps its base name:
1656 1678 //
1657 1679 // dist/* -> vole.deb
1658 1680 // dist/apt/* -> Packages
1659 1681 // dist/*/* -> apt/Packages
1660 1682 // dist/apt/Packages -> Packages (a literal pattern names one file)
1661 1683 //
1662 // A pattern with a glob in its first segment is rooted at the checkout, which is
1663 // what its matches describe.
1684 // A directory declaration is handled before this: its matches are relative to
1685 // the directory itself, so `dist` publishes `apt/Packages` and `dist/apt`
1686 // publishes `Packages`. A glob with a wildcard in its first segment is rooted at
1687 // the checkout, which is what its matches describe.
1664 1688 func artifactTarget(pattern, file string) string {
1665 1689 segments := strings.Split(pattern, "/")
1666 1690 root := ""