This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow-site-archive.git
The following commit(s) were added to refs/heads/main by this push:
new 3698c84445 Small improvements in github to s3 workflow (#12)
3698c84445 is described below
commit 3698c844453dc80b8d630ab741f3c2931e114482
Author: Jarek Potiuk <[email protected]>
AuthorDate: Fri May 9 22:23:30 2025 +0200
Small improvements in github to s3 workflow (#12)
---
.github/workflows/github-to-s3.yml | 87 ++++++++++++++++++++++++++++++--------
.github/workflows/s3-to-github.yml | 10 +++--
scripts/github_to_s3.py | 28 +++++++-----
scripts/s3_to_github.py | 2 +-
scripts/transfer_utils.py | 2 +-
5 files changed, 94 insertions(+), 35 deletions(-)
diff --git a/.github/workflows/github-to-s3.yml
b/.github/workflows/github-to-s3.yml
index f92e69e300..e0249841d3 100644
--- a/.github/workflows/github-to-s3.yml
+++ b/.github/workflows/github-to-s3.yml
@@ -25,24 +25,24 @@ on: # yamllint disable-line rule:truthy
required: false
default: "s3://live-docs-airflow-apache-org/docs/"
type: string
- local-path:
- description: "The location of the local folder to sync"
- required: false
- default: "./docs-archive"
- type: string
document-folder:
description: "Provide any specific package document folder to sync"
required: false
- default: "NO_DOCS"
+ default: ""
type: string
sync-type:
description: "Perform a full sync or just sync the last commit"
required: false
- default: "last_commit"
+ default: "single_commit"
type: choice
options:
- - last_commit
+ - single_commit
- full_sync
+ commit-sha:
+ description: "If specified, commit SHA used for single_commit (default
is latest commit)"
+ required: false
+ default: ""
+ type: string
processes:
description: "Number of processes to use for syncing"
required: false
@@ -58,6 +58,13 @@ jobs:
with:
python-version: '3.11'
+ - uses: actions/checkout@v4
+ # Checkout only workflow and scripts directory to run scripts from
+ with:
+ sparse-checkout: |
+ .github
+ scripts
+
- name: Install AWS CLI v2
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o
/tmp/awscliv2.zip
@@ -80,20 +87,64 @@ jobs:
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
+ - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} ) for scripts"
+ uses: actions/checkout@v4
+ # Checkout only workflow and scripts directory to run scripts from
+ with:
+ sparse-checkout: |
+ .github
+ scripts
+
- name: Create /mnt/airflow-site-archive directory
- run: sudo mkdir -p /mnt/airflow-site-archive && sudo chown -R
"${USER}" /mnt/airflow-site-archive
+ run: |
+ sudo mkdir -pv /mnt/airflow-site-archive
+ sudo chown -R "${USER}" /mnt/airflow-site-archive
+ ln -v -s /mnt/airflow-site-archive ./airflow-site-archive
- - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
+ - name: Pre-process docs folder
+ env:
+ DOCUMENTS_FOLDER: ${{ inputs.document-folder }}
+ id: docs-folder
run: |
- git clone --depth 2
https://github.com/apache/airflow-site-archive.git /mnt/airflow-site-archive
+ echo "docs-folder=${DOCUMENTS_FOLDER}" >> ${GITHUB_OUTPUT}
+ if [[ "${DOCUMENTS_FOLDER}" != "" ]]; then
+ echo "Preprocessing docs folder: ${DOCUMENTS_FOLDER}"
+ if [[ "${DOCUMENTS_FOLDER}" != apache-airflow-providers* ]]; then
+ echo
"docs-folder=apache-airflow-providers-${DOCUMENTS_FOLDER/./-}" >>
${GITHUB_OUTPUT}
+ fi
+ fi
+
+ - name: >
+ Checkout (${{ inputs.commit-sha || github.sha }}) to
/mnt/airflow-site-archive
+ with docs: ${{ steps.docs-folder.outputs.docs-folder }}"
+ uses: actions/checkout@v4
+ with:
+ path: ./airflow-site-archive
+ fetch-depth: 2
+ sparse-checkout: |
+ docs-archive/${{ steps.docs-folder.outputs.docs-folder }}
+ ref: ${{ inputs.commit-sha || github.sha }}
- - name: "Syncing ${{ github.ref }} ( ${{ github.sha }} )"
+ - name: >
+ Syncing ${{ inputs.commit-sha || github.sha }}:
+ ${{ inputs.sync-type }} ${{ steps.docs-folder.outputs.docs-folder }}"
env:
- COMMIT_SHA: ${{ github.sha }}
+ COMMIT_SHA: ${{ inputs.commit-sha || github.sha }}
+ SYNC_TYPE: ${{ inputs.sync-type }}
+ PROCESSES: ${{ inputs.processes }}
+ DOCUMENTS_FOLDER: ${{ steps.docs-folder.outputs.docs-folder }}
+ DESTINATION_LOCATION: ${{ inputs.destination-location }}
run: |
- ls -la
+ if [[ "${SYNC_TYPE}" == "single_commit" ]]; then
+ echo "Syncing ${COMMIT_SHA}"
+ else
+ echo "Syncing whole repo"
+ fi
+ ls -la /mnt/airflow-site-archive/*
python3 -m pip install uv
- uv run ./scripts/github_to_s3.py --bucket-path
${{inputs.destination-location}} --local-path ${{inputs.local-path}} \
- --document-folder ${{inputs.document-folder}} --commit-sha
${COMMIT_SHA} --sync-type ${{ inputs.sync-type }} \
- --processes ${{ inputs.processes }}
- working-directory: /mnt/airflow-site-archive
+ uv run ./scripts/github_to_s3.py \
+ --bucket-path ${DESTINATION_LOCATION} \
+ --local-path /mnt/airflow-site-archive/docs-archive \
+ --document-folder "${DOCUMENTS_FOLDER}" \
+ --commit-sha ${COMMIT_SHA} --sync-type ${SYNC_TYPE} \
+ --processes ${PROCESSES}
diff --git a/.github/workflows/s3-to-github.yml
b/.github/workflows/s3-to-github.yml
index e0854f35f5..4070192fca 100644
--- a/.github/workflows/s3-to-github.yml
+++ b/.github/workflows/s3-to-github.yml
@@ -33,7 +33,7 @@ on: # yamllint disable-line rule:truthy
document-folder:
description: "Provide any specific package document folder to sync"
required: false
- default: "NO_DOCS"
+ default: ""
type: string
processes:
description: "Number of processes to use for syncing"
@@ -83,9 +83,11 @@ jobs:
- name: Syncing
run: |
python3 -m pip install uv
- uv run ./scripts/s3_to_github.py --bucket-path
${{inputs.source-location}} \
- --local-path ${{inputs.local-destination}} --document-folder
${{inputs.document-folder}} \
- --processes ${{inputs.processes}}
+ uv run ./scripts/s3_to_github.py \
+ --bucket-path ${{inputs.source-location}} \
+ --local-path ${{inputs.local-destination}} \
+ --document-folder "${{inputs.document-folder}}" \
+ --processes ${{inputs.processes}}
working-directory: /mnt/cloned-airflow-site-archive
- name: Commiting changes
diff --git a/scripts/github_to_s3.py b/scripts/github_to_s3.py
index 3f00f4d8cc..b35bafb042 100644
--- a/scripts/github_to_s3.py
+++ b/scripts/github_to_s3.py
@@ -40,7 +40,7 @@ class GithubToS3(CommonTransferUtils):
super().__init__(bucket, local_path)
@staticmethod
- def fetch_last_commit_files(commit_sha, diff_filter="ACM"):
+ def fetch_commit_files(commit_sha, diff_filter="ACM"):
console.print(f"[blue] Fetching files from last commit {commit_sha}
[/]")
cmd = [
"git",
@@ -61,7 +61,7 @@ class GithubToS3(CommonTransferUtils):
return []
return result.stdout.splitlines() if result.stdout else []
- def sync_last_commit_files(self, commit_sha: str, processes: int):
+ def sync_single_commit_files(self, commit_sha: str, processes: int):
'''
There are two parts here.
1. When any file gets removed under docs folder, we will remove from
target location
@@ -70,8 +70,8 @@ class GithubToS3(CommonTransferUtils):
# Fetching `d` excludes deleted files
# Fetching `D` includes deleted files
- files_cp_required = self.fetch_last_commit_files(commit_sha,
diff_filter="d")
- files_del_required = self.fetch_last_commit_files(commit_sha,
diff_filter="D")
+ files_cp_required = self.fetch_commit_files(commit_sha,
diff_filter="d")
+ files_del_required = self.fetch_commit_files(commit_sha,
diff_filter="D")
files_cp_required_under_docs = [f for f in files_cp_required if
f.startswith("docs-archive/")]
files_del_required_required_under_docs = [f for f in
files_del_required if f.startswith("docs-archive/")]
@@ -102,15 +102,19 @@ class GithubToS3(CommonTransferUtils):
self.run_with_pool(self.sync, pool_args, processes=processes)
+def convert_short_name_to_folder_name(short_name: str):
+ if not short_name.startswith("apache-airflow-providers-"):
+ return f"apache-airflow-providers-{short_name.replace('.', '-')}"
+ return short_name
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Sync GitHub to S3")
parser.add_argument("--bucket-path", required=True, help="S3 bucket name
with path")
parser.add_argument("--local-path", required=True, help="local path to
sync")
- parser.add_argument("--document-folder", help="Document folder to sync",
default="")
+ parser.add_argument("--document-folder", help="Document folder to sync (or
short provider-id)", default="")
parser.add_argument("--commit-sha", help="Commit SHA to sync", default="")
- parser.add_argument("--sync-type", help="Sync type", default="last_commit")
+ parser.add_argument("--sync-type", help="Sync type",
default="single_commit")
parser.add_argument("--processes", help="Number of processes", type=int,
default=8)
args = parser.parse_args()
@@ -120,21 +124,23 @@ if __name__ == "__main__":
document_folder = args.document_folder
- if document_folder and document_folder != "NO_DOCS":
+ if document_folder and document_folder != "":
full_local_path = Path(f"{args.local_path}/{document_folder}")
+ if not full_local_path.exists():
+ full_local_path =
Path(f"{args.local_path}/{convert_short_name_to_folder_name(document_folder)}")
if full_local_path.exists():
console.print(f"[blue] Document folder {document_folder} exists in
bucket {args.bucket_path}.[/]")
destination =
f"s3://{syncer.bucket_name}/{syncer.prefix}".rstrip("/") + "/" + document_folder
- syncer.sync(source=full_local_path, destination=destination)
+ syncer.sync(source=full_local_path.as_posix(),
destination=destination)
sys.exit(0)
else:
- console.print(f"[red] Document folder {document_folder} does not
exist in github {args.local_path}.[/]")
+ console.print(f"[red] Document folder {full_local_path} does not
exist.[/]")
sys.exit(1)
- if args.sync_type == "last_commit" and args.commit_sha:
+ if args.sync_type == "single_commit" and args.commit_sha:
console.print(f"[blue] Syncing last commit {args.commit_sha} from
{args.local_path} [/]")
- syncer.sync_last_commit_files(args.commit_sha,
processes=int(args.processes))
+ syncer.sync_single_commit_files(args.commit_sha,
processes=int(args.processes))
sys.exit(0)
if args.sync_type == "full_sync":
diff --git a/scripts/s3_to_github.py b/scripts/s3_to_github.py
index 47636d2b5d..f8240c4703 100644
--- a/scripts/s3_to_github.py
+++ b/scripts/s3_to_github.py
@@ -73,7 +73,7 @@ if __name__ == "__main__":
syncer.check_bucket()
document_folder = args.document_folder
- if document_folder and document_folder != "NO_DOCS":
+ if document_folder and document_folder != "":
if syncer.verify_document_folder(document_folder):
console.print(f"[blue] Document folder {document_folder} exists in
bucket {args.bucket_path}.[/]")
source_prefix = syncer.prefix.rstrip("/") + "/" + document_folder
diff --git a/scripts/transfer_utils.py b/scripts/transfer_utils.py
index 132ff00bd2..bf73d0f6dd 100644
--- a/scripts/transfer_utils.py
+++ b/scripts/transfer_utils.py
@@ -63,7 +63,7 @@ class CommonTransferUtils:
console.print(f"[yellow] Error: {e}[/]")
return []
- def sync(self, source, destination):
+ def sync(self, source: str, destination: str):
console.print(f"[blue] Syncing {source} to {destination} [/]")