Skip to content

Commit 571fe7d

Browse files
committed
Implement publish and check commands
1 parent 964a4bf commit 571fe7d

File tree

6 files changed

+162
-2
lines changed

6 files changed

+162
-2
lines changed

Diff for: Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:18-alpine
2+
3+
ENV version=1.2
4+
5+
# Metadata
6+
LABEL name=techdocs-check version=$version \
7+
maintainer="Pavel Dedik <dedikx@gmail.com>"
8+
9+
RUN apk add --no-cache bash py3-pip && \
10+
pip install --no-cache mkdocs-techdocs-core==1.* && \
11+
pip install --no-cache shyaml && \
12+
npm install -g @techdocs/cli
13+
14+
WORKDIR /app
15+
16+
COPY mkdocs-check.sh /usr/local/bin/mkdocs-check
17+
COPY techdocs-publish.sh /usr/local/bin/techdocs-publish
18+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
19+
20+
USER nobody
21+
22+
ENTRYPOINT ["entrypoint.sh"]

Diff for: README.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1-
# actions-backstage
2-
Github Actions for various tools useful when running Backstage from Spotify
1+
# actions-techdocs
2+
3+
Github Action for Backstage's techdocs plugin from Spotify.
4+
5+
## Usage
6+
7+
```yaml
8+
jobs:
9+
techdocs:
10+
name: Check & Publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v3
15+
16+
# Runs mkdocs check in all directories containing **/mkdocs.yaml file
17+
- name: Run mkdocs check
18+
uses: TwistoPayments/actions-techdocs@main
19+
with:
20+
command: check
21+
22+
# Runs techdocs generate and techdocs publish commands in all directories containgin
23+
# **/mkdocs.yaml file. Currently only S3 publisher is supported.
24+
- name: Run techdocs publish
25+
uses: TwistoPayments/actions-techdocs@main
26+
with:
27+
command: publish
28+
env:
29+
TECHDOCS_PUBLISHER_TYPE: awsS3
30+
TECHDOCS_S3_BUCKET_NAME: ${{ secrets.TECHDOCS_S3_BUCKET_NAME }}
31+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
32+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33+
AWS_REGION: ${{ secrets.AWS_REGION }}
34+
```

Diff for: action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'backstage-techdocs'
2+
description: 'Run command for technical documentation generation'
3+
author: 'TwistoPayments Platform team'
4+
inputs:
5+
command:
6+
description: Command to run, currently only `check` and `publish`
7+
required: true
8+
9+
runs:
10+
using: 'docker'
11+
image: 'Dockerfile'
12+
args:
13+
- ${{ inputs.command }}

Diff for: entrypoint.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
if [ "$1" = "check" ]; then
4+
mkdocs-check
5+
elif [ "$1" = "publish" ]; then
6+
techdocs-publish
7+
else
8+
echo "Unknown command."
9+
fi

Diff for: mkdocs-check.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
working_dir="$PWD"
4+
5+
for mkdocs in $(find . -name mkdocs.yaml 2>/dev/null); do
6+
docs_dir=$(dirname $mkdocs)
7+
8+
echo "info: Running command 'mkdocs build $docs_dir' ..."
9+
10+
if [ $docs_dir = "." ]; then
11+
build_dir="/tmp/root"
12+
else
13+
build_dir="/tmp/$docs_dir"
14+
fi
15+
16+
cd $docs_dir
17+
18+
output=$(mkdocs build -d $build_dir 2>&1)
19+
errors=$(echo "$output" | grep ERROR)
20+
21+
if [ -z "$errors" ]; then
22+
warnings=$(echo "$output" | grep WARNING)
23+
24+
if [ -z "$warnings" ]; then
25+
echo "info: Build suceeded"
26+
else
27+
echo "error: Build failed returning the following WARNINGs:"
28+
echo ""
29+
echo "$warnings"
30+
exit 1
31+
fi
32+
33+
else
34+
echo "error: Build failed returning the following ERRORs:"
35+
echo ""
36+
echo "$errors"
37+
exit 1
38+
fi
39+
40+
echo ""
41+
cd $working_dir
42+
43+
done

Diff for: techdocs-publish.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
working_dir="$PWD"
4+
5+
for mkdocs in $(find . -name mkdocs.yaml 2>/dev/null); do
6+
docs_dir=$(dirname $mkdocs)
7+
8+
echo "info: Found mkdocs.yaml in $docs_dir ..."
9+
10+
if [ $docs_dir = "." ]; then
11+
build_dir="/tmp/root"
12+
else
13+
build_dir="/tmp/$docs_dir"
14+
fi
15+
16+
cd $docs_dir
17+
18+
if [[ ! -f 'catalog-info.yaml' ]]; then
19+
echo "warning: $build_dir/catalog-info.yaml not found"
20+
continue
21+
fi
22+
23+
catalog_info=$(cat catalog-info.yaml)
24+
25+
kind=$(echo "$catalog_info" | shyaml get-value kind)
26+
name=$(echo "$catalog_info" | shyaml get-value metadata.name)
27+
namespace=$(echo "$catalog_info" | shyaml get-value metadata.namespace default)
28+
entity_name="$namespace/$kind/$name"
29+
30+
echo "info: Docs for entity $entity_name generating ..."
31+
techdocs-cli generate --output-dir $build_dir --no-docker --verbose
32+
33+
echo "info: Docs for entity $entity_name publishing ..."
34+
techdocs-cli publish --publisher-type $TECHDOCS_PUBLISHER_TYPE --storage-name $TECHDOCS_S3_BUCKET_NAME --directory $build_dir --entity $entity_name
35+
36+
echo "info: Docs for entity $entity_name published"
37+
echo ""
38+
39+
cd $working_dir
40+
41+
done

0 commit comments

Comments
 (0)