Skip to content

Commit bd0916b

Browse files
authored
Merge branch 'master' into copilot/fix-260
2 parents db4aa6f + 05a4b96 commit bd0916b

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

.github/scripts/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# GitHub Scripts and Automation
2+
3+
This directory contains scripts and documentation for GitHub Actions automation in the Orionrobots repository.
4+
5+
## Features
6+
7+
### Automated Docker Image PR Comments
8+
9+
When a Pull Request modifies files that affect the base Docker image (such as `Dockerfile`, `package.json`, `package-lock.json`, or workflow files), the CI system automatically:
10+
11+
1. **Detects changes** to base image related files
12+
2. **Builds and pushes** a Docker image tagged with the PR number to `ghcr.io/orionrobots/orionrobots-site.base:${PR_NUMBER}`
13+
3. **Comments on the PR** with a direct link to the newly built Docker image
14+
15+
#### How it works
16+
17+
The automation is implemented in `.github/workflows/on_pr_test.yaml`:
18+
19+
- **Detection**: The `detect_base_image_changes` job uses `tj-actions/changed-files` to detect changes to base image files
20+
- **Build**: If changes are detected, the `build_site` job builds and pushes the image with the PR number as tag
21+
- **Comment**: The `comment_docker_image` job creates or updates a comment on the PR with the image details
22+
23+
#### Benefits
24+
25+
- **Easy access**: Reviewers and team members can quickly find and use the Docker image built for a specific PR
26+
- **No searching**: No need to dig through workflow logs or GitHub Package registry
27+
- **Idempotent**: Comments are updated rather than duplicated when the image is rebuilt
28+
- **Clear instructions**: The comment includes copy-paste commands for using the image
29+
30+
#### Comment format
31+
32+
The automated comment includes:
33+
- Direct link to the Docker image
34+
- Instructions for pulling and running the image
35+
- Usage examples for local development
36+
- Clear indication that the comment is automatically managed
37+
38+
#### Permissions and fork compatibility
39+
40+
- **Internal PRs**: Full functionality with automatic image building and commenting
41+
- **Forks**: May have limited access to push images depending on repository settings
42+
- **Security**: Uses minimal required permissions (`pull-requests: write` for commenting)
43+
44+
### Scripts
45+
46+
- `new_post.sh`: Script for creating new blog posts with proper folder structure
47+
- `staging/`: Configuration files for staging environment setup
48+
49+
## Maintenance
50+
51+
The Docker image commenting system is self-maintaining and requires no manual intervention. If issues arise:
52+
53+
1. Check the workflow logs in GitHub Actions
54+
2. Verify that the GitHub token has appropriate permissions
55+
3. Ensure the base image build completed successfully before the comment job runs

.github/workflows/on_pr_test.yaml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
- '.github/workflows/on_push_to_master_test_and_deploy.yaml'
2020
- '.github/workflows/on_call_build_site.yaml'
2121
- '.github/workflows/on_call_staging_test.yaml'
22+
- '.github/workflows/on_pr_test.yaml'
2223
- 'package.json'
2324
- 'package-lock.json'
2425
- 'webpack.config.js'
@@ -58,6 +59,76 @@ jobs:
5859
${{ needs.detect_base_image_changes.outputs.changed == 'true'
5960
&& github.event.number || '' }}
6061
62+
comment_docker_image:
63+
needs: [detect_base_image_changes, build_site]
64+
runs-on: ubuntu-latest
65+
# Only run if base image changes were detected and this is a PR event
66+
if: needs.detect_base_image_changes.outputs.changed == 'true' && github.event_name == 'pull_request'
67+
permissions:
68+
pull-requests: write # Allow commenting on PR
69+
steps:
70+
- name: Comment on PR with Docker image link
71+
uses: actions/github-script@v7
72+
with:
73+
script: |
74+
const prNumber = context.issue.number;
75+
const imageTag = prNumber;
76+
const imageUrl = `ghcr.io/orionrobots/orionrobots-site.base:${imageTag}`;
77+
78+
// Comment body with Docker image information
79+
const commentBody = `## 🐳 Docker Base Image Available
80+
81+
A new base Docker image has been built and pushed for this PR:
82+
83+
**Image:** \`${imageUrl}\`
84+
85+
### How to use this image:
86+
87+
\`\`\`bash
88+
# Pull the image
89+
docker pull ${imageUrl}
90+
91+
# Run with the image
92+
docker run -it ${imageUrl} bash
93+
\`\`\`
94+
95+
### For local development:
96+
You can use this image as a base for testing changes without rebuilding dependencies.
97+
98+
_This comment is automatically updated when the base image is rebuilt._`;
99+
100+
// Look for existing comment from this bot
101+
const comments = await github.rest.issues.listComments({
102+
owner: context.repo.owner,
103+
repo: context.repo.repo,
104+
issue_number: prNumber,
105+
});
106+
107+
const botComment = comments.data.find(comment =>
108+
comment.user.type === 'Bot' &&
109+
comment.body.includes('🐳 Docker Base Image Available')
110+
);
111+
112+
if (botComment) {
113+
// Update existing comment
114+
await github.rest.issues.updateComment({
115+
owner: context.repo.owner,
116+
repo: context.repo.repo,
117+
comment_id: botComment.id,
118+
body: commentBody
119+
});
120+
console.log('Updated existing Docker image comment');
121+
} else {
122+
// Create new comment
123+
await github.rest.issues.createComment({
124+
owner: context.repo.owner,
125+
repo: context.repo.repo,
126+
issue_number: prNumber,
127+
body: commentBody
128+
});
129+
console.log('Created new Docker image comment');
130+
}
131+
61132
staging_test:
62133
uses: ./.github/workflows/on_call_staging_test.yaml
63134
needs: build_site

0 commit comments

Comments
 (0)