diff --git a/.github/workflows/reusable-CI-workflow.yml b/.github/workflows/reusable-CI-workflow.yml index ce1a511..2ab6795 100644 --- a/.github/workflows/reusable-CI-workflow.yml +++ b/.github/workflows/reusable-CI-workflow.yml @@ -3,10 +3,6 @@ name: 'CI reusable workflow' on: workflow_call: -env: - TEST_OUTPUT_STYLE: pretty - COMPOSER_OPTIONS: --optimize-autoloader - jobs: coverage: name: Go @@ -30,7 +26,7 @@ jobs: - name: Create coverage group id: tests-coverage-group - uses: yoanm/temp-reports-group-workspace/gha-create@v0 + uses: yoanm/temp-reports-group-workspace/create-group@v0 with: format: clover files: coverage.out diff --git a/.github/workflows/reusable-coverage-upload-workflow.yml b/.github/workflows/reusable-coverage-upload-workflow.yml index ca11475..7d26e8a 100644 --- a/.github/workflows/reusable-coverage-upload-workflow.yml +++ b/.github/workflows/reusable-coverage-upload-workflow.yml @@ -17,17 +17,19 @@ jobs: checks: write # For the check run creation ! steps: - name: 'Check run ○' - uses: yoanm/temp-reports-group-workspace/gha-attach-check-run-to-triggering-workflow@v0 + uses: yoanm/temp-reports-group-workspace/utils/attach-check-run-to-triggering-workflow@v0 with: - name: 'Fetch coverage info' + name: 'Fetch triggering workflow metadata' fails-on-triggering-workflow-failure: true - - uses: yoanm/temp-reports-group-workspace/gha-fetch-workflow-metadata@v0 + - uses: yoanm/temp-reports-group-workspace/utils/fetch-workflow-metadata@v0 id: fetch-workflow-metadata outputs: commit-sha: ${{ steps.fetch-workflow-metadata.outputs.commit-sha }} run-id: ${{ steps.fetch-workflow-metadata.outputs.run-id }} + branch: ${{ steps.fetch-workflow-metadata.outputs.branch }} + pull-request: ${{ steps.fetch-workflow-metadata.outputs.pull-request }} codacy-uploader: name: Codacy @@ -39,7 +41,7 @@ jobs: secrets: PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} with: - artifact: coverage-group + artifacts-pattern: coverage-group run-id: ${{ needs.fetch-info.outputs.run-id }} force-git-commit: ${{ needs.fetch-info.outputs.commit-sha }} force-uploader-language: go @@ -56,10 +58,10 @@ jobs: secrets: TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - artifact: coverage-group + artifacts-pattern: coverage-group run-id: ${{ needs.fetch-info.outputs.run-id }} force-git-commit: ${{ needs.fetch-info.outputs.commit-sha }} force-git-branch: ${{ needs.fetch-info.outputs.branch }} - force-gh-pr: ${{ needs.fetch-info.outputs.pr-number }} + force-gh-pr: ${{ needs.fetch-info.outputs.pull-request }} force-uploader-build: ${{ needs.fetch-info.outputs.run-id }} force-uploader-build-url: ${{ needs.fetch-info.outputs.run-url }} diff --git a/errors.go b/errors.go index 73c1ed7..b936615 100644 --- a/errors.go +++ b/errors.go @@ -16,8 +16,6 @@ var ( errInputDirectoryDoesntExist = errors.New("input directory doesn't exist") errRepositoryAlreadyImported = errors.New("repository already imported") - - errPathIsNotADirectory = errors.New("path is not a directory") ) func workspaceLoadingError(errList []error) error { @@ -52,7 +50,3 @@ func alreadyImportedRepositoryError(repoName string, filepathList []string) erro strings.Join(filepathList, ", "), ) } - -func pathIsNotADirectoryError(path string) error { - return fmt.Errorf("%w: %s", errPathIsNotADirectory, path) -} diff --git a/fshelper.go b/fshelper.go deleted file mode 100644 index 24b32d2..0000000 --- a/fshelper.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "os" -) - -func readDirectory(rootPath string) ([]string, error) { - directory, dirErr := openDirectory(rootPath) - if dirErr != nil { - return nil, dirErr - } - - //nolint:wrapcheck // Expected to return error as is - return directory.Readdirnames(0) -} - -func openDirectory(path string) (*os.File, error) { - directory, readErr := os.Open(path) - if readErr != nil { - //nolint:wrapcheck // Expected to return error as is - return nil, readErr - } - - directoryStat, statErr := directory.Stat() - if statErr != nil { - //nolint:wrapcheck // Expected to return error as is - return nil, statErr - } - - if !directoryStat.IsDir() { - return nil, pathIsNotADirectoryError(path) - } - - return directory, nil -} diff --git a/testdata/write/loading-errors/multiple-unknown-files/base.ct b/testdata/write/loading-errors/multiple-unknown-files/base.ct index 727e16e..d1a98ee 100644 --- a/testdata/write/loading-errors/multiple-unknown-files/base.ct +++ b/testdata/write/loading-errors/multiple-unknown-files/base.ct @@ -6,8 +6,8 @@ Debug | Template directory: templates Debug | YAML anchor directory: yaml-anchors Debug | Reading repository directory: config/repos Debug | config/repos/unknown_file.txt is not a YAML template => ignored -Debug | config/unknown_file.txt is not a known file or directory => ignored Debug | config/unknown_dir is not a known file or directory => ignored +Debug | config/unknown_file.txt is not a known file or directory => ignored Debug | Reading template directory: templates Debug | templates/test.unknown_template_type.yml is not a known template type => ignored Debug | templates/unknown_file.txt is not a YAML template => ignored diff --git a/workspace.go b/workspace.go index 67080de..6059808 100644 --- a/workspace.go +++ b/workspace.go @@ -61,14 +61,19 @@ func readConfigDirectory(config *core.Config, rootPath string, decoderOpts []yam } var ( - filenames []string - readErr error + files []os.DirEntry + readErr error ) - if filenames, readErr = readDirectory(rootPath); readErr != nil { + if files, readErr = os.ReadDir(rootPath); readErr != nil { return configDirectoryLoadingError([]error{readErr}) } + filenames := make([]string, 0, len(files)) + for _, file := range files { + filenames = append(filenames, file.Name()) + } + return loadConfigDirectoryFiles(config, rootPath, decoderOpts, filenames) } @@ -164,7 +169,7 @@ func readRepositoryDirectory( ) (map[string]string, map[string]error) { dirName := filepath.Base(rootPath) - filenames, readErr := readDirectory(rootPath) + files, readErr := os.ReadDir(rootPath) if readErr != nil { return nil, map[string]error{dirName: readErr} } @@ -174,10 +179,10 @@ func readRepositoryDirectory( log.Debug().Msgf("Reading repository directory: %s", rootPath) - for _, filename := range filenames { - filePath := filepath.Join(rootPath, filename) + for _, file := range files { + filePath := filepath.Join(rootPath, file.Name()) - ext := filepath.Ext(filename) + ext := filepath.Ext(file.Name()) if ext == ".yml" || ext == ".yaml" { repoConfig, loadErr := core.LoadRepositoryFromFile(filePath, decoderOpts...) if loadErr != nil { @@ -205,14 +210,14 @@ func readTemplateDirectory( return nil } - dirContents, readErr := readDirectory(rootPath) + files, readErr := os.ReadDir(rootPath) if readErr == nil { log.Debug().Msgf("Reading template directory: %s", rootPath) errList := map[string]error{} - for _, filename := range dirContents { - readTemplateDirectoryFile(config, filepath.Join(rootPath, filename), decoderOpts, errList) + for _, file := range files { + readTemplateDirectoryFile(config, filepath.Join(rootPath, file.Name()), decoderOpts, errList) } if len(errList) > 0 {