Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 58 additions & 26 deletions .github/workflows/publish-learn-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,77 @@ on:
types: [completed]

jobs:
trigger:
publish:
runs-on: ubuntu-24.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}

# strategy:
# matrix:
# python-version: ['3.12']
# node-version: [24.x]

steps:
- name: Trigger publishing on learn-latest repo
- name: Look up Sphinx Content Tests run ID
id: lookup
env:
LEARN_REPO_TOKEN: ${{ secrets.LEARN_READ_TOKEN }}
LEARN_LATEST_REPO_TOKEN: ${{ secrets.LEARN_LATEST_WRITE_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
BOOKS_RUN_ID: ${{ github.event.workflow_run.id }}
SOURCE_REPO: ${{ github.repository }}
run: |
# Set the required variables
repo_owner="AdaCore"
repo_name="learn-latest-html-pages"
event_type="trigger-workflow"
service="publish-learn-latest"

# Look up the successful Sphinx Content Tests run ID for the same commit
# (read-only access to AdaCore/learn)
content_run_id=$(curl -L --fail-with-body \
-H "Authorization: Bearer $LEARN_REPO_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$SOURCE_REPO/actions/workflows/sphinx-content-tests.js.yml/runs?head_sha=$HEAD_SHA&status=success&per_page=1" \
| jq -r '.workflow_runs[0].id')
echo "content_run_id=$content_run_id" >> $GITHUB_OUTPUT

# Trigger the publish workflow on AdaCore/learn-latest-html-pages
# (write access to AdaCore/learn-latest-html-pages)
curl -L --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $LEARN_LATEST_REPO_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"service\": \"$service\", \"version\": \"$HEAD_SHA\", \"books_run_id\": \"$BOOKS_RUN_ID\", \"content_run_id\": \"$content_run_id\", \"source_repo\": \"$SOURCE_REPO\", \"unit\": false, \"integration\": true}}"
- name: Download HTML artifact
uses: actions/download-artifact@v4
with:
name: learn-html
path: unzipped_html
run-id: ${{ steps.lookup.outputs.content_run_id }}
github-token: ${{ secrets.LEARN_READ_TOKEN }}

- name: Download PDF books artifact
uses: actions/download-artifact@v4
with:
name: learn-pdf-books
path: unzipped_pdf_books
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.LEARN_READ_TOKEN }}

- name: Download EPUB books artifact
uses: actions/download-artifact@v4
with:
name: learn-epub-books
path: unzipped_epub_books
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.LEARN_READ_TOKEN }}

- name: Checkout learn-latest-html-pages
uses: actions/checkout@v4
with:
repository: AdaCore/learn-latest-html-pages
ref: gh-pages
token: ${{ secrets.LEARN_LATEST_WRITE_TOKEN }}
path: learn-latest-html-pages

- name: Publish content
run: |
TARGET=learn-latest-html-pages

rm -rf $TARGET/_sources
( cd $TARGET/docs \
&& rm -rf *.* courses booklets _images labs _static _plantuml \
training_examples pdf_books epub_books zip )
rsync -avz ./unzipped_html/ $TARGET/docs/
rsync -avz ./unzipped_pdf_books/ $TARGET/docs/pdf_books/
rsync -avz ./unzipped_epub_books/ $TARGET/docs/epub_books/
mv $TARGET/docs/_sources $TARGET/
rm -rf $TARGET/docs/_plantuml

- name: Commit and push
working-directory: learn-latest-html-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add docs/ _sources
git commit -m "Publish learn-latest ${{ github.event.workflow_run.head_sha }}"
git push
Loading