source-update #21
This file contains hidden or 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
name: Generate MessageFlow Docs | |
on: | |
repository_dispatch: | |
types: [ source-update ] | |
permissions: | |
contents: write | |
jobs: | |
generate-messageflow-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout aggregator repo | |
uses: actions/checkout@v4 | |
- name: Checkout source repo | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.event.client_payload.source_repo }} | |
path: temp-source | |
token: ${{ secrets.INTEGRATION_PAT }} | |
- name: Copy asyncapi files to appropriate folder | |
run: | | |
mkdir -p source/${{ github.event.client_payload.source_repo }} | |
find temp-source -type f \( -name "*.yaml" -o -name "*.yml" \) -exec grep -l "asyncapi:" {} \; | while read -r file; do | |
FILENAME=$(basename "$file") | |
cp $file "source/${{ github.event.client_payload.source_repo }}/$FILENAME" | |
done | |
rm -rf temp-source | |
- name: Generate docs and capture changelog | |
id: generate-docs | |
run: | | |
OUTPUT=$(docker run --rm \ | |
--user $(id -u):$(id -g) \ | |
-v ${{ github.workspace }}:/work \ | |
ghcr.io/holydocs/messageflow:latest \ | |
gen-docs --dir work/source --output work/docs 2>&1) | |
echo "$OUTPUT" | |
if echo "$OUTPUT" | grep -q "New Changes Detected:"; then | |
CHANGELOG=$(echo "$OUTPUT" | sed -n '/New Changes Detected:/,$p' | sed '1d') | |
echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
else | |
echo "changelog=" >> $GITHUB_OUTPUT | |
fi | |
- name: Commit & push (if anything changed) | |
env: | |
PAT: ${{ secrets.INTEGRATION_PAT }} | |
CHANGELOG: ${{ steps.generate-docs.outputs.changelog }} | |
run: | | |
if ! (git diff-index --quiet HEAD -- && [ -z "$(git ls-files --others --exclude-standard)" ]); then | |
git config user.name "messageflow-ci-bot" | |
git config user.email "messageflow-ci-bot@example.com" | |
git add -A | |
COMMIT_MSG="Sync: ${{ github.event.client_payload.source_repo }}@${{ github.event.client_payload.source_sha }}" | |
# Add changes details if available | |
if [ -n "$CHANGELOG" ]; then | |
echo "Changelog from variable:" | |
echo "$CHANGELOG" | |
printf "%s\n\n%s\n" "$COMMIT_MSG" "$CHANGELOG" > /tmp/commit_msg.txt | |
else | |
echo "$COMMIT_MSG" > /tmp/commit_msg.txt | |
fi | |
echo "Commit message file:" | |
cat /tmp/commit_msg.txt | |
git commit -F /tmp/commit_msg.txt | |
git remote set-url origin "https://x-access-token:${PAT}@github.com/${GITHUB_REPOSITORY}" | |
git push | |
fi |