-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Confluence deployment workflow (feat)
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Deploy to Confluence | ||
on: | ||
workflow_call: | ||
inputs: | ||
confluenceUrl: | ||
description: The URL of the Confluence instance to which the documentation will be deployed. | ||
required: true | ||
type: string | ||
filePattern: | ||
description: The glob pattern used to identify which documents should be considered for deployment to Confluence. | ||
required: false | ||
type: string | ||
default: '*.md' | ||
markVersion: | ||
description: The version of mark to install and use (see https://github.com/kovetskiy/mark/releases). | ||
required: false | ||
type: string | ||
default: '8.7' | ||
secrets: | ||
CONFLUENCE_API_TOKEN: | ||
required: true | ||
CONFLUENCE_SERVICE_ACCOUNT: | ||
required: false | ||
GIT_TOKEN_BASIC: | ||
required: false | ||
jobs: | ||
deploy-to-confluence: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
token: ${{ secrets.GIT_TOKEN_BASIC || github.token }} | ||
- uses: actions/checkout@v3 | ||
with: | ||
repository: cncsc/actions | ||
path: ./.actions/ | ||
- name: Install Mark | ||
run: | | ||
curl -sL "https://github.com/kovetskiy/mark/releases/download/${{ inputs.markVersion }}/mark_${{ inputs.markVersion }}_Linux_x86_64.tar.gz" | tar -xzvf - mark | ||
chmod 755 mark | ||
mv mark /usr/bin/mark | ||
shell: bash | ||
- name: Deploy to Confluence | ||
run: ./.actions/scripts/deployment/deploy-docs-to-confluence.sh "${{ inputs.filePattern }}" | ||
shell: bash | ||
env: | ||
CONFLUENCE_SERVICE_ACCOUNT: ${{ secrets.CONFLUENCE_SERVICE_ACCOUNT }} | ||
CONFLUENCE_API_TOKEN: ${{ secrets.CONFLUENCE_API_TOKEN }} | ||
CONFLUENCE_URL: ${{ inputs.confluenceUrl }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
function create_config_file() { | ||
mkdir -p "$HOME/.config/" | ||
local -r destination_path="$HOME/.config/mark" | ||
|
||
echo "username = \"$CONFLUENCE_SERVICE_ACCOUNT\"" > "$destination_path" | ||
echo "password = \"$CONFLUENCE_API_TOKEN\"" >> "$destination_path" | ||
echo "base_url = \"$CONFLUENCE_URL\"" >> "$destination_path" | ||
} | ||
|
||
function process_files() { | ||
local -r file_pattern="$1" | ||
local -r error_path="$(mktemp)" | ||
local -r error_files="$(mktemp)" | ||
|
||
while read -r -d '' file; do | ||
|
||
# Skip base README.md | ||
if [[ "$file" == "./README.md" ]]; then | ||
echo "::debug::Skipping ./README.md" | ||
continue | ||
fi | ||
|
||
if ! grep -qP '<!--\s*Space:\s*\S+\s*-->' "$file"; then | ||
echo "::notice::Skipping $file missing metadata: Space" | ||
continue | ||
fi | ||
|
||
( | ||
echo "Syncing $file..." | ||
pushd "$(dirname "$file")" > /dev/null || exit | ||
filename="$(basename "$file")" | ||
mark -k -f "$filename" 2> >(tee "$error_path") | ||
exit_status="$?" | ||
if [ $exit_status -ne 0 ]; then | ||
cat "$error_path" | ||
if [[ $(cat "$error_path") != *"doesn't contain metadata"* ]]; then | ||
echo -e "::warning::Failed to process file: $file"; | ||
echo "$file" | tee -a "$error_files" | ||
fi | ||
fi | ||
popd > /dev/null || exit | ||
) | ||
done < <(find . -type f -name "$file_pattern" -print0) | ||
if [ -s "$error_files" ]; then | ||
echo "::error::Failed to process files with mark: $(printf ', %s' "$(<"$error_files")" | cut -f2- -d,)" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function main() { | ||
create_config_file | ||
process_files "$@" | ||
} | ||
|
||
main "$@" |