Skip to content

Commit

Permalink
Merge pull request #313 from ty-dc/docs-version
Browse files Browse the repository at this point in the history
Change the process of CI publishing charts and documents
  • Loading branch information
weizhoublue authored Sep 6, 2023
2 parents 1ec7dd8 + 543a2b3 commit 27c5f33
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 58 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/auto-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,22 @@ jobs:
ref: ${{ needs.get-tag.outputs.tag }}
secrets: inherit

release-chart:
needs: [build-release-image, get-tag]
uses: ./.github/workflows/call-release-chart.yaml
with:
ref: ${{ needs.get-tag.outputs.tag }}
secrets: inherit

create-release:
needs: [ release-changelog, get-tag, release-pages]
needs: [ release-changelog, get-tag, release-chart]
name: create release
runs-on: ubuntu-latest
steps:
- name: Download Chart Artifact
uses: actions/[email protected]
with:
name: ${{ needs.release-pages.outputs.artifact }}
name: ${{ needs.release-chart.outputs.artifact }}
path: chart-package/

- name: Download Changelog Artifact
Expand Down
123 changes: 123 additions & 0 deletions .github/workflows/call-release-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Call Release Chart

env:
MERGE_BRANCH: github_pages
PR_LABEL: pr/robot_update
PR_REVIWER: weizhoublue
CHART_OUTPUT_PATH: output/chart/*

on:
workflow_call:
inputs:
ref:
required: true
type: string
outputs:
artifact:
description: "name of chart artifact"
value: chart_package_artifact
# --- call by manual
workflow_dispatch:
inputs:
ref:
description: 'branch, tag, sha'
required: true
default: main

permissions: write-all

jobs:
package:
name: prepare
runs-on: ubuntu-latest
outputs:
ref: ${{ env.RUN_REF }}
steps:
- name: Get Ref
id: get_ref
run: |
pwd
ls
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "call by workflow_dispatch"
echo "REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
elif ${{ inputs.ref != '' }}; then
echo "call by workflow_call"
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.REF }}

- name: Install yq
run: |
YQ_VERSION=v4.33.1
YQ_BINARY="yq_$(uname | tr 'A-Z' 'a-z')_amd64"
wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BINARY}.tar.gz -O /tmp/yq.tar.gz
tar -xzf /tmp/yq.tar.gz -C /tmp
sudo mv /tmp/${YQ_BINARY} /usr/bin/yq
sudo chmod +x /usr/bin/yq
yq &>/dev/null || exit 1
- name: Build chart
run: |
make chart_package
- name: Upload Artifact
uses: actions/[email protected]
with:
name: chart_package_artifact
path: ${{ env.CHART_OUTPUT_PATH }}
retention-days: 1
if-no-files-found: error

create_pr:
name: Create PR
needs: [package]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ env.MERGE_BRANCH }}
fetch-depth: 0

## chart
- name: Install Helm
uses: azure/[email protected]

- name: Download Chart Artifact
uses: actions/[email protected]
with:
name: chart_package_artifact
path: charts

- name: Update Chart Yaml
run: |
name=${{ github.repository }}
proj=${name#*/}
url=https://${{ github.repository_owner }}.github.io/${proj}
helm repo index ./charts --url ${url}/charts
mv ./charts/index.yaml ./index.yaml
# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/[email protected]
with:
title: "robot update chart from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot update chart from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_chart
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}
128 changes: 72 additions & 56 deletions .github/workflows/call-release-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ env:
MERGE_BRANCH: github_pages
PR_LABEL: pr/robot_update
PR_REVIWER: weizhoublue
CHART_OUTPUT_PATH: output/chart/*

on:
workflow_call:
inputs:
ref:
required: true
type: string
outputs:
artifact:
description: "name of chart artifact"
value: chart_package_artifact
# --- call by manual
workflow_dispatch:
inputs:
Expand All @@ -32,18 +27,19 @@ jobs:
runs-on: ubuntu-latest
outputs:
ref: ${{ env.RUN_REF }}
skip_all_job: ${{ env.SKIP_ALL_JOB }}
steps:
- name: Get Ref
id: get_ref
run: |
pwd
ls
if ${{ inputs.ref != '' }}; then
echo "call by workflow_call"
echo "RUN_REF=${{ inputs.ref }}" >> $GITHUB_ENV
elif ${{ github.event_name == 'workflow_dispatch' }} ; then
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "call by workflow_dispatch"
echo "RUN_REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
echo "REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
elif ${{ inputs.ref != '' }}; then
echo "call by workflow_call"
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
Expand All @@ -52,90 +48,110 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ steps.get_ref.outputs.ref }}
fetch-depth: 0
ref: ${{ env.REF }}

- name: Extract Version
id: extract
run: |
if ! grep -E "^[[:space:]]*v[0-9]+.[0-9]+.[0-9]+[[:space:]]*$" VERSION &>/dev/null ; then
echo "not a release version, skip generating doc."
cat VERSION
echo "SKIP_ALL_JOB=true" >> $GITHUB_ENV
exit 0
fi
# for example v0.6.1, the build's documentation version is v0.6
docVersion=` cat VERSION | tr -d ' ' | tr -d '\n' | grep -Eo "v[0-9]+\.[0-9]+" `
if [ -n "${docVersion}" ]; then
echo "the version intercepted from the branch is: ${docVersion}"
else
echo "error, failed to get version." && exit 1
fi
git checkout -f ${{ env.MERGE_BRANCH }}
echo "Switch to the branch:${{ env.MERGE_BRANCH }} where the document is located"
ls
if [ -e "${docVersion}" ]; then
echo "doc version:${docVersion} already exists, just update it."
echo "SET_LATEST=false" >> $GITHUB_ENV
else
echo "The doc version:${docVersion} does not exist yet, while generating the doc and set it to latest"
echo "SET_LATEST=true" >> $GITHUB_ENV
fi
echo "the doc version is: ${docVersion}"
echo "DOCS_TAG=${docVersion}" >> $GITHUB_ENV
- name: Build Site and chart
- name: build doc site
id: build_doc
if: ${{ env.SKIP_ALL_JOB != 'true' }}
run: |
make build_doc
make chart_package
git checkout ${{ env.REF }}
ls
echo "switch to the release version branch ${{ env.REF }}"
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==9.2.8
git config user.email "[email protected]"
git config user.name "robot"
cp ./docs/mkdocs.yml ./
if ${{ env.SET_LATEST == 'true' }} ;then
echo "generate doc version:${{ env.DOCS_TAG }} and set to latest."
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} --update-aliases ${{env.DOCS_TAG }} latest
mike set-default -b ${{ env.MERGE_BRANCH }} latest
else
echo "the version:${{ env.DOCS_TAG }} of the doc does not need to be set to the latest."
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DOCS_TAG }}
fi
rm -rf ./site
rm -rf ./mkdocs.yml
git checkout -f ${{ env.MERGE_BRANCH }}
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs
tar -czvf ./site.tar.gz *
ls
echo "Automatic release, offline doc site package ready"
echo "Push a doc version: ${{ env.DOCS_TAG }} from branch: ${{ env.REF }}, update it to latest: ${{ env.SET_LATEST }} "
- name: Upload Artifact
uses: actions/[email protected]
if: ${{ env.SKIP_ALL_JOB != 'true' }}
with:
name: site_artifact
path: output/docs/site.tar.gz
path: site.tar.gz
retention-days: 0
if-no-files-found: error

- name: Upload Artifact
uses: actions/[email protected]
with:
name: chart_package_artifact
path: ${{ env.CHART_OUTPUT_PATH }}
retention-days: 1
if-no-files-found: error

create_pr:
name: Create PR
needs: [package]
if: ${{ needs.package.outputs.skip_all_job != 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: ${{ env.MERGE_BRANCH }}
fetch-depth: 0

## doc
- name: Prepare
run: |
# prepare directory
mv docs/charts charts
rm -rf docs
mkdir docs
- name: Download Artifact
uses: actions/[email protected]
with:
name: site_artifact
path: docs

- name: Untar Doc
run: |
cd docs
tar -xzvf site.tar.gz
rm -f site.tar.gz
## chart
- name: Install Helm
uses: azure/[email protected]

- name: Download Chart Artifact
uses: actions/[email protected]
with:
name: chart_package_artifact
path: charts/

- name: Update Chart Yaml
run: |
mv charts docs/charts
name=${{ github.repository }}
proj=${name#*/}
url=https://${{ github.repository_owner }}.github.io/${proj}
cd docs
helm repo index ./charts --url ${url}/charts
mv ./charts/index.yaml ./index.yaml
# https://github.com/peter-evans/create-pull-request
# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/[email protected]
with:
title: "robot Update doc from ${{ needs.prepare_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot Update chart from ${{ needs.prepare_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
title: "robot update website from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot update website from ${{ needs.package.outputs.REF }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_doc
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.WELAN_PAT }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}
5 changes: 5 additions & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repo_url: https://github.com/spidernet-io/rocktemplate
remote_branch: github_pages
theme:
name: material
custom_dir: docs/overrides
# The maximum depth of the navigation tree in the sidebar
navigation_depth: 2
palette:
Expand All @@ -28,6 +29,10 @@ plugins:
- tags
- search

extra:
version:
provider: mike

markdown_extensions:
- meta
- toc
Expand Down
8 changes: 8 additions & 0 deletions docs/overrides/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block outdated %}
You're not viewing the latest version.
<a href="{{ '../' ~ base_url }}">
<strong>Click here to go to latest.</strong>
</a>
{% endblock %}

0 comments on commit 27c5f33

Please sign in to comment.