From f7825801aa621c89f2680ea2b018045b5e6b1e61 Mon Sep 17 00:00:00 2001 From: Luke Fritz Date: Mon, 20 Feb 2023 17:59:31 -0600 Subject: [PATCH] Add Confluence deployment workflow (feat) --- .github/workflows/deploy-to-confluence.yaml | 50 ++++++++++++++++ .../deployment/deploy-docs-to-confluence.sh | 57 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 .github/workflows/deploy-to-confluence.yaml create mode 100644 scripts/deployment/deploy-docs-to-confluence.sh diff --git a/.github/workflows/deploy-to-confluence.yaml b/.github/workflows/deploy-to-confluence.yaml new file mode 100644 index 0000000..b786f83 --- /dev/null +++ b/.github/workflows/deploy-to-confluence.yaml @@ -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 }} diff --git a/scripts/deployment/deploy-docs-to-confluence.sh b/scripts/deployment/deploy-docs-to-confluence.sh new file mode 100644 index 0000000..e8406aa --- /dev/null +++ b/scripts/deployment/deploy-docs-to-confluence.sh @@ -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 '' "$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 "$@"