Skip to content

Commit de8215a

Browse files
committed
first test
1 parent fa27d82 commit de8215a

File tree

3 files changed

+233
-14
lines changed

3 files changed

+233
-14
lines changed

.github/workflows/docs-build-deploy.yaml

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Run tests, build PD, and deploy it to sandbox
2-
31
name: 'Docs build and deploy'
42

53
on:
@@ -9,10 +7,13 @@ on:
97
- '.github/workflows/docs-build-deploy.yaml'
108
push:
119
branches:
12-
- 'edge'
10+
- 'docs-testing-jesse'
11+
tags:
12+
- 'staging-*'
13+
- 'production-*'
1314

1415
concurrency:
15-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.ref_name != 'edge' || github.run_id}}-${{ github.ref_type != 'tag' || github.run_id }}
16+
group: ${{ github.workflow }}-${{ github.ref }}
1617
cancel-in-progress: true
1718

1819
defaults:
@@ -21,8 +22,8 @@ defaults:
2122

2223
jobs:
2324
sandbox-build-and-deploy-flex-manual:
24-
timeout-minutes: 5
25-
runs-on: 'ubuntu-24.04'
25+
if: github.event_name != 'push' || !startsWith(github.ref, 'refs/tags/')
26+
runs-on: ubuntu-24.04
2627
permissions:
2728
id-token: write
2829
contents: read
@@ -50,8 +51,80 @@ jobs:
5051
run: make build-flex-manual
5152
- name: Deploy Flex Manual to Sandbox
5253
working-directory: ./docs
53-
run: make deploy-flex-manual BRANCH=${{ env.BRANCH }}
54+
run: python deploy_flex_manual.py sandbox --branch ${{ env.BRANCH }}
5455
- name: Output URL to Summary
5556
run: |
5657
echo "## Flex Manual deployed to sandbox" >> $GITHUB_STEP_SUMMARY
5758
echo "<http://sandbox.docs.s3-website.us-east-2.amazonaws.com/${{ env.BRANCH }}/flex-manual/>" >> $GITHUB_STEP_SUMMARY
59+
60+
staging-build-and-deploy-flex-manual:
61+
if: startsWith(github.ref, 'refs/tags/staging-')
62+
runs-on: ubuntu-24.04
63+
permissions:
64+
id-token: write
65+
contents: read
66+
env:
67+
BRANCH: ${{ github.ref_name }}
68+
steps:
69+
- name: Configure AWS Credentials
70+
uses: aws-actions/configure-aws-credentials@v4
71+
with:
72+
role-to-assume: ${{ secrets.DOCS_STAGING_ROLE }}
73+
aws-region: us-east-2
74+
- name: 'Checkout Repository'
75+
uses: actions/checkout@v4
76+
- name: Setup UV
77+
uses: astral-sh/setup-uv@v6
78+
with:
79+
python-version: '3.10'
80+
enable-cache: true
81+
cache-dependency-glob: './docs/uv.lock'
82+
- name: Sync the project
83+
working-directory: ./docs
84+
run: make setup
85+
- name: Build Flex Manual
86+
working-directory: ./docs
87+
run: make build-flex-manual
88+
- name: Deploy Flex Manual to Staging
89+
working-directory: ./docs
90+
run: python deploy_flex_manual.py staging --branch ${{ env.BRANCH }}
91+
- name: Output URL to Summary
92+
run: |
93+
echo "## Flex Manual deployed to staging" >> $GITHUB_STEP_SUMMARY
94+
echo "<https://staging.docs.opentrons.com/${{ env.BRANCH }}/flex-manual/>" >> $GITHUB_STEP_SUMMARY
95+
96+
production-build-and-deploy-flex-manual:
97+
if: startsWith(github.ref, 'refs/tags/production-')
98+
runs-on: ubuntu-24.04
99+
permissions:
100+
id-token: write
101+
contents: read
102+
env:
103+
BRANCH: ${{ github.ref_name }}
104+
steps:
105+
- name: Configure AWS Credentials
106+
uses: aws-actions/configure-aws-credentials@v4
107+
with:
108+
role-to-assume: ${{ secrets.DOCS_PRODUCTION_ROLE }}
109+
aws-region: us-east-2
110+
- name: 'Checkout Repository'
111+
uses: actions/checkout@v4
112+
- name: Setup UV
113+
uses: astral-sh/setup-uv@v6
114+
with:
115+
python-version: '3.10'
116+
enable-cache: true
117+
cache-dependency-glob: './docs/uv.lock'
118+
- name: Sync the project
119+
working-directory: ./docs
120+
run: make setup
121+
- name: Build Flex Manual
122+
working-directory: ./docs
123+
run: make build-flex-manual
124+
- name: Deploy Flex Manual to Production
125+
working-directory: ./docs
126+
run: python deploy_flex_manual.py production --branch ${{ env.BRANCH }}
127+
- name: Output URL to Summary
128+
run: |
129+
echo "## Flex Manual deployed to production" >> $GITHUB_STEP_SUMMARY
130+
echo "<https://docs.opentrons.com/${{ env.BRANCH }}/flex-manual/>" >> $GITHUB_STEP_SUMMARY

docs/Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FLEX_MANUAL_PREFIX ?= flex-manual
22
# AWS_PROFILE is intentionally left undefined by default
33
BRANCH ?= edge
4-
SANDBOX_S3_BUCKET ?= sandbox.docs
54

65
.PHONY: setup
76
setup:
@@ -15,9 +14,18 @@ serve-flex-manual:
1514
build-flex-manual:
1615
uv run mkdocs build -f $(FLEX_MANUAL_PREFIX)/mkdocs.yml
1716

18-
.PHONY: deploy-flex-manual
19-
deploy-flex-manual:
20-
@if [ -n "$$CI" ]; then \
21-
echo "If you need to run this locally, set the variable AWS_PROFILE."; \
22-
fi
23-
aws s3 sync $(FLEX_MANUAL_PREFIX)/site/ s3://$(SANDBOX_S3_BUCKET)/$(BRANCH)/$(FLEX_MANUAL_PREFIX)/ --delete --acl public-read $(if $(AWS_PROFILE),--profile $(AWS_PROFILE))
17+
.PHONY: deploy-flex-manual-sandbox
18+
deploy-flex-manual-sandbox:
19+
python deploy_flex_manual.py sandbox $(if $(BRANCH),--branch $(BRANCH)) $(if $(AWS_PROFILE),--aws-profile $(AWS_PROFILE)) $(if $(FLEX_MANUAL_PREFIX),--flex-manual-prefix $(FLEX_MANUAL_PREFIX))
20+
21+
.PHONY: deploy-flex-manual-staging
22+
deploy-flex-manual-staging:
23+
python deploy_flex_manual.py staging $(if $(BRANCH),--branch $(BRANCH)) $(if $(AWS_PROFILE),--aws-profile $(AWS_PROFILE)) $(if $(FLEX_MANUAL_PREFIX),--flex-manual-prefix $(FLEX_MANUAL_PREFIX))
24+
25+
.PHONY: deploy-flex-manual-production
26+
deploy-flex-manual-production:
27+
python deploy_flex_manual.py production $(if $(BRANCH),--branch $(BRANCH)) $(if $(AWS_PROFILE),--aws-profile $(AWS_PROFILE)) $(if $(FLEX_MANUAL_PREFIX),--flex-manual-prefix $(FLEX_MANUAL_PREFIX))
28+
29+
# Backward compatibility - defaults to sandbox
30+
#.PHONY: deploy-flex-manual
31+
#deploy-flex-manual: deploy-flex-manual-sandbox

docs/deploy-flex-manual.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
script_content = '''#!/usr/bin/env python3
2+
"""
3+
Deploy Flex Manual to S3
4+
Replaces the deploy-flex-manual Makefile target with staging/production/sandbox support
5+
"""
6+
7+
import argparse
8+
import os
9+
import subprocess
10+
import sys
11+
from pathlib import Path
12+
13+
14+
def run_command(cmd, check=True):
15+
"""Run a shell command and return the result"""
16+
print(f"Running: {' '.join(cmd)}")
17+
result = subprocess.run(cmd, check=check, capture_output=True, text=True)
18+
if result.stdout:
19+
print(result.stdout)
20+
if result.stderr:
21+
print(result.stderr, file=sys.stderr)
22+
return result
23+
24+
25+
def deploy_flex_manual(environment, branch=None, aws_profile=None, flex_manual_prefix="flex-manual"):
26+
"""Deploy flex manual to S3"""
27+
28+
# Environment-specific bucket configuration
29+
buckets = {
30+
"sandbox": "sandbox.docs", # Your current sandbox bucket
31+
"staging": "opentrons.staging.docs", # Replace with your staging bucket
32+
"production": "opentrons.production.docs" # Replace with your production bucket
33+
}
34+
35+
if environment not in buckets:
36+
print(f"Error: Environment must be one of {list(buckets.keys())}")
37+
sys.exit(1)
38+
39+
bucket = buckets[environment]
40+
41+
# Default branch based on environment
42+
if branch is None:
43+
if environment == "sandbox":
44+
branch = "edge"
45+
elif environment == "staging":
46+
branch = "edge"
47+
else: # production
48+
branch = "main"
49+
50+
# Check if we're in CI
51+
is_ci = os.getenv("CI") is not None
52+
if is_ci:
53+
print("Running in CI environment")
54+
elif aws_profile is None:
55+
print("Warning: AWS_PROFILE not set. Make sure you have AWS credentials configured.")
56+
57+
# Verify source directory exists
58+
source_dir = Path(flex_manual_prefix) / "site"
59+
if not source_dir.exists():
60+
print(f"Error: Source directory {source_dir} does not exist.")
61+
print("Make sure you've run 'make build-flex-manual' first.")
62+
sys.exit(1)
63+
64+
# Build S3 sync command
65+
s3_path = f"s3://{bucket}/{branch}/{flex_manual_prefix}/"
66+
cmd = [
67+
"aws", "s3", "sync",
68+
str(source_dir) + "/",
69+
s3_path,
70+
"--delete",
71+
"--acl", "public-read"
72+
]
73+
74+
# Add AWS profile if specified
75+
if aws_profile:
76+
cmd.extend(["--profile", aws_profile])
77+
78+
print(f"Deploying to {environment} environment:")
79+
print(f" Bucket: {bucket}")
80+
print(f" Branch: {branch}")
81+
print(f" S3 Path: {s3_path}")
82+
83+
try:
84+
run_command(cmd)
85+
print(f"✅ Successfully deployed to {environment}!")
86+
87+
# Print the URL where it's deployed
88+
url = f"https://{bucket}/{branch}/{flex_manual_prefix}/"
89+
print(f"📍 Deployed to: {url}")
90+
91+
except subprocess.CalledProcessError as e:
92+
print(f"❌ Deployment failed with exit code {e.returncode}")
93+
sys.exit(1)
94+
95+
96+
def main():
97+
parser = argparse.ArgumentParser(description="Deploy Flex Manual to S3")
98+
parser.add_argument(
99+
"environment",
100+
choices=["sandbox", "staging", "production"],
101+
help="Deployment environment"
102+
)
103+
parser.add_argument(
104+
"--branch",
105+
help="Branch name (defaults to 'edge' for sandbox/staging, 'main' for production)"
106+
)
107+
parser.add_argument(
108+
"--aws-profile",
109+
help="AWS profile to use (defaults to AWS_PROFILE env var)"
110+
)
111+
parser.add_argument(
112+
"--flex-manual-prefix",
113+
default="flex-manual",
114+
help="Flex manual prefix directory (default: flex-manual)"
115+
)
116+
117+
args = parser.parse_args()
118+
119+
# Use AWS_PROFILE env var if not specified
120+
aws_profile = args.aws_profile or os.getenv("AWS_PROFILE")
121+
122+
deploy_flex_manual(
123+
environment=args.environment,
124+
branch=args.branch,
125+
aws_profile=aws_profile,
126+
flex_manual_prefix=args.flex_manual_prefix
127+
)
128+
129+
130+
if __name__ == "__main__":
131+
main()
132+
'''
133+
134+
# Write the script to a file
135+
with open('deploy_flex_manual.py', 'w') as f:
136+
f.write(script_content)
137+
138+
print("Updated deploy_flex_manual.py with sandbox support")

0 commit comments

Comments
 (0)