@@ -58,6 +58,9 @@ function setup_environment() {
5858 elif [[ -n " ${GITHUB_WORKSPACE: +x} " ]]; then
5959 # GitHub Actions
6060 RELATIVE_PATH=" ${GITHUB_WORKSPACE} "
61+ elif [[ -n " ${BITBUCKET_CLONE_DIR: +x} " ]]; then
62+ # BitBucket Pipelines
63+ RELATIVE_PATH=" ${BITBUCKET_CLONE_DIR} "
6164 elif [[ -d " /src/.git" ]]; then
6265 # Pre-commit
6366 RELATIVE_PATH=" /src"
@@ -66,7 +69,15 @@ function setup_environment() {
6669 exit 1
6770 fi
6871
69- export REPO_DICTIONARY=" ${RELATIVE_PATH} /.github/etc/dictionary.txt"
72+ if [[ -r " ${RELATIVE_PATH} /.github/etc/dictionary.txt" ]]; then
73+ # GitHub
74+ export REPO_DICTIONARY=" ${RELATIVE_PATH} /.github/etc/dictionary.txt"
75+ elif [[ -r " ${RELATIVE_PATH} /dictionary.txt" ]]; then
76+ export REPO_DICTIONARY=" ${RELATIVE_PATH} /dictionary.txt"
77+ else
78+ feedback ERROR " Unable to find the dictionary file"
79+ exit 1
80+ fi
7081
7182 if [[ -n ${JSCPD_CONFIG: +x} ]]; then
7283 feedback WARNING " JSCPD_CONFIG is set; not auto ignoring the goat submodule..."
@@ -125,15 +136,23 @@ function setup_environment() {
125136}
126137
127138function check_environment() {
128- # Check the GITHUB_BASE_REF (PRs only)
129- if [[ ${GITHUB_ACTIONS:- false} == " true" && -n ${GITHUB_BASE_REF: +x} ]]; then
139+ # Check PRs for the main branch
140+ local wrong_destination_branch=" false"
141+
142+ if [[ -n ${BITBUCKET_PR_DESTINATION_BRANCH: +x} && " ${BITBUCKET_PR_DESTINATION_BRANCH} " != " main" ]]; then
143+ wrong_destination_branch=" true"
144+ elif [[ ${GITHUB_ACTIONS:- false} == " true" && -n ${GITHUB_BASE_REF: +x} ]]; then
130145 mainline=" ${GITHUB_BASE_REF##*/ } "
131146 if [[ ${mainline} != " main" ]]; then
132- feedback ERROR " Base branch name is not main"
133- exit 1
147+ wrong_destination_branch=" true"
134148 fi
135149 fi
136150
151+ if [[ " ${wrong_destination_branch} " == " true" ]]; then
152+ feedback ERROR " Base branch name is not main"
153+ exit 1
154+ fi
155+
137156 # Ensure there is a repo dictionary
138157 if [[ ! -r " ${REPO_DICTIONARY} " ]]; then
139158 feedback ERROR " Unable to read a repo dictionary at ${REPO_DICTIONARY} ; does it exist?"
@@ -213,8 +232,13 @@ function get_files_matching_filetype() {
213232 fi
214233 fi
215234 if [ " $linter_name " == " actionlint" ]; then
216- local action_path=" ${GITHUB_WORKSPACE:- .} /.github/workflows/"
217- if [[ " ${file} " != " ${action_path} " * ]]; then
235+ if [[ -n " ${GITHUB_WORKSPACE: +x} " ]]; then
236+ local action_path=" ${GITHUB_WORKSPACE:- .} /.github/workflows/"
237+ if [[ " ${file} " != " ${action_path} " * ]]; then
238+ continue
239+ fi
240+ else
241+ # Skip actionlint if not running in a GitHub Action
218242 continue
219243 fi
220244 fi
@@ -303,15 +327,26 @@ function lint_files() {
303327function seiso_lint() {
304328 echo -e " \nRunning Seiso Linter\n--------------------------\n"
305329
306- if [[ -n ${GITHUB_WORKSPACE:- } ]]; then
307- echo " Setting ${GITHUB_WORKSPACE} as safe directory"
308- git config --global --add safe.directory " ${GITHUB_WORKSPACE} "
330+ if [[ -n ${GITHUB_WORKSPACE: +x} ]]; then
331+ # GitHub Actions
332+ local safe_directory=" ${GITHUB_WORKSPACE} "
333+ elif [[ -n ${BITBUCKET_CLONE_DIR: +x} ]]; then
334+ # BitBucket Pipelines
335+ local safe_directory=" ${BITBUCKET_CLONE_DIR} "
336+ else
337+ feedback ERROR " Unable to identify a directory to set as safe"
338+ exit 1
309339 fi
310340
341+ echo " Setting ${safe_directory} as safe directory"
342+ git config --global --add safe.directory " ${safe_directory} "
343+
311344 # When run in a pipeline, move per-repo configurations into the right location at runtime so the goat finds them, overwriting the defaults.
312345 # This will handle hidden and non-hidden files, as well as sym links
313346 if [[ -d " ${GITHUB_WORKSPACE:- .} /.github/linters" ]]; then
314347 cp -p " ${GITHUB_WORKSPACE:- .} /.github/linters/" * " ${GITHUB_WORKSPACE:- .} /.github/linters/" .* /etc/opt/goat/ 2> /dev/null || true
348+ elif [[ -d " ${BITBUCKET_CLONE_DIR:- .} /linters" ]]; then
349+ cp -p " ${BITBUCKET_CLONE_DIR:- .} /linters/" * " ${BITBUCKET_CLONE_DIR:- .} /linters/" .* /etc/opt/goat/ 2> /dev/null || true
315350 fi
316351
317352 excluded=()
0 commit comments