diff --git a/.github/workflows/registry-updates.yaml b/.github/workflows/registry-updates.yaml index dc259063..720e346e 100644 --- a/.github/workflows/registry-updates.yaml +++ b/.github/workflows/registry-updates.yaml @@ -45,36 +45,27 @@ jobs: run: | cat changed_files.txt - # - name: Get the actual changes in the files - # run: | - # echo "Fetching actual changes ..." - # while read -r FILE; do - # echo "Changes in $FILE: " - # git diff $BASE_SHA $HEAD_SHA -- "$FILE" - # done < changed_files.txt - # env: - # BASE_SHA: ${{ steps.list_files.outputs.base }} - # HEAD_SHA: ${{ steps.list_files.outputs.head }} - - # - name: Pseudocode for Next steps - # id: next_steps - # run: | - # echo 'Detect status - added/modified/removed files' - # echo 'for each removed connector, remove from registry db' - # echo 'for each added connector, create a stub in the registry db' - # echo 'for each modified connector:' - # echo ' * Download tgz' - # echo ' * Re-upload tgz' - # echo ' * Extract' - # echo ' * Build payload for API' - # echo ' * PUT to API (gql)' + - name: Pseudocode for Next steps + id: next_steps + run: | + echo 'Detect status - added/modified/removed files' + echo 'for each removed connector, remove from registry db' + echo 'for each added connector, create a stub in the registry db' + echo 'for each modified connector:' + echo ' * Download tgz' + echo ' * Re-upload tgz' + echo ' * Extract' + echo ' * Build payload for API' + echo ' * PUT to API (gql)' - # - name: Setup Go - # uses: actions/setup-go@v4 - # with: - # go-version: 1.21.x + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.21.x - # - name: Run registry automaion program - # run: | - # cd registry-automation - # go run main.go ci + - name: Run registry automation program + env: + CHANGED_FILES_PATH: "changed_files.txt" + run: | + cd registry-automation + go run main.go ci diff --git a/registry-automation/cmd/ci.go b/registry-automation/cmd/ci.go index 6b7b21d3..bbad5fce 100644 --- a/registry-automation/cmd/ci.go +++ b/registry-automation/cmd/ci.go @@ -4,7 +4,6 @@ Copyright © 2024 Hasura package cmd import ( - "bufio" "context" "encoding/json" "fmt" @@ -30,13 +29,19 @@ var ciCmd = &cobra.Command{ Run: runCI, } +type ChangedFiles struct { + Added []string `json:"added_files"` + Modified []string `json:"modified_files"` + Deleted []string `json:"deleted_files"` +} + func init() { rootCmd.AddCommand(ciCmd) // Path for the changed files in the PR - var cfpE = os.Getenv(`CHANGED_FILES_PATH`) - ciCmd.PersistentFlags().String("changed-files-path", cfpE, "path to a line-separated list of changed files in the PR") - if cfpE == "" { + var changedFilesPathEnv = os.Getenv(`CHANGED_FILES_PATH`) + ciCmd.PersistentFlags().String("changed-files-path", changedFilesPathEnv, "path to a line-separated list of changed files in the PR") + if changedFilesPathEnv == "" { ciCmd.MarkPersistentFlagRequired("changed-files-path") } @@ -55,28 +60,53 @@ func runCI(cmd *cobra.Command, args []string) { // For each connector where a change is detected... - var changed_files = map[string]bool{} + // var changed_files = map[string]bool{} + // var changed_files_path = cmd.PersistentFlags().Lookup("changed-files-path").Value.String() + // file, err := os.Open(changed_files_path) + // if err != nil { + // log.Fatal(err) + // } + // defer file.Close() + + // scanner := bufio.NewScanner(file) + // for scanner.Scan() { + // changed_files[filepath.Dir(scanner.Text())] = true // Just assume we'll treat each connector as if everything has changed. + // } + + // if err := scanner.Err(); err != nil { + // panic(err) + // } + + // var hub_directory = cmd.PersistentFlags().Lookup("connector-hub-directory").Value.String() + + // for k := range changed_files { + // respondToChangedConnector(path.Join(hub_directory, k)) + // } + var changed_files_path = cmd.PersistentFlags().Lookup("changed-files-path").Value.String() - file, err := os.Open(changed_files_path) - if err != nil { - log.Fatal(err) + changedFilesContent, err := os.Open(changed_files_path) + + if err!= nil { + log.Fatalf("Failed to open the file: %v, err: %v", changed_files_path, err) } - defer file.Close() - scanner := bufio.NewScanner(file) - for scanner.Scan() { - changed_files[filepath.Dir(scanner.Text())] = true // Just assume we'll treat each connector as if everything has changed. + defer changedFilesContent.Close() + + // Read the file's contents + changedFilesByteValue, err := ioutil.ReadAll(changedFilesContent) + if err != nil { + log.Fatalf("Failed to read JSON file: %v", err) } - if err := scanner.Err(); err != nil { - panic(err) + var changedFiles ChangedFiles + err = json.Unmarshal(changedFilesByteValue, &changedFiles) + if err != nil { + log.Fatalf("Failed to unmarshal JSON: %v", err) } - var hub_directory = cmd.PersistentFlags().Lookup("connector-hub-directory").Value.String() + fmt.Printf("Parsed JSON: \n%+v\n", changedFiles) + - for k := range changed_files { - respondToChangedConnector(path.Join(hub_directory, k)) - } }