dispatch-workflow.sh: piiloriippuvuudet pois — GITEA_API_URL ja GITEA_TOKEN nyt explicit parametreina
This commit is contained in:
@@ -67,7 +67,7 @@ Dispatchaa workflow'n toisessa repossa ja pollaa sen valmistumista synkronisesti
|
|||||||
### Rajapinta
|
### Rajapinta
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_minutes]
|
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> <gitea_api_url> <gitea_token> [timeout_minutes]
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parametri | Pakollinen | Kuvaus |
|
| Parametri | Pakollinen | Kuvaus |
|
||||||
@@ -76,6 +76,8 @@ dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_
|
|||||||
| `workflow_file` | Kyllä | Workflow-tiedoston nimi (esim. `test.yml`) |
|
| `workflow_file` | Kyllä | Workflow-tiedoston nimi (esim. `test.yml`) |
|
||||||
| `ref` | Kyllä | Branch |
|
| `ref` | Kyllä | Branch |
|
||||||
| `inputs_json` | Kyllä | JSON-objekti input-parametreina |
|
| `inputs_json` | Kyllä | JSON-objekti input-parametreina |
|
||||||
|
| `gitea_api_url` | Kyllä | Gitean API-URL (esim. `https://gitea.example.com`) |
|
||||||
|
| `gitea_token` | Kyllä | Gitea API -token |
|
||||||
| `timeout_minutes` | Ei | Oletus: 360 (6 tuntia) |
|
| `timeout_minutes` | Ei | Oletus: 360 (6 tuntia) |
|
||||||
|
|
||||||
### Toiminta
|
### Toiminta
|
||||||
@@ -90,7 +92,8 @@ dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
dispatch-workflow.sh "tests/integration" "test.yml" "main" \
|
dispatch-workflow.sh "tests/integration" "test.yml" "main" \
|
||||||
'{"version":"1.2.3","tags":"@smoke","root_commit":"abc123","root_repo":"services/temperature-store"}'
|
'{"version":"1.2.3","tags":"@smoke","root_commit":"abc123","root_repo":"services/temperature-store"}' \
|
||||||
|
"https://gitea.example.com" "gtp_abc123"
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -181,8 +184,8 @@ Skriptit lukevat nämä Gitea Actionsin ympäristömuuttujat:
|
|||||||
|
|
||||||
| Muuttuja | Lähde | Käyttäjä |
|
| Muuttuja | Lähde | Käyttäjä |
|
||||||
|----------|-------|----------|
|
|----------|-------|----------|
|
||||||
| `GITEA_API_URL` | Org variable | Kaikki skriptit |
|
| `GITEA_API_URL` | Org variable | `report-status.sh` |
|
||||||
| `GITEA_TOKEN` | Org secret | `report-status.sh`, `dispatch-workflow.sh`, `tag-commit.sh` |
|
| `GITEA_TOKEN` | Org secret | `report-status.sh`, `tag-commit.sh` |
|
||||||
| `MINIO_BASE_URL` | Org variable | `push-reports.sh` |
|
| `MINIO_BASE_URL` | Org variable | `push-reports.sh` |
|
||||||
| `MINIO_ACCESS_KEY` | Org secret | `push-reports.sh` |
|
| `MINIO_ACCESS_KEY` | Org secret | `push-reports.sh` |
|
||||||
| `MINIO_SECRET_KEY` | Org secret | `push-reports.sh` |
|
| `MINIO_SECRET_KEY` | Org secret | `push-reports.sh` |
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ Dispatchaa workflow toisessa repossa ja pollaa sen valmistumista synkronisesti.
|
|||||||
## Rajapinta
|
## Rajapinta
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_minutes]
|
dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> <gitea_api_url> <gitea_token> [timeout_minutes]
|
||||||
```
|
```
|
||||||
|
|
||||||
| Parametri | Pakollinen | Kuvaus |
|
| Parametri | Pakollinen | Kuvaus |
|
||||||
@@ -63,6 +63,8 @@ dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_
|
|||||||
| `workflow_file` | Kyllä | Workflow-tiedosto (esim. `test.yml`) |
|
| `workflow_file` | Kyllä | Workflow-tiedosto (esim. `test.yml`) |
|
||||||
| `ref` | Kyllä | Branch |
|
| `ref` | Kyllä | Branch |
|
||||||
| `inputs_json` | Kyllä | JSON-objekti input-parametreina |
|
| `inputs_json` | Kyllä | JSON-objekti input-parametreina |
|
||||||
|
| `gitea_api_url` | Kyllä | Gitean API-URL |
|
||||||
|
| `gitea_token` | Kyllä | Gitea API -token |
|
||||||
| `timeout_minutes` | Ei | Oletus: 360 |
|
| `timeout_minutes` | Ei | Oletus: 360 |
|
||||||
|
|
||||||
## API-kutsut
|
## API-kutsut
|
||||||
@@ -77,7 +79,8 @@ dispatch-workflow.sh <target_repo> <workflow_file> <ref> <inputs_json> [timeout_
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
dispatch-workflow.sh "tests/integration" "test.yml" "main" \
|
dispatch-workflow.sh "tests/integration" "test.yml" "main" \
|
||||||
'{"version":"1.2.3","tags":"@smoke","root_commit":"abc123","root_repo":"services/temperature-store"}'
|
'{"version":"1.2.3","tags":"@smoke","root_commit":"abc123","root_repo":"services/temperature-store"}' \
|
||||||
|
"https://gitea.example.com" "gtp_abc123"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Verifiointi
|
## Verifiointi
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
[ -z "${GITEA_API_URL:-}" ] && echo "ERROR: GITEA_API_URL is not set" >&2 && exit 1
|
|
||||||
[ -z "${GITEA_TOKEN:-}" ] && echo "ERROR: GITEA_TOKEN is not set" >&2 && exit 1
|
|
||||||
|
|
||||||
TARGET_REPO="${1:-}"
|
TARGET_REPO="${1:-}"
|
||||||
WORKFLOW_FILE="${2:-}"
|
WORKFLOW_FILE="${2:-}"
|
||||||
REF="${3:-}"
|
REF="${3:-}"
|
||||||
INPUTS_JSON="${4:-}"
|
INPUTS_JSON="${4:-}"
|
||||||
TIMEOUT_MINUTES="${5:-360}"
|
GITEA_API_URL="${5:-}"
|
||||||
|
GITEA_TOKEN="${6:-}"
|
||||||
|
TIMEOUT_MINUTES="${7:-360}"
|
||||||
POLL_INTERVAL="${DISPATCH_POLL_INTERVAL:-10}"
|
POLL_INTERVAL="${DISPATCH_POLL_INTERVAL:-10}"
|
||||||
|
|
||||||
[ -z "$TARGET_REPO" ] && echo "ERROR: target_repo argument is required" >&2 && exit 1
|
[ -z "$TARGET_REPO" ] && echo "ERROR: target_repo argument is required" >&2 && exit 1
|
||||||
[ -z "$WORKFLOW_FILE" ] && echo "ERROR: workflow_file argument is required" >&2 && exit 1
|
[ -z "$WORKFLOW_FILE" ] && echo "ERROR: workflow_file argument is required" >&2 && exit 1
|
||||||
[ -z "$REF" ] && echo "ERROR: ref argument is required" >&2 && exit 1
|
[ -z "$REF" ] && echo "ERROR: ref argument is required" >&2 && exit 1
|
||||||
[ -z "$INPUTS_JSON" ] && echo "ERROR: inputs_json argument is required" >&2 && exit 1
|
[ -z "$INPUTS_JSON" ] && echo "ERROR: inputs_json argument is required" >&2 && exit 1
|
||||||
|
[ -z "$GITEA_API_URL" ] && echo "ERROR: gitea_api_url argument is required" >&2 && exit 1
|
||||||
|
[ -z "$GITEA_TOKEN" ] && echo "ERROR: gitea_token argument is required" >&2 && exit 1
|
||||||
|
|
||||||
DISPATCH_URL="$GITEA_API_URL/api/v1/repos/$TARGET_REPO/actions/workflows/$WORKFLOW_FILE/dispatches"
|
DISPATCH_URL="$GITEA_API_URL/api/v1/repos/$TARGET_REPO/actions/workflows/$WORKFLOW_FILE/dispatches"
|
||||||
DISPATCH_BODY=$(jq -nc --arg ref "$REF" --argjson inputs "$INPUTS_JSON" '{ref: $ref, inputs: $inputs}')
|
DISPATCH_BODY=$(jq -nc --arg ref "$REF" --argjson inputs "$INPUTS_JSON" '{ref: $ref, inputs: $inputs}')
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
source tests/helpers/mock-api.sh
|
source tests/helpers/mock-api.sh
|
||||||
export GITEA_API_URL="http://localhost:18080"
|
|
||||||
export GITEA_TOKEN="test-token-abc123"
|
|
||||||
export DISPATCH_POLL_INTERVAL="0.1"
|
export DISPATCH_POLL_INTERVAL="0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +19,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +31,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +43,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +61,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"running"}}
|
{"code":200,"body":{"id":1,"status":"running"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "0.001"
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" "0.001"
|
||||||
[ "$status" -eq 124 ]
|
[ "$status" -eq 124 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ teardown() {
|
|||||||
{"code":500}
|
{"code":500}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +81,7 @@ teardown() {
|
|||||||
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
|
||||||
]'
|
]'
|
||||||
mock_start
|
mock_start
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
path=$(mock_get_first_request_path)
|
path=$(mock_get_first_request_path)
|
||||||
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
|
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
|
||||||
@@ -95,36 +93,34 @@ teardown() {
|
|||||||
[[ "$body" == *'"version":"1.2.3"'* ]]
|
[[ "$body" == *'"version":"1.2.3"'* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing GITEA_API_URL → exit 1 with error message" {
|
@test "missing gitea_api_url argument → exit 1 with error message" {
|
||||||
unset GITEA_API_URL
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "" "test-token-abc123"
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[[ "$output" == *"ERROR"* || "$output" == *"GITEA_API_URL"* ]]
|
[[ "$output" == *"ERROR"* || "$output" == *"gitea_api_url"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing GITEA_TOKEN → exit 1 with error message" {
|
@test "missing gitea_token argument → exit 1 with error message" {
|
||||||
unset GITEA_TOKEN
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" ""
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}'
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[[ "$output" == *"ERROR"* || "$output" == *"GITEA_TOKEN"* ]]
|
[[ "$output" == *"ERROR"* || "$output" == *"gitea_token"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing target_repo argument → exit 1" {
|
@test "missing target_repo argument → exit 1" {
|
||||||
run bash scripts/dispatch-workflow.sh "" "test.yml" "main" '{}'
|
run bash scripts/dispatch-workflow.sh "" "test.yml" "main" '{}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing workflow_file argument → exit 1" {
|
@test "missing workflow_file argument → exit 1" {
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "" "main" '{}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "" "main" '{}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing ref argument → exit 1" {
|
@test "missing ref argument → exit 1" {
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "" '{}'
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "" '{}' "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "missing inputs_json argument → exit 1" {
|
@test "missing inputs_json argument → exit 1" {
|
||||||
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" ""
|
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" "" "http://localhost:18080" "test-token-abc123"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user