Skip to content

Commit

Permalink
chore(ci): Adds automatic doc syncing
Browse files Browse the repository at this point in the history
Right now, this is specific to go, in a follow up, I'll add support for
TS and Rust and might rename the script if it can be used generically

Signed-off-by: Taylor Thomas <taylor@cosmonic.com>
  • Loading branch information
thomastaylor312 committed Jan 2, 2025
1 parent 6b7aa8d commit e0867c6
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/sync-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Sync example docs

on:
workflow_dispatch:
schedule:
- '0 1 * * *'
pull_request:
branches: ['main']

permissions:
contents: read

jobs:
sync-docs:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout docs repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: ./wasmcloud.com
- name: Checkout Go repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
path: ./wasmcloud-go
repository: wasmCloud/go
- name: Sync docs
id: sync-docs
working-directory: ./wasmcloud.com
run: ./scripts/update-docs.sh ../wasmcloud-go
- name: Create Docs PR
if: steps.sync-docs.outputs.docs_changed == 'true'
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
path: ./wasmcloud.com
commit-message: Updates Go example docs from wasmcloud-go
title: 'chore: Update Go example docs'
body: Updates Go example docs from wasmcloud-go. This is an automatic PR.
branch: chore/update-go-example-docs
delete-branch: true
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
committer: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: true
43 changes: 43 additions & 0 deletions scripts/update-go-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -euo pipefail

# If no arguments are passed, print help message and exit
if [ $# -eq 0 ]; then
echo "Usage: $0 <go_repo_path>"
exit 1
fi

go_repo=$1

# Get the top-level directory of the repository
pushd "${go_repo}";
docs_dir="$(git rev-parse --show-toplevel)/examples";
popd;

while IFS= read -r -d '' file
do
# Get the relative path of the file from the repo root
rel_path=$(dirname "${file#"$docs_dir/"}")
# This uppercases the first letter of each word in the path so the sidebar is correct. We may
# change this in the future with some metadata in the docs repo
target_dir="$(git rev-parse --show-toplevel)/docs/Examples/Go/${rel_path^}"
# Create the target directory structure
mkdir -p "${target_dir}"
# Copy the file to the docs repo
cp "$file" "${target_dir}/index.md"
done < <(find "${docs_dir}" -name "README.md" -type f -print0)

# Now check if there are any git changes in the repo
if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes detected in docs repo. Exiting..."
exit 0
fi

echo "Changes detected in docs repo after syncing"
# If GITHUB_OUTPUT is set, write a variable to it. This is mostly here so people can run it locally
# if desired and for testing.
if [ -n "${GITHUB_OUTPUT:-}" ]; then
echo "docs_changed=true" >> "$GITHUB_OUTPUT"
fi
exit 0

0 comments on commit e0867c6

Please sign in to comment.