Skip to content

Commit a6d8e18

Browse files
Fix env vars (#5)
* fix env-vars * rename var in test * fix failing test * empty commit
1 parent 57a897e commit a6d8e18

18 files changed

+121
-68
lines changed

scripts/pack-and-publish.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ PackAndPublish() {
44
project_root="$(dirname "$(dirname "${BASH_SOURCE[0]}")")"
55
source_path="$project_root/src"
66
output_path="$project_root/orb.yml"
7-
rm -f "$output_path"
8-
circleci orb pack "$source_path" > "$output_path"
9-
circleci orb validate "$output_path" || { echo "Orb validation failed"; exit 1; }
10-
circleci orb publish "$output_path" "infinitered/publish-docs@dev:alpha"
7+
8+
# Default version suffix
9+
version_suffix="alpha"
10+
11+
# Check if an argument is provided
12+
if [ "$#" -gt 0 ]; then
13+
version_suffix="$1"
14+
fi
15+
16+
rm -f "$output_path"
17+
circleci orb pack "$source_path" > "$output_path"
18+
circleci orb validate "$output_path" || { echo "Orb validation failed"; exit 1; }
19+
circleci orb publish "$output_path" "infinitered/publish-docs@dev:$version_suffix"
1120
}
1221

13-
PackAndPublish
22+
PackAndPublish "$@"
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
description: "Install Yarn dependencies and cache them."
22
parameters:
3-
working_directory:
3+
repo_directory:
44
type: string
5-
default: ""
6-
description: "The working directory where the repository is cloned."
5+
default: "./"
6+
description: "The directory for repository operations."
77
steps:
8-
- run:
9-
name: Compute checksum
10-
command: echo 'export YARN_LOCK_CHECKSUM=$(checksum $TARGET_REPO_DIRECTORY/yarn.lock)' >> $BASH_ENV
118
- restore_cache:
129
name: Restore Yarn Cache
1310
keys:
14-
- yarn-cache-$TARGET_REPO_DIRECTORY-{{ .Environment.YARN_LOCK_CHECKSUM }}
11+
- yarn-cache-<< parameters.repo_directory >>-{{ checksum "<< parameters.repo_directory >>/yarn.lock" }}
1512
- run:
1613
name: Use local Yarn version
1714
command: <<include(scripts/use_local_yarn_version.sh)>>
1815
- run:
1916
name: Install Dependencies
17+
working_directory: << parameters.repo_directory >>
2018
command: yarn install --immutable
2119
- save_cache:
2220
name: Save Yarn Cache
23-
key: yarn-cache-$TARGET_REPO_DIRECTORY-{{ .Environment.YARN_LOCK_CHECKSUM }}
21+
key: yarn-cache-<< parameters.repo_directory >>-{{ checksum "<< parameters.repo_directory >>/yarn.lock" }}
2422
paths:
25-
- $TARGET_REPO_DIRECTORY/.yarn/cache
23+
- << parameters.repo_directory >>/.yarn/cache

src/jobs/build_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ steps:
6060
command: <<include(scripts/log_env_vars.sh)>>
6161
- clone_required_repos
6262
- install_and_cache_yarn_dependencies:
63-
working_directory: <<parameters.target_repo_directory>>
63+
repo_directory: <<parameters.target_repo_directory>>
6464
- copy_docs_to_target
6565
- build_docusaurus

src/scripts/check_docs_exist.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
#! /bin/bash
2-
1+
#!/bin/bash
32

43
CheckDocsExist() {
54
# Parameters: Source docs path
65
echo "Checking if documents exist in the source directory."
76

87
# Check if the directory exists
9-
if [ ! -d "$SOURCE_DOCS_PATH" ]; then
10-
echo "Error: Directory $SOURCE_DOCS_PATH does not exist."
8+
if [ ! -d "$FULL_SOURCE_DOCS_PATH" ]; then
9+
echo "Error: Directory $FULL_SOURCE_DOCS_PATH does not exist."
1110
exit 1
1211
fi
1312

1413
# Check if the directory is empty
15-
if [ ! "$(ls -A "$SOURCE_DOCS_PATH")" ]; then
14+
if [ ! "$(ls -A "$FULL_SOURCE_DOCS_PATH")" ]; then
1615
echo "Error: No files found in docs directory."
1716
exit 1
1817
fi
1918
}
2019

21-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
20+
ORB_TEST_ENV="bats-core"
21+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
22+
# shellcheck source=/dev/null
2223
CheckDocsExist
2324
fi

src/scripts/clone_required_repos.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
#! /bin/bash
1+
#!/bin/bash
2+
3+
# Function to log environment variables
4+
LogEnvironmentVariables() {
5+
echo "Logging Environment Variables:"
6+
echo "CIRCLE_REPOSITORY_URL: $CIRCLE_REPOSITORY_URL"
7+
echo "SOURCE_REPO_DIRECTORY: $SOURCE_REPO_DIRECTORY"
8+
echo "TARGET_REPO: $TARGET_REPO"
9+
echo "TARGET_REPO_DIRECTORY: $TARGET_REPO_DIRECTORY"
10+
echo "GIT_USERNAME: $GIT_USERNAME"
11+
echo "GIT_EMAIL: $GIT_EMAIL"
12+
echo "-----------------------------"
13+
}
214

315
# Function to set the Git username and email
416
SetGitUser() {
@@ -24,12 +36,19 @@ CloneSourceRepo() {
2436
CloneTargetRepo() {
2537
echo "Cloning target repository from $TARGET_REPO to $TARGET_REPO_DIRECTORY"
2638
git clone "$TARGET_REPO" "$TARGET_REPO_DIRECTORY" || { echo "Failed to clone target repository"; exit 1; }
39+
ls "$TARGET_REPO_DIRECTORY"
2740
}
2841

2942
# Check if the script is being sourced or executed directly
30-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
43+
ORB_TEST_ENV="bats-core"
44+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
45+
LogEnvironmentVariables
46+
echo "Script is being executed directly"
47+
3148
SetGitUser
3249
AddGithubToKnownHosts
3350
CloneSourceRepo
3451
CloneTargetRepo
52+
else
53+
echo "Script is being sourced"
3554
fi

src/scripts/commit_and_push_to_target.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ git commit -m "\"$FINAL_COMMIT_MESSAGE\"" || { echo "Git commit failed"; exit 1;
88
git push origin main || { echo "Git push failed"; exit 1; }
99
}
1010

11-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
11+
ORB_TEST_ENV="bats-core"
12+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
1213
CommitAndPushToTarget
1314
fi

src/scripts/copy_docs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
CopyDocs() {
44
echo "Copying documents to the target repository."
5-
cp -R "$SOURCE_DOCS_PATH" "$TARGET_REPO_DIRECTORY/$TARGET_DOCS_PATH/$PROJECT_NAME"
5+
cp -R "$FULL_SOURCE_DOCS_PATH" "$TARGET_REPO_DIRECTORY/$TARGET_DOCS_PATH/$PROJECT_NAME"
66
echo "Documents copied successfully."
77
}
88

9-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
9+
ORB_TEST_ENV="bats-core"
10+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
1011
CopyDocs
1112
fi
1213

src/scripts/create_category_json.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
#! /bin/bash
2-
# Parameters: Project name, Label, Description
1+
#!/bin/bash
32

4-
CreateCategoryJSON() {
5-
echo "Creating _category_.json file."
6-
echo "
7-
\{
8-
\"label\": \"$LABEL\",
9-
\"link\": \{
10-
\"type\": \"generated-index\",
11-
\"description\": \"$DESCRIPTION\"
12-
\}
13-
\}
14-
" > "$TARGET_REPO_DIRECTORY/docs/$PROJECT_NAME/_category_.json"
3+
# Assumes LABEL, DESCRIPTION, TARGET_REPO_DIRECTORY, and PROJECT_NAME are environment variables
154

16-
echo "_category_.json file created successfully."
5+
CreateCategoryJSONFromTemplate() {
6+
# Inlined template with placeholders
7+
# shellcheck disable=SC2016
8+
TEMPLATE='{"label": "${LABEL}","link": {"type": "generated-index","description": "${DESCRIPTION}"}}'
9+
10+
# Substitute the variables in the template and write to target location
11+
echo "$TEMPLATE" | sed \
12+
-e "s/\${LABEL}/$LABEL/" \
13+
-e "s/\${DESCRIPTION}/$DESCRIPTION/" \
14+
> "$TARGET_REPO_DIRECTORY/docs/$PROJECT_NAME/_category_.json"
15+
16+
echo "_category_.json file created successfully."
1717
}
1818

19-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
20-
CreateCategoryJSON
19+
# Check for bats
20+
ORB_TEST_ENV="bats-core"
21+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
22+
CreateCategoryJSONFromTemplate
2123
fi
22-

src/scripts/docusaurus_build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ echo "Running Docusaurus build..."
77
yarn build || { echo "Docusaurus build failed"; exit 1; }
88
}
99

10-
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
10+
ORB_TEST_ENV="bats-core"
11+
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
1112
DocusaurusBuild
1213
fi

src/scripts/log_env_vars.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

33
# Construct paths with $CIRCLE_WORKING_DIRECTORY
4-
FULL_SOURCE_DOCS_PATH="${CIRCLE_WORKING_DIRECTORY}/${SOURCE_REPO_DIRECTORY_PARAM}/${SOURCE_DOCS_DIR}"
5-
SOURCE_REPO_DIRECTORY="${CIRCLE_WORKING_DIRECTORY}/${SOURCE_REPO_DIRECTORY_PARAM}"
6-
TARGET_REPO_DIRECTORY="${CIRCLE_WORKING_DIRECTORY}/${TARGET_REPO_DIRECTORY_PARAM}"
4+
FULL_SOURCE_DOCS_PATH=$(eval echo "${CIRCLE_WORKING_DIRECTORY}/${SOURCE_REPO_DIRECTORY_PARAM}/${SOURCE_DOCS_DIR}")
5+
SOURCE_REPO_DIRECTORY=$(eval echo "${CIRCLE_WORKING_DIRECTORY}/${SOURCE_REPO_DIRECTORY_PARAM}")
6+
TARGET_REPO_DIRECTORY=$(eval echo "${CIRCLE_WORKING_DIRECTORY}/${TARGET_REPO_DIRECTORY_PARAM}")
77

88
{
99
# Set environment variables for subsequent steps

0 commit comments

Comments
 (0)