Skip to content

Commit c047eaf

Browse files
committed
standalone logging - sudo only for gh actions
1 parent 12ab0ac commit c047eaf

File tree

2 files changed

+121
-2
lines changed

2 files changed

+121
-2
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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

scripts/package.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ CONTAINER_ENGINE="${CONTAINER_ENGINE:-podman}"
1010
# By default, use container for building, but allow using local asciibinder
1111
USE_LOCAL="${USE_LOCAL:-false}"
1212

13+
# Determine if sudo is needed (typically only in GHA if files are created by root in container)
14+
SUDO_CMD=""
15+
if [ "$GITHUB_ACTIONS" == "true" ]; then
16+
echo "Running in GitHub Actions. Sudo prefix will be used if necessary."
17+
SUDO_CMD="sudo"
18+
fi
19+
1320
## CLONE REPO
1421
echo "---> Cloning docs from $BRANCH branch in $REPO"
1522
# Clone OpenShift Docs into current directory
@@ -46,8 +53,8 @@ fi
4653
## MOVING FILES INTO THE RIGHT PLACES
4754
rm -rf ../_package
4855
mkdir -p ../_package
49-
sudo mv _package/${PACKAGE}/* ../_package/
56+
$SUDO_CMD mv _package/${PACKAGE}/* ../_package/
5057
git checkout $BRANCH
5158

5259
cd ..
53-
sudo rm -rf .docs_source
60+
$SUDO_CMD rm -rf .docs_source

0 commit comments

Comments
 (0)