Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/commands/commit_and_push_to_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ description: >
"Commits and pushes the updated documentation to the docs repository."

steps:
- run:
name: Parse commit message and PR number
command: <<include(scripts/parse_commit_info.sh)>>
- run:
name: Commit and push to target repository
command: <<include(scripts/commit_and_push_to_target.sh)>>
6 changes: 6 additions & 0 deletions src/commands/extract_github_org_and_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: >
"Extracts GitHub organization and repository name from the repository URL."
steps:
- run:
name: "Extract GitHub Organization and Repository"
command: <<include(scripts/extract_github_org_and_repo.sh)>>
6 changes: 6 additions & 0 deletions src/commands/fetch_commit_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: >
"Fetch the last commit message and commit hash from the source repository."
steps:
- run:
name: "Fetch Commit Info"
command: <<include(scripts/fetch_commit_info.sh)>>
6 changes: 6 additions & 0 deletions src/commands/generate_commit_message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: >
"Constructs the final commit message incorporating all relevant details and links."
steps:
- run:
name: "Generate Commit Message"
command: <<include(scripts/generate_commit_message.sh)>>
6 changes: 6 additions & 0 deletions src/commands/normalize_repository_url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: >
"Normalizes the GitHub URL for use in later parts of the script."
steps:
- run:
name: "Normalize Repository URL"
command: <<include(scripts/normalize_repository_url.sh)>>
File renamed without changes.
32 changes: 32 additions & 0 deletions src/examples/references.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description: >
You can reduce repetition by defining props in a YAML anchor and referencing it later.

usage:
version: 2.1
orbs:
publish-docs: infinitered/publish-docs@x.y.z # Replace with the actual version

# Define common parameters
common_params: &publish_docs_params
description: "The description that will appear on autogenerated indexes and components."
git_email: "your.ci@email.here"
git_username: "Your CI Username"
label: "The label that will appear in the sidebar of the docs site."
project_name: 'name-of-project'
source_docs_dir: "docs"
source_repo_directory: "source"
target_docs_dir: "docs"
target_repo: "git@github.com:your-org/your-repo.git"
target_repo_directory: "target"

workflows:
build_docs:
jobs:
- publish-docs/build_docs:
# this will expand to all the parameters defined in the anchor
<<: *publish_docs_params
publish_to_docs_site:
jobs:
- publish-docs/publish_docs:
# this will expand to all the parameters defined in the anchor
<<: *publish_docs_params
4 changes: 4 additions & 0 deletions src/jobs/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ steps:
repo_directory: <<parameters.target_repo_directory>>
- copy_docs_to_target
- build_docusaurus
- fetch_commit_info
- normalize_repository_url
- extract_github_org_and_repo
- generate_commit_message
- commit_and_push_to_target
7 changes: 4 additions & 3 deletions src/scripts/check_docs_exist.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/bin/bash

# Function to check if documents exist in the source directory
CheckDocsExist() {
# Parameters: Source docs path
echo "Checking if documents exist in the source directory."
echo "Checking if documents exist in the source directory." >&2

# Check if the directory exists
if [ ! -d "$FULL_SOURCE_DOCS_PATH" ]; then
echo "Error: Directory $FULL_SOURCE_DOCS_PATH does not exist."
echo "Error: Directory $FULL_SOURCE_DOCS_PATH does not exist." >&2
exit 1
fi

# Check if the directory is empty
if [ ! "$(ls -A "$FULL_SOURCE_DOCS_PATH")" ]; then
echo "Error: No files found in docs directory."
echo "Error: No files found in docs directory." >&2
exit 1
fi
}
Expand Down
12 changes: 5 additions & 7 deletions src/scripts/clone_required_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ LogEnvironmentVariables() {

# Function to set the Git username and email
SetGitUser() {
echo "Configuring Git username and email: $GIT_USERNAME -- $GIT_EMAIL"
echo "Configuring Git username and email: $GIT_USERNAME -- $GIT_EMAIL" >&2
git config --global user.name "$GIT_USERNAME" || { echo "Failed to configure Git username"; exit 1; }
git config --global user.email "$GIT_EMAIL" || { echo "Failed to configure Git email"; exit 1; }
}

# Function to add github.com to known SSH hosts
AddGithubToKnownHosts() {
echo "Adding github.com to known SSH hosts"
echo "Adding github.com to known SSH hosts" >&2
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts || { echo "Failed to add github.com to known hosts"; exit 1; }
}

# Function to clone the source repository
CloneSourceRepo() {
echo "Cloning the $CIRCLE_BRANCH branch of source repository ($CIRCLE_REPOSITORY_URL) to $SOURCE_REPO_DIRECTORY"
echo "Cloning the $CIRCLE_BRANCH branch of source repository ($CIRCLE_REPOSITORY_URL) to $SOURCE_REPO_DIRECTORY" >&2
git clone --branch "$CIRCLE_BRANCH" "$CIRCLE_REPOSITORY_URL" "$SOURCE_REPO_DIRECTORY" || { echo "Failed to clone source repository"; exit 1; }
}

# Function to clone the target repository
CloneTargetRepo() {
echo "Cloning target repository from $TARGET_REPO to $TARGET_REPO_DIRECTORY"
echo "Cloning target repository from $TARGET_REPO to $TARGET_REPO_DIRECTORY" >&2
git clone "$TARGET_REPO" "$TARGET_REPO_DIRECTORY" || { echo "Failed to clone target repository"; exit 1; }
ls "$TARGET_REPO_DIRECTORY"
}
Expand All @@ -43,12 +43,10 @@ CloneTargetRepo() {
ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
LogEnvironmentVariables
echo "Script is being executed directly"
echo "Script is being executed directly" >&2

SetGitUser
AddGithubToKnownHosts
CloneSourceRepo
CloneTargetRepo
else
echo "Script is being sourced"
fi
19 changes: 9 additions & 10 deletions src/scripts/commit_and_push_to_target.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#! /bin/bash

CommitAndPushToTarget () {
cd "$TARGET_REPO_DIRECTORY" || { echo "Changing directory failed"; exit 1; }
# Function to commit and push changes to the target repository
CommitAndPushToTarget() {
cd "$TARGET_REPO_DIRECTORY" || { echo "Changing directory failed" >&2; exit 1; }

git add docs || { echo "Git add docs failed"; exit 1; }
git add static || { echo "Git add static failed"; exit 1; }
git add docs || { echo "Git add docs failed" >&2; exit 1; }
git add static || { echo "Git add static failed" >&2; exit 1; }

if git diff-index --quiet HEAD --; then
echo "No changes"
echo "No changes" >&2
exit 0

echo "FINAL_COMMIT_MESSAGE: $FINAL_COMMIT_MESSAGE"

else
git commit -m "$FINAL_COMMIT_MESSAGE" || { echo "Git commit failed"; exit 1; }
git push origin main || { echo "Git push failed"; exit 1; }
git commit -m "$FINAL_COMMIT_MESSAGE" || { echo "Git commit failed" >&2; exit 1; }
git push origin main || { echo "Git push failed" >&2; exit 1; }
fi
}

ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
echo "Final Commit Message: '$FINAL_COMMIT_MESSAGE'"
echo "Final Commit Message: '$FINAL_COMMIT_MESSAGE'" >&2
CommitAndPushToTarget
fi
27 changes: 15 additions & 12 deletions src/scripts/copy_docs.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
#! /bin/bash

# Function to clear the target repository
ClearTarget() {
echo "Clearing the target repository at: $FULL_TARGET_DOCS_PATH/$PROJECT_NAME"
echo "Clearing the target repository at: $FULL_TARGET_DOCS_PATH/$PROJECT_NAME" >&2

# Check if the target path exists
if [ -d "$FULL_TARGET_DOCS_PATH/$PROJECT_NAME" ]; then
# Remove all content at the target path
rm -rf "${FULL_TARGET_DOCS_PATH:?}/$PROJECT_NAME"
echo "Existing docs at ${FULL_TARGET_DOCS_PATH:?}/$PROJECT_NAME removed."
echo "Existing docs at ${FULL_TARGET_DOCS_PATH:?}/$PROJECT_NAME removed." >&2
else
echo "The target directory does not yet exist and will be created."
echo "The target directory does not yet exist and will be created." >&2
fi
}

# Function to copy documents to the target repository
CopyDocs() {
echo "Copying documents to the target repository."
echo "Source: $FULL_SOURCE_DOCS_PATH"
echo "Destination: $FULL_TARGET_DOCS_PATH"
echo "Copying documents to the target repository." >&2
echo "Source: $FULL_SOURCE_DOCS_PATH" >&2
echo "Destination: $FULL_TARGET_DOCS_PATH" >&2

echo "Clearing the target repository..."
echo "Clearing the target repository..." >&2
ClearTarget

echo "Files to be copied:"
echo "Files to be copied:" >&2
# Log the list of files to be copied
find "$FULL_SOURCE_DOCS_PATH" -type f -print
echo "----"
find "$FULL_SOURCE_DOCS_PATH" -type f -print >&2
echo "----" >&2

echo "Copying files..."
echo "Copying files..." >&2
cp -R "$FULL_SOURCE_DOCS_PATH" "$FULL_TARGET_DOCS_PATH/$PROJECT_NAME"
echo "Documents copied successfully."
echo "Documents copied successfully." >&2
}

# Check if the script is being sourced or executed directly
ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
CopyDocs
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/create_category_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CreateCategoryJSON() {
-e "s|\${PROJECT_NAME}|$PROJECT_NAME|g" \
> "$TARGET_REPO_DIRECTORY/docs/$PROJECT_NAME/_category_.json"

echo "_category_.json file created successfully."
echo "_category_.json file created successfully." >&2
}

# Check for bats
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/docusaurus_build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /bin/bash

DocusaurusBuild() {
echo "Changing to target directory: $TARGET_REPO_DIRECTORY"
cd "$TARGET_REPO_DIRECTORY" || { echo "Changing directory failed"; exit 1; }
echo "Running Docusaurus build..."
yarn build || { echo "Docusaurus build failed"; exit 1; }
echo "Changing to target directory: $TARGET_REPO_DIRECTORY" >&2
cd "$TARGET_REPO_DIRECTORY" || { echo "Changing directory failed" >&2; exit 1; }
echo "Running Docusaurus build..." >&2
yarn build || { echo "Docusaurus build failed" >&2; exit 1; }
}

ORB_TEST_ENV="bats-core"
Expand Down
43 changes: 43 additions & 0 deletions src/scripts/extract_github_org_and_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /bin/bash


# Function to validate the repository URL and extract organization and repository name
ValidateAndExtractRepoInfo() {
local EXTRACTED
local ORG
local REPO

# Validate the repository URL
if [[ "$NORMALIZED_REPO_URL" != *github.com* ]]; then
echo "Error: Not a GitHub URL." >&2
exit 1
fi

# Extract GitHub organization and repository name
EXTRACTED=$(echo "$NORMALIZED_REPO_URL" | awk -F'/' '{gsub(".git", "", $NF); print $(NF-1), $NF}')

echo "EXTRACTED: $EXTRACTED" >&2

if [ -z "$EXTRACTED" ]; then
echo "Error: Invalid GitHub URL format." >&2
exit 1
fi

read -r ORG REPO <<< "$EXTRACTED"

echo "ORG: $ORG" >&2
echo "REPO: $REPO" >&2

# Export extracted organization and repository name as environment variables
{
echo "export GITHUB_ORG=\"${ORG}\""; \
echo "export GITHUB_REPO=\"${REPO}\""; \
} >> "$BASH_ENV"
}


# Check for bats
ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
ValidateAndExtractRepoInfo
fi
35 changes: 35 additions & 0 deletions src/scripts/fetch_commit_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -x # Enable debugging output

ChangeToSourceRepoDirectory() {
echo "Changing directory to $SOURCE_REPO_DIRECTORY" >&2
cd "$SOURCE_REPO_DIRECTORY" || { echo "Changing directory to $SOURCE_REPO_DIRECTORY failed" >&2; exit 1; }
}

FetchCommitInfo() {
local PR_NUMBER
local COMMIT_MESSAGE
local COMMIT_HASH

COMMIT_MESSAGE=$(git log -1 --pretty=%B || { echo "Fetching commit message failed" >&2 ; exit 1; })
echo "COMMIT_MESSAGE: $COMMIT_MESSAGE" >&2
COMMIT_HASH=$(git rev-parse HEAD || { echo "Fetching commit hash failed" >&2 ; exit 1; })
echo "COMMIT_HASH: $COMMIT_HASH" >&2

PR_NUMBER=$(echo "$COMMIT_MESSAGE" | grep -oP '(Merge pull request #\K\d+)|(\(#\K\d+\))' || true)
PR_NUMBER=${PR_NUMBER:-""}


echo "COMMIT_MESSAGE: $COMMIT_MESSAGE" >&2
echo "export COMMIT_MESSAGE=\"${COMMIT_MESSAGE}\"" >> "$BASH_ENV"
echo "COMMIT_HASH: $COMMIT_HASH" >&2
echo "export COMMIT_HASH=\"${COMMIT_HASH}\"" >> "$BASH_ENV"
echo "PR_NUMBER: $PR_NUMBER" >&2
echo "export PR_NUMBER=\"$PR_NUMBER\"" >> "BASH_ENV"
}

ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
ChangeToSourceRepoDirectory
FetchCommitInfo
fi
55 changes: 55 additions & 0 deletions src/scripts/generate_commit_message.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

GenerateCommitMessage() {
echo "Changing directory to $SOURCE_REPO_DIRECTORY" >&2
cd "$SOURCE_REPO_DIRECTORY" || { echo "Changing directory failed" >&2; exit 1; }
echo "Changed directory to $(pwd)" >&2

# Fetch COMMIT_MESSAGE and COMMIT_HASH from git logs
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "COMMIT_MESSAGE: $COMMIT_MESSAGE" >&2

COMMIT_HASH=$(git rev-parse HEAD)
echo "COMMIT_HASH: $COMMIT_HASH" >&2

# Check if it's a pull request commit based on the existence of a PR_NUMBER
PR_MATCH=$(git log -1 --pretty=%B | grep -o "#[0-9]\+" | grep -o "[0-9]\+" | tail -n 1 || true) # Use "|| true" to prevent exit on failure
if [ -n "$PR_MATCH" ]; then
echo "PR-based commit detected" >&2
FINAL_COMMIT_MESSAGE="orb($PROJECT_NAME): $COMMIT_MESSAGE https://github.com/$GITHUB_ORG/$GITHUB_REPO/pull/$PR_MATCH"
else
echo "Non-PR-based commit detected" >&2
FINAL_COMMIT_MESSAGE="orb($PROJECT_NAME): $COMMIT_MESSAGE https://github.com/$GITHUB_ORG/$GITHUB_REPO/commit/$COMMIT_HASH"
fi


# Differentiate between PR-based and non-PR-based commits
if [ -n "$PR_NUMBER" ]; then
echo "PR-based commit detected" >&2
FINAL_COMMIT_MESSAGE="orb($PROJECT_NAME): $COMMIT_MESSAGE https://github.com/$GITHUB_ORG/$PROJECT_NAME/pull/$PR_NUMBER"
else
echo "Non-PR-based commit detected" >&2
FINAL_COMMIT_MESSAGE="orb($PROJECT_NAME): $COMMIT_MESSAGE ($COMMIT_HASH)"
fi

echo "FINAL_COMMIT_MESSAGE: $FINAL_COMMIT_MESSAGE" >&2

# Export variables
{
echo "export COMMIT_MESSAGE=\"${COMMIT_MESSAGE}\""
echo "export COMMIT_HASH=\"${COMMIT_HASH}\""
echo "export PR_NUMBER=\"${PR_NUMBER}\""
echo "export FINAL_COMMIT_MESSAGE=\"${FINAL_COMMIT_MESSAGE}\""
} >> "$BASH_ENV"

# Log environment variables
echo "COMMIT_MESSAGE: ${COMMIT_MESSAGE}" >&2
echo "COMMIT_HASH: ${COMMIT_HASH}" >&2
echo "PR_NUMBER: ${PR_NUMBER}" >&2
echo "FINAL_COMMIT_MESSAGE: ${FINAL_COMMIT_MESSAGE}" >&2
}

ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" = "$0" ]; then
GenerateCommitMessage
fi
Loading