|
| 1 | +# GitHub Actions Workflow - Quick Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This repository uses GitHub Actions to automatically validate and deploy Jenkins Job Builder (JJB) configurations. |
| 6 | + |
| 7 | +**Two Workflows:** |
| 8 | +1. **Validation** (`test.yaml`) - Runs on Pull Requests |
| 9 | +2. **Deployment** (`deploy.yaml`) - Runs on merge to `centos-ci` branch |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Workflow Architecture |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +**Simple Flow:** |
| 18 | +``` |
| 19 | +Developer → Pull Request → test.yaml (Validate) → Merge → deploy.yaml (Deploy) → Jenkins Updated |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 1. Validation Workflow (`test.yaml`) |
| 25 | + |
| 26 | +**Trigger:** Pull Request to any branch |
| 27 | + |
| 28 | +**What it does:** |
| 29 | +- Builds Docker container with JJB |
| 30 | +- Validates YAML syntax |
| 31 | +- Checks macro references |
| 32 | +- **Does NOT** connect to Jenkins |
| 33 | + |
| 34 | +**File:** `.github/workflows/test.yaml` |
| 35 | + |
| 36 | +```yaml |
| 37 | +on: |
| 38 | + pull_request: |
| 39 | + branches: ['*'] |
| 40 | +steps: |
| 41 | + - Checkout code |
| 42 | + - Build Docker image |
| 43 | + - Run: jenkins-jobs test (validation only) |
| 44 | +``` |
| 45 | +
|
| 46 | +--- |
| 47 | +
|
| 48 | +## 2. Deployment Workflow (`deploy.yaml`) |
| 49 | + |
| 50 | +**Trigger:** Push to `centos-ci` branch |
| 51 | + |
| 52 | +**What it does:** |
| 53 | +- Builds Docker container with JJB |
| 54 | +- Injects Jenkins API key |
| 55 | +- Connects to Jenkins |
| 56 | +- Creates/updates jobs |
| 57 | + |
| 58 | +**File:** `.github/workflows/deploy.yaml` |
| 59 | + |
| 60 | +```yaml |
| 61 | +on: |
| 62 | + push: |
| 63 | + branches: ['centos-ci'] |
| 64 | +steps: |
| 65 | + - Checkout code |
| 66 | + - Build Docker image |
| 67 | + - Run: jenkins-jobs update (actual deployment) |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## Supporting Files |
| 73 | + |
| 74 | +### `tests/Containerfile` |
| 75 | +Docker image with JJB installed |
| 76 | + |
| 77 | +### `tests/verify-yaml.sh` |
| 78 | +```bash |
| 79 | +jenkins-jobs test globals/macros:jobs |
| 80 | +``` |
| 81 | +Validates syntax without Jenkins connection |
| 82 | + |
| 83 | +### `tests/deploy-nfs-ganesha-ci.sh` |
| 84 | +```bash |
| 85 | +sed "s/JENKINS_API_KEY/$JENKINS_API_KEY/g" tests/jenkins.conf > jobs/jenkins.ini |
| 86 | +jenkins-jobs --conf jobs/jenkins.ini update jobs/:globals/macros/ |
| 87 | +``` |
| 88 | +Injects API key and deploys to Jenkins |
| 89 | + |
| 90 | +### `tests/jenkins.conf` |
| 91 | +JJB configuration template with API key placeholder |
| 92 | + |
| 93 | +### `globals/macros/macros.yml` |
| 94 | +Reusable JJB templates (SCM, parameters, triggers, etc.) |
| 95 | + |
| 96 | +### `jobs/jjb/*.yaml` |
| 97 | +Jenkins job definitions using JJB format |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## How Files Work Together |
| 102 | + |
| 103 | +``` |
| 104 | +Pull Request |
| 105 | + ↓ |
| 106 | +test.yaml → Containerfile → verify-yaml.sh → JJB (test mode) |
| 107 | + ↓ |
| 108 | +Validation Result → PR Status Check |
| 109 | + |
| 110 | +Merge to centos-ci |
| 111 | + ↓ |
| 112 | +deploy.yaml → Containerfile → deploy-nfs-ganesha-ci.sh |
| 113 | + ↓ |
| 114 | +jenkins.conf + API Key → JJB (update mode) |
| 115 | + ↓ |
| 116 | +macros.yml + jobs/jjb/*.yaml → Jenkins API |
| 117 | + ↓ |
| 118 | +Jobs Created/Updated in Jenkins |
| 119 | +``` |
| 120 | +
|
| 121 | +--- |
| 122 | +
|
| 123 | +## Testing Locally |
| 124 | +
|
| 125 | +```bash |
| 126 | +# 1. Build container |
| 127 | +docker build -t nfs-ganesha-ci-tests -f tests/Containerfile . |
| 128 | +
|
| 129 | +# 2. Test validation (like test.yaml) |
| 130 | +docker run --rm nfs-ganesha-ci-tests:latest |
| 131 | +
|
| 132 | +# 3. Generate XML preview |
| 133 | +docker run --rm -v $(pwd)/output:/output nfs-ganesha-ci-tests:latest sh -c \ |
| 134 | + "jenkins-jobs test globals/macros:jobs/jjb -o /output --config-xml" |
| 135 | +
|
| 136 | +# 4. View generated XML |
| 137 | +cat output/*/config.xml |
| 138 | +
|
| 139 | +# 5. Deploy to Jenkins (requires API key) |
| 140 | +docker run --rm --env="JENKINS_API_KEY=your-token" \ |
| 141 | + --entrypoint=tests/deploy-nfs-ganesha-ci.sh \ |
| 142 | + nfs-ganesha-ci-tests:latest |
| 143 | +``` |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## Quick Reference |
| 148 | + |
| 149 | +**Jenkins Server:** https://jenkins-nfs-ganesha.apps.ocp.cloud.ci.centos.org |
| 150 | + |
| 151 | +**Test locally:** `docker run --rm nfs-ganesha-ci-tests:latest` |
| 152 | + |
| 153 | +**Deploy:** Push to `centos-ci` branch |
| 154 | + |
| 155 | +**Monitor:** https://github.com/nfs-ganesha/ci-tests/actions |
0 commit comments