Skip to content

Commit 94e1a59

Browse files
committed
Minor changes
1 parent c2dd5f1 commit 94e1a59

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

.DS_Store

6 KB
Binary file not shown.

.github/workflows/deploy.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ jobs:
113113
printf '%s\n' "$MESH_SECRETS" > secrets.yaml
114114
chmod 600 secrets.yaml
115115
- name: Materialize branch .env file
116+
shell: bash
116117
if: ${{ env.AIO_ENV_FILE != '' }}
117118
run: |
118119
set -euo pipefail

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Repository layout (expected):
2929
├── .github/workflows/tests.yaml # Reusable Newman regression tests
3030
├── mesh.json # API Mesh definition (commit your own)
3131
├── .env # Optional runtime variables used by mesh.json
32+
├── tests/
33+
│ └── newman/
34+
│ ├── collection.json # Postman collection export
35+
│ ├── environment_staging.json # Environment variables for staging
36+
│ └── environment_production.json # Environment variables for production
3237
└── README.md # This documentation
3338
```
3439

@@ -69,6 +74,27 @@ Add any extra secrets referenced by your mesh (for custom resolvers, HTTP header
6974

7075
If these variables are present, the workflow writes them to `.env` before running `aio api-mesh:*`. If they are empty, the pipeline falls back to any `.env` file committed in the repository or skips the flag entirely.
7176

77+
#### How Environment Variable Injection Works
78+
79+
The workflow uses an internal environment variable `AIO_ENV_FILE` to handle the `.env` materialization:
80+
81+
1. **Branch detection** — The workflow identifies the current branch (`staging` or `production`).
82+
2. **Variable mapping** — If `ENV_STAGE` or `ENV_PROD` is set, its contents are stored in the `AIO_ENV_FILE` workflow environment variable.
83+
3. **File materialization** — If `AIO_ENV_FILE` is not empty, the workflow writes its contents to `.env` in the repository root with restricted permissions (`chmod 600`).
84+
4. **Flag computation** — The "Compute Mesh Credential Flags" step checks for the presence of `.env` and automatically appends `--env .env` to the mesh CLI commands.
85+
86+
This approach allows you to:
87+
- Keep sensitive environment values out of Git by storing them as GitHub Variables.
88+
- Override a committed `.env` file with branch-specific values.
89+
- Support multi-line `.env` payloads (GitHub Variables preserve newlines).
90+
91+
**Example `ENV_STAGE` variable content:**
92+
```
93+
RESOLVER_API_KEY=sk-staging-xxx
94+
BACKEND_URL=https://api.staging.example.com
95+
DEBUG=true
96+
```
97+
7298
---
7399

74100
### Runner image requirements
@@ -171,6 +197,78 @@ Extend or reorder steps as needed (e.g., run linting/tests before deployment, se
171197

172198
---
173199

200+
## Newman Testing Configuration
201+
202+
The template includes a reusable testing workflow (`.github/workflows/tests.yaml`) that runs Newman-based regression tests after each successful deployment. Tests are **optional** — the workflow gracefully skips execution if the required files are not present.
203+
204+
### Required Folder Structure
205+
206+
```
207+
tests/
208+
└── newman/
209+
├── collection.json # Postman collection export (required)
210+
├── environment_staging.json # Environment variables for staging branch
211+
└── environment_production.json # Environment variables for production branch
212+
```
213+
214+
### File Details
215+
216+
| File | Description |
217+
| --- | --- |
218+
| `collection.json` | Exported Postman collection containing your API tests. Export from Postman using **Collection → Export → Collection v2.1**. |
219+
| `environment_staging.json` | Postman environment export with variables for staging (e.g., `baseUrl`, API keys). The filename must match `environment_staging.json`. |
220+
| `environment_production.json` | Postman environment export with variables for production. The filename must match `environment_production.json`. |
221+
222+
### How It Works
223+
224+
1. After the `deploy` job completes successfully, the `tests` job is triggered.
225+
2. The workflow checks for `tests/newman/collection.json` — if missing, tests are skipped.
226+
3. The workflow looks for `tests/newman/environment_<branch>.json` based on the current branch — if missing, tests are skipped.
227+
4. If both files exist, Newman runs inside a Docker container (`postman/newman_alpine33`) and executes all requests in the collection against the branch-specific environment.
228+
229+
### Creating Your Test Files
230+
231+
1. **Export your Postman collection:**
232+
- Open Postman and select your collection.
233+
- Click the **...** menu → **Export****Collection v2.1** → Save as `collection.json`.
234+
235+
2. **Export your Postman environments:**
236+
- Go to **Environments** in Postman.
237+
- Select the environment → **...****Export** → Save as `environment_staging.json` or `environment_production.json`.
238+
239+
3. **Place files in the correct location:**
240+
```bash
241+
mkdir -p tests/newman
242+
mv collection.json tests/newman/
243+
mv environment_staging.json tests/newman/
244+
mv environment_production.json tests/newman/
245+
```
246+
247+
### Example Environment File
248+
249+
```json
250+
{
251+
"id": "abc123",
252+
"name": "staging",
253+
"values": [
254+
{
255+
"key": "baseUrl",
256+
"value": "https://your-mesh-staging.adobeioruntime.net/api/v1/web/mesh",
257+
"enabled": true
258+
},
259+
{
260+
"key": "apiKey",
261+
"value": "your-staging-api-key",
262+
"enabled": true
263+
}
264+
]
265+
}
266+
```
267+
268+
> **Tip:** Avoid committing sensitive values in environment files. Use Postman's variable substitution with placeholder values and override them via GitHub Secrets if needed.
269+
270+
---
271+
174272
## Customizing the Template
175273

176274
- **Additional environments** – duplicate the branch/secrets mapping block and add new branches like `qa` or `dev` with their own credential sets.

0 commit comments

Comments
 (0)