Skip to content

Commit aa0aa4d

Browse files
committed
Use the workflow file associate git reference
1 parent 3ec9561 commit aa0aa4d

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed

.github/workflows/docs-ci.yml

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,64 @@ jobs:
88
build:
99
runs-on: "ubuntu-latest"
1010
steps:
11+
# The git reference for the workflow isn't acessible directly. That's a workaround:
12+
# https://github.com/actions/toolkit/issues/1264#issuecomment-2496121368
13+
- name: "Get called workflow reference"
14+
run: |
15+
JWT=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL")
16+
PAYLOAD=$(echo "$JWT" | cut -d '.' -f 2 | base64 -d 2>/dev/null || true)
17+
18+
WORKFLOW_FULL_REF=$(
19+
echo "$PAYLOAD" \
20+
| grep -o '"job_workflow_ref":"[^"]*"' \
21+
| cut -d':' -f2 \
22+
| cut -d'@' -f2 \
23+
| tr -d '"'
24+
)
25+
26+
echo "WORKFLOW_FULL_REF=$WORKFLOW_FULL_REF"
27+
28+
case $WORKFLOW_FULL_REF in
29+
refs/heads/*)
30+
WORKFLOW_REF=${WORKFLOW_FULL_REF#refs/heads/}
31+
;;
32+
refs/tags/*)
33+
WORKFLOW_REF=${WORKFLOW_FULL_REF#refs/tags/}
34+
;;
35+
refs/pull/*/merge)
36+
# exception: we got triggered by a pull request, the ref is the base branch
37+
WORKFLOW_REF=$GITHUB_HEAD_REF
38+
;;
39+
esac
40+
41+
echo "::notice ::WORKFLOW_FULL_REF=$WORKFLOW_FULL_REF"
42+
echo "::notice ::WORKFLOW_REF=$WORKFLOW_REF"
43+
44+
echo "WORKFLOW_REF=$WORKFLOW_REF" | tee -a $GITHUB_ENV
45+
46+
- name: "Checkout pulp-docs repository"
47+
uses: "actions/checkout@v4"
48+
with:
49+
repository: "pulp/pulp-docs"
50+
path: "pulp-docs"
51+
ref: "${{ env.WORKFLOW_REF }}"
52+
fetch-depth: 0
53+
54+
- name: "Get pulp-docs commit"
55+
working-directory: "pulp-docs"
56+
run: |
57+
set -e
58+
echo "CHECKOUT_SHA=$(git rev-parse HEAD)" | tee -a $GITHUB_ENV
1159
1260
- name: "Instructions to run locally"
13-
shell: "bash"
1461
run: |
1562
cat <<EOL
16-
To run this locally, make sure:
17-
1. You have pulp-docs and your plugin checkout in the same dir.
18-
2. You have the latest pulp-docs availabe in your python environment
19-
20-
Then run:
63+
Assuming you have pulp-docs and your plugin checkout in the same dir, run:
2164
2265
cd pulp-docs
66+
git checkout ${{ env.CHECKOUT_SHA }}
2367
pulp-docs fetch --dest /tmp/pulp-docs-tmp
2468
pulp-docs build --path pulp-docs@..:${{ github.event.repository.name }}@..:/tmp/pulp-docs-tmp
25-
2669
EOL
2770
2871
# The caller repository and context is used
@@ -32,16 +75,6 @@ jobs:
3275
with:
3376
path: "${{ github.event.repository.name }}"
3477

35-
- name: "Checkout pulp-docs repository"
36-
uses: "actions/checkout@v4"
37-
with:
38-
repository: "pulp/pulp-docs"
39-
path: "pulp-docs"
40-
# ref: "rewrite-as-mkdocs-plugin"
41-
# TODO: revert. using this because pulpcore-selinux is not included in rewrite-as-mkdocs-plugin
42-
ref: "experiment-reusable-ci-workflow"
43-
fetch-depth: 0
44-
4578
- uses: "actions/setup-python@v5"
4679
with:
4780
python-version: "3.12"
@@ -54,15 +87,15 @@ jobs:
5487
5588
- name: "Build Docs"
5689
working-directory: "pulp-docs"
90+
env:
91+
DOCS_PATH: "pulp-docs@..:${{ github.event.repository.name }}@.."
92+
DOCS_TMPDIR: "/tmp/pulp-docs-tmp"
5793
run: |
58-
PATH="pulp-docs@..:${{ github.event.repository.name }}@.."
59-
TMPDIR="/tmp/pulp-docs-tmp"
60-
pulp-docs fetch --path "$PATH" --dest "$TMPDIR"
61-
pulp-docs build --path "$PATH:$TMPDIR"
94+
pulp-docs fetch --path-exclude "$DOCS_PATH" --dest "$DOCS_TMPDIR"
95+
pulp-docs build --path "$DOCS_PATH:$DOCS_TMPDIR"
6296
6397
- name: "Sanity Check"
6498
working-directory: "pulp-docs"
65-
shell: "bash"
6699
run: |
67100
echo "Checking that the namespace for the component under CI exists in the built docs."
68101
ls "site/${{ github.event.repository.name }}/docs"

.github/workflows/pr.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ concurrency:
1010

1111
jobs:
1212
docs:
13+
permissions:
14+
contents: "read"
15+
id-token: "write"
1316
uses: "./.github/workflows/docs-ci.yml"
1417

1518
tests:
19+
needs: "docs"
1620
uses: "./.github/workflows/tests.yml"
1721

1822
ready-to-ship:

src/pulp_docs/cli.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,19 @@ async def clone_repository(repo_url: str) -> None:
101101
envvar="PULPDOCS_DIR",
102102
help="Path to mkdocs.yml config file",
103103
)
104-
@path_option
105-
def fetch(dest, config_file, find_path):
104+
@click.option(
105+
"--path-exclude",
106+
default="",
107+
callback=find_path_callback,
108+
help="A colon separated list of lookup paths to exclude in the form [repo1@]path1 [:[repo2@]path2 [...]].",
109+
)
110+
def fetch(dest, config_file, path_exclude):
106111
"""Fetch repositories to destination dir."""
107112
dest_path = Path(dest)
108-
config = load_config(config_file)
109-
all_components = config.plugins["PulpDocs"].config.components
113+
pulpdocs_plugin = load_config(config_file).plugins["PulpDocs"]
114+
all_components = pulpdocs_plugin.config.components
110115
all_repositories_set = {r.git_url for r in all_components if r.git_url}
111-
found_components = load_components(find_path, config_file, draft=True)
116+
found_components = load_components(path_exclude, pulpdocs_plugin.config, draft=True)
112117
found_repositories_set = {r.git_url for r in found_components}
113118
final_repositories_set = all_repositories_set - found_repositories_set
114119

src/pulp_docs/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def rss_items() -> list:
257257
return rss_feed["items"][:20]
258258

259259

260-
def load_components(find_path: list[str], config: MkDocsConfig, draft: bool):
260+
def load_components(find_path: list[str], config: PulpDocsPluginConfig, draft: bool):
261261
loaded_components = []
262262
for component_opt in config.components:
263263
component = Component.build(find_path, component_opt)

0 commit comments

Comments
 (0)