@@ -142,33 +142,20 @@ func updateLocalFile(orgName, sectionContent string) error {
142142 outputPath = ".github/README.md"
143143 }
144144
145- // Ensure directory exists
146- dir := filepath .Dir (outputPath )
147- if err := os .MkdirAll (dir , 0755 ); err != nil {
148- return fmt .Errorf ("failed to create directory %s: %w" , dir , err )
145+ // Update the specified output file
146+ if err := writeReadmeFile (outputPath , orgName , sectionContent ); err != nil {
147+ return err
149148 }
150149
151- // Read existing content or create new
152- var newContent string
153- if _ , err := os .Stat (outputPath ); err == nil {
154- // File exists, update section
155- existingContent , err := os .ReadFile (outputPath )
156- if err != nil {
157- return fmt .Errorf ("failed to read existing file: %w" , err )
150+ // Also update profile/README.md if output is under a .github directory
151+ outputDir := filepath .Dir (outputPath )
152+ if filepath .Base (outputDir ) == ".github" {
153+ profilePath := filepath .Join (outputDir , "profile" , "README.md" )
154+ if err := writeReadmeFile (profilePath , orgName , sectionContent ); err != nil {
155+ return err
158156 }
159- newContent = updateSectionInContent (string (existingContent ), sectionContent , updateOrgStatusSection )
160- } else {
161- // File doesn't exist, create full README
162- newContent = generateFullREADME (orgName , sectionContent )
163157 }
164158
165- // Write file
166- if err := os .WriteFile (outputPath , []byte (newContent ), 0644 ); err != nil {
167- return fmt .Errorf ("failed to write README: %w" , err )
168- }
169-
170- fmt .Printf ("Updated: %s\n " , outputPath )
171-
172159 // Git operations (unless skipped)
173160 if ! updateOrgStatusSkipPush {
174161 if err := gitCommitAndPush (outputPath , orgName ); err != nil {
@@ -198,36 +185,18 @@ func updateDotGitHubRepo(orgName, sectionContent string) error {
198185 return fmt .Errorf ("failed to clone .github repository: %w\n Note: Make sure the .github repository exists and is accessible" , err )
199186 }
200187
201- // Determine README path (profile/ README.md or README.md)
202- readmePath := filepath . Join ( repoDir , "profile" , "README.md" )
203- if _ , err := os . Stat ( readmePath ); os . IsNotExist ( err ) {
204- readmePath = filepath .Join (repoDir , "README.md" )
188+ // Update both README.md and profile/ README.md
189+ paths := [] string {
190+ filepath . Join ( repoDir , "README.md" ),
191+ filepath .Join (repoDir , "profile" , " README.md" ),
205192 }
206193
207- // Read existing content or create new
208- var newContent string
209- if _ , err := os .Stat (readmePath ); err == nil {
210- existingContent , err := os .ReadFile (readmePath )
211- if err != nil {
212- return fmt .Errorf ("failed to read existing README: %w" , err )
194+ for _ , readmePath := range paths {
195+ if err := writeReadmeFile (readmePath , orgName , sectionContent ); err != nil {
196+ return err
213197 }
214- newContent = updateSectionInContent (string (existingContent ), sectionContent , updateOrgStatusSection )
215- } else {
216- newContent = generateFullREADME (orgName , sectionContent )
217- }
218-
219- // Ensure directory exists
220- if err := os .MkdirAll (filepath .Dir (readmePath ), 0755 ); err != nil {
221- return fmt .Errorf ("failed to create directory: %w" , err )
222198 }
223199
224- // Write file
225- if err := os .WriteFile (readmePath , []byte (newContent ), 0644 ); err != nil {
226- return fmt .Errorf ("failed to write README: %w" , err )
227- }
228-
229- fmt .Printf ("Updated: %s\n " , readmePath )
230-
231200 // Git operations in .github repo
232201 if updateOrgStatusSkipPush {
233202 fmt .Println ("Skipping git push (--skip-push used)" )
@@ -273,6 +242,31 @@ func updateDotGitHubRepo(orgName, sectionContent string) error {
273242 return nil
274243}
275244
245+ func writeReadmeFile (readmePath , orgName , sectionContent string ) error {
246+ // Ensure directory exists
247+ if err := os .MkdirAll (filepath .Dir (readmePath ), 0755 ); err != nil {
248+ return fmt .Errorf ("failed to create directory: %w" , err )
249+ }
250+
251+ var newContent string
252+ if _ , err := os .Stat (readmePath ); err == nil {
253+ existingContent , err := os .ReadFile (readmePath )
254+ if err != nil {
255+ return fmt .Errorf ("failed to read existing README: %w" , err )
256+ }
257+ newContent = updateSectionInContent (string (existingContent ), sectionContent , updateOrgStatusSection )
258+ } else {
259+ newContent = generateFullREADME (orgName , sectionContent )
260+ }
261+
262+ if err := os .WriteFile (readmePath , []byte (newContent ), 0644 ); err != nil {
263+ return fmt .Errorf ("failed to write README: %w" , err )
264+ }
265+
266+ fmt .Printf ("Updated: %s\n " , readmePath )
267+ return nil
268+ }
269+
276270func updateSectionInContent (content , newSection , sectionName string ) string {
277271 sectionHeader := "## " + sectionName
278272
0 commit comments