Merge pull request 'Assignment 6: enforce Python CI before merging' (#11) from assignment6/python-ci into main
Reviewed-on: #11 Reviewed-by: nkogut <nkogut@stevens.edu>
This commit was merged in pull request #11.
This commit is contained in:
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
pipeline {
|
||||
agent any
|
||||
options {
|
||||
skipDefaultCheckout()
|
||||
disableConcurrentBuilds()
|
||||
timeout(time: 5, unit: 'MINUTES')
|
||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||
timestamps()
|
||||
}
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
sh 'git rev-parse HEAD'
|
||||
}
|
||||
}
|
||||
stage('Syntax check') {
|
||||
steps {
|
||||
sh 'python3 --version'
|
||||
sh 'python3 -m py_compile pricing.py tests/test_pricing.py'
|
||||
}
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'python3 -m unittest discover -s tests -v'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
## Product Scope
|
||||
|
||||
FilePilot demonstrates a controlled file-update workflow. It accepts a target
|
||||
MyFileAgent demonstrates a controlled file-update workflow. It accepts a target
|
||||
file description, expected text, and replacement text. The application locates
|
||||
the file only within an approved demonstration directory, verifies the expected
|
||||
text, creates a backup, presents a diff, performs the replacement, verifies the
|
||||
result, and records the outcome.
|
||||
|
||||
FilePilot does not provide unrestricted filesystem access, general desktop
|
||||
MyFileAgent does not provide unrestricted filesystem access, general desktop
|
||||
control, arbitrary shell execution, or open-ended autonomous planning.
|
||||
|
||||
## Demonstration Acceptance Criteria
|
||||
|
||||
The demonstration succeeds when FilePilot:
|
||||
The demonstration succeeds when MyFileAgent:
|
||||
|
||||
1. finds the approved project-status file;
|
||||
2. confirms that it contains `Status: Draft`;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Merge this site block into the deployment's existing Caddyfile.
|
||||
# Gitea delivers directly to Jenkins through the private Docker bridge.
|
||||
ci.myfileagent.tech {
|
||||
@giteaHook path /gitea-webhook /gitea-webhook/*
|
||||
respond @giteaHook "Webhook is available only on the private network" 403
|
||||
reverse_proxy jenkins:8080
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
# Assignment 6 Python CI
|
||||
|
||||
The pipeline runs on the trusted Jenkins controller executor. Only trusted
|
||||
team members may change pipeline code. Do not supply secrets or privileged
|
||||
Docker access to untrusted pull requests. Fork PR discovery is disabled.
|
||||
|
||||
The controller uses the official Jenkins LTS image recorded in compose.jenkins.yaml.
|
||||
Python comes from that image's Debian package repositories; record the actual
|
||||
Python version from each build. No pip dependencies or Docker socket are needed.
|
||||
After replacing the container, run `sh ops/jenkins/install-python.sh` on the
|
||||
Droplet before building. A restart retains Python; replacement requires reinstall.
|
||||
Jenkins jobs and settings persist in the jenkins-home volume.
|
||||
|
||||
From the repository root, reproduce checks with:
|
||||
|
||||
python3 -m py_compile pricing.py tests/test_pricing.py
|
||||
python3 -m unittest discover -s tests -v
|
||||
|
||||
Expected: both tests pass. Syntax or test failures must fail the Jenkins run.
|
||||
Multibranch origin PR discovery tests the current PR revision, not a merged revision.
|
||||
The printed checkout commit identifies what was actually tested.
|
||||
|
||||
Webhook delivery, status reporting, branch protection, and the controlled
|
||||
failure/repair demonstration must be configured and verified separately.
|
||||
|
||||
## Gitea webhook and required merge gate
|
||||
|
||||
Configure the repository Gitea webhook with POST, application/json, active,
|
||||
push and pull-request events, branch filter `*`, and target
|
||||
`http://jenkins:8080/gitea-webhook/post`. Gitea must allow the exact `jenkins`
|
||||
host through its webhook destination allowlist; see `compose.webhook.yaml`.
|
||||
The deployed base Compose file includes this same environment setting.
|
||||
The hook is configured manually, so Jenkins does not manage repository hooks.
|
||||
|
||||
The installed Gitea plugin handler does not verify a shared-secret signature.
|
||||
Leave the hook secret empty and use the existing private Docker network.
|
||||
Block `/gitea-webhook` and `/gitea-webhook/*` at the public Caddy site, as in
|
||||
`Caddyfile.jenkins`. Raw port 8080 remains loopback-only. Do not claim HMAC
|
||||
authentication, and do not expose the unsigned receiver publicly.
|
||||
|
||||
Require `myfileagent-python-ci/pipeline/pr-main` on `main`; this is the
|
||||
observed PR-head context. The branch context ending `/pipeline/head` is
|
||||
not the PR context. `main-branch-protection.json` records the applied rule:
|
||||
no direct or force pushes, one approval, dismiss stale approvals, reject
|
||||
changes-requested reviews, and no administrator merge override.
|
||||
|
||||
October 9, 2026 acceptance exercise, linked to issue #10 and PR #11:
|
||||
- PR build 1 passed on ad056a3 after a real pull-request-open webhook.
|
||||
- Commit d6477b3 changed multiplication to addition; PR build 2 failed with
|
||||
`AssertionError: 13 != 30`; Gitea showed the required check failed.
|
||||
- Commit 02d3169 restored multiplication; the webhook started PR build 3,
|
||||
which passed both tests and updated the same required context.
|
||||
- PR #11 remains open for reviewer nkogut. No review approval or merge has
|
||||
been performed by automation.
|
||||
|
||||
For delivery diagnosis, inspect Gitea's recent delivery response and compare
|
||||
its event/head SHA with Jenkins' console. A 200 `Processed` delivery alone
|
||||
is not proof that tests passed. Save the failed and repaired PR gate views
|
||||
before further commits. A new commit needs a new success status and review.
|
||||
@@ -0,0 +1,17 @@
|
||||
services:
|
||||
jenkins:
|
||||
image: jenkins/jenkins@sha256:a660310e39ade10631f774bacd5219de767dfd08947ea5c32a739b5e5bb382c1
|
||||
container_name: myfileagent-jenkins
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
JAVA_OPTS: "-Xms64m -Xmx256m"
|
||||
mem_limit: 448m
|
||||
ports:
|
||||
- "127.0.0.1:8080:8080"
|
||||
volumes:
|
||||
- jenkins-home:/var/jenkins_home
|
||||
networks:
|
||||
- gitea-private
|
||||
|
||||
volumes:
|
||||
jenkins-home:
|
||||
@@ -0,0 +1,7 @@
|
||||
# Apply with the existing base compose.yaml and compose.jenkins.yaml.
|
||||
# Allows only the named Jenkins destination in addition to Gitea's default
|
||||
# external destinations; never use '*' to allow every private address.
|
||||
services:
|
||||
gitea:
|
||||
environment:
|
||||
GITEA__webhook__ALLOWED_HOST_LIST: "external,jenkins"
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
# Run on the Droplet after recreating the official Jenkins container.
|
||||
# Python installed in the container survives restart, not container replacement.
|
||||
set -eu
|
||||
docker exec -u root myfileagent-jenkins sh -c 'apt-get update -qq && apt-get install -y --no-install-recommends python3'
|
||||
docker exec myfileagent-jenkins python3 --version
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"branch_name": "main",
|
||||
"rule_name": "main",
|
||||
"priority": 1,
|
||||
"enable_push": false,
|
||||
"enable_push_whitelist": false,
|
||||
"push_whitelist_usernames": [],
|
||||
"push_whitelist_teams": [],
|
||||
"push_whitelist_deploy_keys": false,
|
||||
"enable_force_push": false,
|
||||
"enable_force_push_allowlist": false,
|
||||
"force_push_allowlist_usernames": [],
|
||||
"force_push_allowlist_teams": [],
|
||||
"force_push_allowlist_deploy_keys": false,
|
||||
"enable_merge_whitelist": false,
|
||||
"merge_whitelist_usernames": [],
|
||||
"merge_whitelist_teams": [],
|
||||
"enable_bypass_allowlist": false,
|
||||
"bypass_allowlist_usernames": [],
|
||||
"bypass_allowlist_teams": [],
|
||||
"enable_status_check": true,
|
||||
"status_check_contexts": [
|
||||
"myfileagent-python-ci/pipeline/pr-main"
|
||||
],
|
||||
"required_approvals": 1,
|
||||
"enable_approvals_whitelist": false,
|
||||
"approvals_whitelist_username": [],
|
||||
"approvals_whitelist_teams": [],
|
||||
"block_on_rejected_reviews": true,
|
||||
"block_on_official_review_requests": true,
|
||||
"block_on_outdated_branch": false,
|
||||
"dismiss_stale_approvals": true,
|
||||
"ignore_stale_approvals": false,
|
||||
"require_signed_commits": false,
|
||||
"protected_file_patterns": "",
|
||||
"unprotected_file_patterns": "",
|
||||
"block_admin_merge_override": true,
|
||||
"created_at": "2026-10-09T19:03:48Z",
|
||||
"updated_at": "2026-10-09T19:04:32Z"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
def total_price(unit_price, quantity):
|
||||
if quantity < 1:
|
||||
raise ValueError("Quantity must be positive")
|
||||
return unit_price * quantity
|
||||
@@ -0,0 +1,11 @@
|
||||
import unittest
|
||||
from pricing import total_price
|
||||
|
||||
|
||||
class PricingTests(unittest.TestCase):
|
||||
def test_total(self):
|
||||
self.assertEqual(total_price(10, 3), 30)
|
||||
|
||||
def test_invalid_quantity(self):
|
||||
with self.assertRaises(ValueError):
|
||||
total_price(10, 0)
|
||||
Reference in New Issue
Block a user