Skip to content

Commit 935cea5

Browse files
Fix parsing of repo / commit info (#34)
* verbose logs * check for bats * add examples * change testcondition * break up parse-commit-info script * normalize bash style * remove obsolete function call * add exit * remove bash env check * fix parsing of git info * remove obsolete tests
1 parent a2c823f commit 935cea5

23 files changed

+296
-336
lines changed

src/commands/commit_and_push_to_target.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ description: >
22
"Commits and pushes the updated documentation to the docs repository."
33
44
steps:
5-
- run:
6-
name: Parse commit message and PR number
7-
command: <<include(scripts/parse_commit_info.sh)>>
85
- run:
96
name: Commit and push to target repository
107
command: <<include(scripts/commit_and_push_to_target.sh)>>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: >
2+
"Extracts GitHub organization and repository name from the repository URL."
3+
steps:
4+
- run:
5+
name: "Extract GitHub Organization and Repository"
6+
command: <<include(scripts/extract_github_org_and_repo.sh)>>

src/commands/fetch_commit_info.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: >
2+
"Fetch the last commit message and commit hash from the source repository."
3+
steps:
4+
- run:
5+
name: "Fetch Commit Info"
6+
command: <<include(scripts/fetch_commit_info.sh)>>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: >
2+
"Constructs the final commit message incorporating all relevant details and links."
3+
steps:
4+
- run:
5+
name: "Generate Commit Message"
6+
command: <<include(scripts/generate_commit_message.sh)>>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: >
2+
"Normalizes the GitHub URL for use in later parts of the script."
3+
steps:
4+
- run:
5+
name: "Normalize Repository URL"
6+
command: <<include(scripts/normalize_repository_url.sh)>>
File renamed without changes.

src/examples/references.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
description: >
2+
You can reduce repetition by defining props in a YAML anchor and referencing it later.
3+
4+
usage:
5+
version: 2.1
6+
orbs:
7+
publish-docs: infinitered/[email protected] # Replace with the actual version
8+
9+
# Define common parameters
10+
common_params: &publish_docs_params
11+
description: "The description that will appear on autogenerated indexes and components."
12+
git_email: "[email protected]"
13+
git_username: "Your CI Username"
14+
label: "The label that will appear in the sidebar of the docs site."
15+
project_name: 'name-of-project'
16+
source_docs_dir: "docs"
17+
source_repo_directory: "source"
18+
target_docs_dir: "docs"
19+
target_repo: "[email protected]:your-org/your-repo.git"
20+
target_repo_directory: "target"
21+
22+
workflows:
23+
build_docs:
24+
jobs:
25+
- publish-docs/build_docs:
26+
# this will expand to all the parameters defined in the anchor
27+
<<: *publish_docs_params
28+
publish_to_docs_site:
29+
jobs:
30+
- publish-docs/publish_docs:
31+
# this will expand to all the parameters defined in the anchor
32+
<<: *publish_docs_params

src/jobs/publish_docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ steps:
6868
repo_directory: <<parameters.target_repo_directory>>
6969
- copy_docs_to_target
7070
- build_docusaurus
71+
- fetch_commit_info
72+
- normalize_repository_url
73+
- extract_github_org_and_repo
74+
- generate_commit_message
7175
- commit_and_push_to_target

src/scripts/check_docs_exist.sh

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

3+
# Function to check if documents exist in the source directory
34
CheckDocsExist() {
45
# Parameters: Source docs path
5-
echo "Checking if documents exist in the source directory."
6+
echo "Checking if documents exist in the source directory." >&2
67

78
# Check if the directory exists
89
if [ ! -d "$FULL_SOURCE_DOCS_PATH" ]; then
9-
echo "Error: Directory $FULL_SOURCE_DOCS_PATH does not exist."
10+
echo "Error: Directory $FULL_SOURCE_DOCS_PATH does not exist." >&2
1011
exit 1
1112
fi
1213

1314
# Check if the directory is empty
1415
if [ ! "$(ls -A "$FULL_SOURCE_DOCS_PATH")" ]; then
15-
echo "Error: No files found in docs directory."
16+
echo "Error: No files found in docs directory." >&2
1617
exit 1
1718
fi
1819
}

src/scripts/clone_required_repos.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ LogEnvironmentVariables() {
1414

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

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

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

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

4848
SetGitUser
4949
AddGithubToKnownHosts
5050
CloneSourceRepo
5151
CloneTargetRepo
52-
else
53-
echo "Script is being sourced"
5452
fi

0 commit comments

Comments
 (0)