mirror of
https://github.com/ansible/ansible-documentation.git
synced 2026-03-28 13:39:00 +07:00
* fixes #2047 restructure package docs workflow This change splits the package docs workflow into reusable parts for flexibility so that we can run different builds on various schedules. --------- Co-authored-by: Felix Fontein <5781356+felixfontein@users.noreply.github.com>
133 lines
3.9 KiB
YAML
133 lines
3.9 KiB
YAML
---
|
|
name: Deploy docs
|
|
|
|
"on":
|
|
workflow_call:
|
|
inputs:
|
|
repository-owner:
|
|
description: GitHub account or org that owns the repository
|
|
type: string
|
|
required: false
|
|
default: ansible
|
|
repository-branch:
|
|
description: Branch, tag, or commit SHA
|
|
type: string
|
|
required: false
|
|
default: devel
|
|
ansible-package-version:
|
|
type: string
|
|
description: Ansible community package version
|
|
required: false
|
|
default: devel
|
|
deployment-environment:
|
|
description: Deployment environment
|
|
type: string
|
|
required: false
|
|
default: test
|
|
secrets:
|
|
DEPLOY_DOC_BUILD:
|
|
required: true
|
|
|
|
jobs:
|
|
log-inputs:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Log the workflow inputs if deployed
|
|
run: |
|
|
{
|
|
echo "## Deployment details :shipit:";
|
|
echo "Publish to: ${{ inputs.deployment-environment }}";
|
|
echo "Package version: ${{ inputs.ansible-package-version }}";
|
|
echo "Owner: ${{ inputs.repository-owner }}";
|
|
echo "Branch: ${{ inputs.repository-branch }}";
|
|
} >> "${GITHUB_STEP_SUMMARY}"
|
|
|
|
deploy-package-docs:
|
|
runs-on: ubuntu-latest
|
|
environment:
|
|
name: deploy-package-docs
|
|
url: ${{ env.ENV_URL }}
|
|
env:
|
|
TARGET: ${{ github.event.inputs.deployment-environment }}
|
|
DEST_REPO: ansible-community/package-doc-builds
|
|
USER_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
|
|
USER_NAME: "github-actions[bot]"
|
|
steps:
|
|
- name: Download the build archive
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: package-docs-build
|
|
|
|
- name: Extract the tarball
|
|
run: >-
|
|
tar -xvzf
|
|
ansible-package-docs-html-*.tar.gz
|
|
--one-top-level
|
|
|
|
- name: Set the production branch and url
|
|
if: env.TARGET == 'production'
|
|
env:
|
|
BRANCH_NAME: ${{ github.event.inputs.ansible-package-version }}
|
|
PROD_URL: https://ansible.readthedocs.io/projects/ansible
|
|
run: |
|
|
echo "BRANCH=${BRANCH_NAME}" >> "${GITHUB_ENV}"
|
|
echo "ENV_URL=${PROD_URL}/${BRANCH_NAME}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Set the test branch and url
|
|
if: env.TARGET == 'test'
|
|
env:
|
|
TEST_URL: https://ansible-community.github.io/package-doc-builds
|
|
run: |
|
|
echo "BRANCH=gh-pages" >> "${GITHUB_ENV}"
|
|
echo "ENV_URL=${TEST_URL}" >> "${GITHUB_ENV}"
|
|
|
|
- name: Checkout the deploy directory
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ env.DEST_REPO }}
|
|
ref: ${{ env.BRANCH }}
|
|
path: deploy-directory
|
|
fetch-depth: 0
|
|
ssh-key: ${{ secrets.DEPLOY_DOC_BUILD }}
|
|
persist-credentials: true
|
|
|
|
- name: Copy the generated HTML and assets for production
|
|
run: >-
|
|
rsync -av --delete --mkpath
|
|
ansible-package-docs-html-*/
|
|
deploy-directory/docs
|
|
|
|
- name: Create a norobots.txt file for the test site
|
|
if: env.TARGET == 'test'
|
|
run: |
|
|
touch norobots.txt
|
|
echo "User-agent: *" > norobots.txt
|
|
echo "Disallow: /" >> norobots.txt
|
|
working-directory: deploy-directory/docs
|
|
|
|
- name: Configure the git user
|
|
run: |
|
|
git config --local user.email "${USER_EMAIL}"
|
|
git config --local user.name "${USER_NAME}"
|
|
working-directory: deploy-directory
|
|
|
|
- name: Git add the generated HTML and assets
|
|
run: git add ./docs --all --force
|
|
working-directory: deploy-directory
|
|
|
|
- name: Commit generated HTML and assets
|
|
run: >-
|
|
git diff-index --quiet HEAD ||
|
|
git commit -m "Push docs build $(date '+%Y-%m-%d')-${{
|
|
github.run_id
|
|
}}-${{
|
|
github.run_number
|
|
}}-${{
|
|
github.run_attempt
|
|
}}"
|
|
working-directory: deploy-directory
|
|
|
|
- name: Push build to deploy repository
|
|
run: git push origin
|
|
working-directory: deploy-directory
|