@@ -2,7 +2,6 @@ package bundler
22
33import (
44 "archive/tar"
5- "bytes"
65 "compress/gzip"
76 "fmt"
87 "io"
@@ -29,13 +28,11 @@ type Bundler struct {
2928 root string
3029 fsys fs.FS
3130 prefix string // Prefix path inside the archive, e.g. "bundle"
32- githubRef string // GitHub ref string, e.g. "refs/tags/v1.2.3"
3331 filters []FileFilter
3432 plainTransforms []PlainTransform
3533
36- jobs []copyJob
37- files map [string ]string // map of source file paths to their relative destination paths in the bundle
38- manifest []byte // prepared manifest content with placeholders replaced
34+ jobs []copyJob
35+ files map [string ]string // map of source file paths to their relative destination paths in the bundle
3936}
4037
4138type Option func (* Bundler )
@@ -55,14 +52,6 @@ func WithPlainTransforms(transforms ...PlainTransform) Option {
5552 }
5653}
5754
58- // WithGithubRef sets the GitHub ref string to be used for manifest substitution.
59- // The ref should be in the format "refs/tags/v1.2.3".
60- func WithGithubRef (ref string ) Option {
61- return func (b * Bundler ) {
62- b .githubRef = ref
63- }
64- }
65-
6655// New creates a new Bundler instance rooted at at the given directory and using the provided fs.FS.
6756func New (root string , fsys fs.FS , opts ... Option ) * Bundler {
6857 b := & Bundler {
@@ -113,15 +102,13 @@ func defaultFilters() []FileFilter {
113102 }
114103}
115104
116- // Build prepares the list of files to archive, processes the manifest, and writes
105+ // Build prepares the list of files to archive and writes
117106// the resulting archive as a compressed tar.gz to the provided io.Writer.
118107func (b * Bundler ) Build (w io.Writer ) error {
119108 if err := b .prepareFiles (); err != nil {
120109 return err
121110 }
122- if err := b .prepareManifest (); err != nil {
123- return err
124- }
111+
125112 return b .archive (w )
126113}
127114
@@ -170,44 +157,14 @@ func (b *Bundler) prepareFiles() error {
170157 return nil
171158}
172159
173- // prepareManifest reads the manifest template file, replaces the placeholder
174- // "[GITHUB_SHA]" with the GitHub release version extracted from b.githubRef
175- func (b * Bundler ) prepareManifest () error {
176- const (
177- placeholder = "[GITHUB_SHA]"
178- prefix = "refs/tags/v"
179- )
180-
181- data , err := fs .ReadFile (b .fsys , filepath .Join (b .root , "checks" , ".manifest" ))
182- if err != nil {
183- return fmt .Errorf ("read .manifest: %w" , err )
184- }
185-
186- if b .githubRef != "" {
187- releaseVersion , ok := strings .CutPrefix (b .githubRef , prefix )
188- if ! ok {
189- log .Printf ("GitHub ref %q does not start with %q — using unchanged value" , b .githubRef , prefix )
190- }
191- log .Printf ("Using GitHub ref %q -> release version %q" , b .githubRef , releaseVersion )
192- data = bytes .ReplaceAll (data , []byte (placeholder ), []byte (releaseVersion ))
193- }
194-
195- b .manifest = data
196- return nil
197- }
198-
199- // archive writes all prepared files and the manifest into a compressed tar.gz archive
160+ // archive writes all prepared files into a compressed tar.gz archive
200161func (b * Bundler ) archive (w io.Writer ) error {
201162 gw := gzip .NewWriter (w )
202163 defer gw .Close ()
203164
204165 tw := tar .NewWriter (gw )
205166 defer tw .Close ()
206167
207- if err := b .writeManifest (tw ); err != nil {
208- return fmt .Errorf ("write manifest: %w" , err )
209- }
210-
211168 var added int
212169 for src , dst := range b .files {
213170 err := b .addFileToTar (tw , src , b .prefix + dst )
@@ -221,21 +178,6 @@ func (b *Bundler) archive(w io.Writer) error {
221178 return nil
222179}
223180
224- func (b * Bundler ) writeManifest (tw * tar.Writer ) error {
225- hdr := & tar.Header {
226- Name : b .prefix + ".manifest" ,
227- Mode : 0o644 ,
228- Size : int64 (len (b .manifest )),
229- }
230- if err := tw .WriteHeader (hdr ); err != nil {
231- return fmt .Errorf ("write manifest header: %w" , err )
232- }
233- if _ , err := tw .Write (b .manifest ); err != nil {
234- return fmt .Errorf ("write manifest content: %w" , err )
235- }
236- return nil
237- }
238-
239181func (b * Bundler ) addFileToTar (tw * tar.Writer , src , dst string ) error {
240182 fi , err := fs .Stat (b .fsys , src )
241183 if err != nil {
0 commit comments