Documentation CI #35
This file contains 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: Documentation CI | |
on: | |
workflow_call: | |
inputs: | |
git_tag: | |
type: string | |
description: The git tag (version) from the calling workflow | |
workflow_dispatch: | |
inputs: | |
git_tag: | |
type: string | |
description: The git tag (version) to use for `$TAG` | |
jobs: | |
docs-ci: | |
permissions: | |
# need to provide GH_TOKEN with content/pull-request write premissions | |
contents: write | |
pull-requests: write | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
# keeping TAG for cases docs repo workflow is triggered with tag input | |
TAG: ${{ inputs.git_tag }} | |
REF_NAME: ${{ github.ref_name }} | |
# in case of pushed PR, ref_head specifies PR's branch | |
REF_HEAD: ${{ github.head_ref }} | |
# will be used to specify repo tar url according to PR id | |
PR_NUMBER: ${{ github.event.number }} | |
PR_TITLE_PREFIX: "task: update documentation for" | |
steps: | |
- name: Check if PR actor is part of team | |
env: | |
ACTOR: ${{ github.actor }} | |
run: | | |
response=$(curl -H "Authorization: Bearer $GH_TOKEN" \ | |
-H "Accept: application/vnd.github+json" \ | |
"https://api.github.com/orgs/Mellanox/teams/cloud-orchestration/members/$ACTOR") | |
if [[ $(echo "$response" | jq -r '.message') == "Not Found" ]]; then | |
echo "Actor $ACTOR is not part of the 'Mellanox/cloud-orchestration' team and cannot initiate 'Documentation CI' workflow" | |
exit 1 | |
else | |
echo "Actor $ACTOR is part of the 'Mellanox/cloud-orchestration' team" | |
fi | |
- uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository_owner }}/network-operator-docs # repo must be explicitly set here for workflow calling to behave correctly | |
token: ${{ inputs.token || secrets.GH_TOKEN }} | |
- name: Setup Go | |
uses: actions/[email protected] | |
with: | |
go-version: 1.23.x | |
- name: Make docs | |
# handle triggered workflow by pushed tag or PR | |
run: | | |
if [[ -n $PR_NUMBER ]]; then | |
export BRANCH=$REF_HEAD | |
echo "REF_NAME=$REF_HEAD" >> $GITHUB_ENV | |
echo "COMMIT_SUFFIX=pull/$PR_NUMBER" >> $GITHUB_ENV | |
else | |
TAG="${TAG:-$REF_NAME}" | |
export TAG | |
echo "TAG=$TAG" >> $GITHUB_ENV | |
echo "COMMIT_SUFFIX=$TAG" >> $GITHUB_ENV | |
fi | |
make api-docs helm-docs generate-docs-versions-var | |
- name: Close any existing documentation PRs | |
run: | | |
for pr_number in $(gh pr list --search "$PR_TITLE_PREFIX" --json number --jq ".[].number"); do | |
gh pr close $pr_number | |
done | |
- name: Create PR | |
env: | |
REF_NAME: ${{ github.ref_name }} | |
DOWNSTREAM_REPO_OWNER: nvidia-ci-cd | |
DOWNSTREAM_FEATURE_BRANCH: update-docs-for-${{ env.REF_NAME }} | |
UPSTREAM_REPO_OWNER: Mellanox | |
UPSTREAM_DEFAULT_BRANCH: main | |
run: | | |
git config user.name nvidia-ci-cd | |
git config user.email [email protected] | |
gh repo fork --remote --default-branch-only | |
gh repo sync $DOWNSTREAM_REPO_OWNER/network-operator-docs --source $UPSTREAM_REPO_OWNER/network-operator-docs --branch $UPSTREAM_DEFAULT_BRANCH | |
git checkout -b $DOWNSTREAM_FEATURE_BRANCH | |
git add docs | |
COMMIT_MESSAGE="$PR_TITLE_PREFIX $COMMIT_SUFFIX" | |
git commit -m "$COMMIT_MESSAGE" | |
git push -u origin $DOWNSTREAM_FEATURE_BRANCH --force | |
gh pr create \ | |
--head $DOWNSTREAM_REPO_OWNER:$DOWNSTREAM_FEATURE_BRANCH \ | |
--base $UPSTREAM_DEFAULT_BRANCH \ | |
--title "$COMMIT_MESSAGE" \ | |
--body "Created by the *${{ github.job }}* job in [${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})." |