Skip to content

Commit

Permalink
Add Github Action to generate documentation on dispatch trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-mdr committed Mar 11, 2022
1 parent 69eab89 commit 14c4823
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/scripts/doc-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

DOC_TEMPLATE_SUBMODULE="docs/doc-terraform-template"

if [ "$TAG" == "" ]; then
echo "We need the tag of the doc"
exit 1
fi

# Create a branch
git checkout -b "autobuild-Documentation-$TAG"

# Update submodule
(cd $DOC_TEMPLATE_SUBMODULE && git fetch && git checkout $TAG)

# Gen the doc
make doc

# Create PR
git config user.name "Outscale Bot"
git config user.email "[email protected]"

git add $DOC_TEMPLATE_SUBMODULE
git add website/*

git commit -sm "Release Documentation $TAG"
19 changes: 19 additions & 0 deletions .github/scripts/doc-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/env bash
set -e

if [ -z "$GH_BOT_TOKEN" ]; then
echo "GH_BOT_TOKEN is missing, abort."
exit 1
fi

# https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#create-a-pull-request
result=$(curl -s -X POST -H "Authorization: token $GH_BOT_TOKEN" -d "{\"head\":\"autobuild-Documentation-$TAG\",\"base\":\"master\",\"title\":\"Documentation $TAG\",\"body\":\"Automatic generation of the documentation $TAG\"}" "https://api.github.com/repos/outscale-mdr/terraform-provider-outscale/pulls")

errors=$(echo $result | jq .errors)

echo $errors

if [ "$errors" != "null" ]; then
echo "errors while creating pull request, abort."
exit 1
fi
17 changes: 17 additions & 0 deletions .github/scripts/doc-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

if [ "$TAG" == "" ]; then
echo "We need the tag of the doc"
exit 1
fi

if [ "$SSH_PRIVATE_KEY" == "" ]; then
echo "We need the SSH key of the bot"
exit 1
fi

echo "$SSH_PRIVATE_KEY" > bot.key
chmod 600 bot.key
GIT_SSH_COMMAND="ssh -i bot.key" git push -f origin "autobuild-Documentation-$TAG"
31 changes: 31 additions & 0 deletions .github/workflows/generate_doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Generate documentation
on:
workflow_dispatch:
inputs:
tag:
description: 'doc template tag repository'
required: true

jobs:
doc-release:
environment: auto-build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- uses: actions/setup-python@v2
- name: auto-generate release
run: .github/scripts/doc-build.sh
env:
TAG: ${{ github.event.inputs.tag }}
- name: push release branch
run: .github/scripts/doc-push.sh
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
TAG: ${{ github.event.inputs.tag }}
- name: create pull request
run: .github/scripts/doc-pr.sh
env:
TAG: ${{ github.event.inputs.tag }}
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
url = https://github.com/outscale/osc-api
[submodule "docs/doc-terraform-template"]
path = docs/doc-terraform-template
url = https://gitlab.outscale.internal/documentation/doc-terraform-template.git
url = https://github.com/outscale-dev/terraform-provider-outscale-doc-components.git
2 changes: 1 addition & 1 deletion docs/doc-terraform-template

0 comments on commit 14c4823

Please sign in to comment.