|
| 1 | +name: Package Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + # Allows you to run this workflow manually from the Actions tab |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + package: |
| 8 | + description: 'Package type to build' |
| 9 | + required: true |
| 10 | + default: 'commercial' |
| 11 | + type: string |
| 12 | + branch: |
| 13 | + description: 'Branch to use from openshift-docs' |
| 14 | + required: true |
| 15 | + default: 'standalone-logging-docs-main' |
| 16 | + type: string |
| 17 | + repo: |
| 18 | + description: 'Repository to clone' |
| 19 | + required: true |
| 20 | + default: 'https://github.com/openshift/openshift-docs.git' |
| 21 | + type: string |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Setup environment |
| 32 | + run: | |
| 33 | + mkdir -p build |
| 34 | + sudo apt-get update |
| 35 | + sudo apt-get install -y git |
| 36 | +
|
| 37 | + # Install mikefarah/yq version which has different syntax from python-yq |
| 38 | + wget https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64 -O /usr/local/bin/yq |
| 39 | + sudo chmod +x /usr/local/bin/yq |
| 40 | + yq --version |
| 41 | +
|
| 42 | + - name: Setup Docker |
| 43 | + uses: docker/setup-buildx-action@v3 |
| 44 | + |
| 45 | + - name: Run package script |
| 46 | + run: | |
| 47 | + cd build |
| 48 | + export PACKAGE="${{ github.event.inputs.package }}" |
| 49 | + export BRANCH="${{ github.event.inputs.branch }}" |
| 50 | + export REPO="${{ github.event.inputs.repo }}" |
| 51 | + export CONTAINER_ENGINE="docker" |
| 52 | +
|
| 53 | + # Copy the package.sh script from scripts folder to build directory |
| 54 | + cp ../scripts/package.sh ./ |
| 55 | + chmod +x package.sh |
| 56 | +
|
| 57 | + # Run the packaging script |
| 58 | + ./package.sh |
| 59 | + rm -f package.sh |
| 60 | +
|
| 61 | + - name: Move generated content |
| 62 | + run: | |
| 63 | + # Create or clear the docs directory in the repository root |
| 64 | + rm -rf docs |
| 65 | + mkdir -p docs |
| 66 | +
|
| 67 | + # Copy the packaged content to the docs directory |
| 68 | + cp -r build/_package/* docs/ |
| 69 | +
|
| 70 | + - name: Upload artifacts |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: packaged-docs |
| 74 | + path: docs/ |
| 75 | + |
| 76 | + - name: Create or update gh-pages branch |
| 77 | + run: | |
| 78 | + git config --global user.name "GitHub Actions" |
| 79 | + git config --global user.email "actions@github.com" |
| 80 | +
|
| 81 | + # Create a temporary branch |
| 82 | + git checkout -b temp-docs-branch |
| 83 | +
|
| 84 | + # Add the docs directory |
| 85 | + git add docs/ |
| 86 | +
|
| 87 | + # Commit the changes |
| 88 | + git commit -m "Update packaged documentation" || echo "No changes to commit" |
| 89 | +
|
| 90 | + # Try to create the gh-pages branch if it doesn't exist, or update it if it does |
| 91 | + git fetch origin gh-pages || true |
| 92 | + if git show-ref --quiet refs/remotes/origin/gh-pages; then |
| 93 | + # gh-pages branch exists, update it |
| 94 | + git checkout gh-pages |
| 95 | + git rm -rf . || true |
| 96 | + git checkout temp-docs-branch -- docs/ |
| 97 | + git mv docs/* . || true |
| 98 | + rmdir docs || true |
| 99 | + git add . |
| 100 | + git commit -m "Update GitHub Pages content" || echo "No changes to commit" |
| 101 | + else |
| 102 | + # Create gh-pages branch |
| 103 | + git checkout --orphan gh-pages |
| 104 | + git rm -rf . || true |
| 105 | + git checkout temp-docs-branch -- docs/ |
| 106 | + git mv docs/* . || true |
| 107 | + rmdir docs || true |
| 108 | + git add . |
| 109 | + git commit -m "Initial GitHub Pages content" || echo "No changes to commit" |
| 110 | + fi |
| 111 | +
|
| 112 | + git push origin gh-pages |
0 commit comments