Skip to content

Commit

Permalink
Add workflow to update API docs for releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
MirahImage committed Mar 22, 2021
1 parent d06a113 commit df88a94
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/publish-versioned-api-ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Publish Versioned API Reference Wiki page"

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
publish-versioned-api-reference:
name: Publish Versioned API Reference Wiki
runs-on: ubuntu-latest

steps:
- name: Checkout operator codebase
uses: actions/checkout@v2
with:
path: messaging-topology-operator
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Checkout wiki codebase
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}.wiki
path: wiki
- name: Push to wiki
run: |
cd wiki
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
# Add the versioned API Reference to the Wiki
cp ../messaging-topology-operator/docs/api/rabbitmq.com.ref.asciidoc ./API_Reference_${{ steps.get_version.outputs.VERSION }}.asciidoc
# Regenerate the ordered list of API Reference docs for the sidebar
export REGENERATED_SIDEBAR="$(../messaging-topology-operator/hack/generate-ordered-api-reference-list.sh .)"
echo "$REGENERATED_SIDEBAR" > Wiki_Sidebar.md
git add ./API_Reference_${{ steps.get_version.outputs.VERSION }}.asciidoc
git add ./Wiki_Sidebar.md
git commit -m "Publish version ${{ steps.get_version.outputs.VERSION }} API Reference" && git push
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,action,eventName
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
32 changes: 32 additions & 0 deletions hack/generate-ordered-api-reference-list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -euo pipefail

wikiDir=$1

generateVersionedEntry() {
echo "* [$1](https://github.com/rabbitmq/messaging-topology-operator/wiki/API_Reference_$1)"
}

generateLatestEntry() {
echo "* [Latest](https://github.com/rabbitmq/messaging-topology-operator/wiki/API_Reference)"
}

lead='^<!--- BEGIN API REFERENCE LIST -->$'
tail='^<!--- END API REFERENCE LIST -->$'

unorderedlistfile="$(mktemp)"
orderedlistfile="$(mktemp)"

apiVersions="$(find "$wikiDir/API_Reference_*" -printf "%f\n" | sed -r 's/API_Reference_(v[0-9]+.[0-9]+.[0-9]+).asciidoc/\1/' | sort -Vr )"
for version in $apiVersions
do
generateVersionedEntry "$version" >> "$unorderedlistfile"
done

# Latest API version is a special case, that is always top of the list
generateLatestEntry > "$orderedlistfile"
cat "$unorderedlistfile" >> "$orderedlistfile"

sed -e "/$lead/,/$tail/{ /$lead/{p; r $orderedlistfile
}; /$tail/p; d }" "$wikiDir/Wiki_Sidebar.md"

0 comments on commit df88a94

Please sign in to comment.