diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ed89b9..cdd037b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,27 +17,82 @@ jobs: - name: Check action files exist run: | - test -f action.yml - test -f plan/action.yml - test -f run/action.yml - test -f validate/action.yml + echo "::group::Check required files" + for f in action.yml plan/action.yml run/action.yml validate/action.yml; do + if [ -f "$f" ]; then + echo " ✓ $f" + else + echo "::error::Missing required file: $f" + exit 1 + fi + done + echo "::endgroup::" - name: Validate YAML syntax run: | + echo "::group::Validate YAML" python3 -c " import yaml, sys, pathlib files = ['action.yml','plan/action.yml','run/action.yml','validate/action.yml'] + ok = True for f in files: try: - yaml.safe_load(pathlib.Path(f).read_text()) - print(f'OK: {f}') + data = yaml.safe_load(pathlib.Path(f).read_text()) + assert 'name' in data, 'missing name field' + assert 'runs' in data, 'missing runs field' + print(f' ✓ {f} ({data[\"name\"]})') except Exception as e: - print(f'FAIL: {f}: {e}', file=sys.stderr) - sys.exit(1) + print(f' ✗ {f}: {e}', file=sys.stderr) + ok = False + if not ok: + sys.exit(1) " + echo "::endgroup::" - smoke-setup: - name: Smoke — setup action + - name: Validate action schema + run: | + echo "::group::Schema validation" + python3 -c " + import yaml, sys, pathlib + + def validate_action(path): + data = yaml.safe_load(pathlib.Path(path).read_text()) + errors = [] + if 'description' not in data: + errors.append('missing description') + if 'runs' not in data: + errors.append('missing runs') + elif data['runs'].get('using') != 'composite': + errors.append('not a composite action') + elif 'steps' not in data['runs']: + errors.append('missing steps in runs') + if data.get('inputs'): + for name, spec in data['inputs'].items(): + if 'description' not in spec: + errors.append(f'input \"{name}\" missing description') + if data.get('outputs'): + for name, spec in data['outputs'].items(): + if 'description' not in spec: + errors.append(f'output \"{name}\" missing description') + return errors + + files = ['action.yml','plan/action.yml','run/action.yml','validate/action.yml'] + ok = True + for f in files: + errs = validate_action(f) + if errs: + for e in errs: + print(f' ✗ {f}: {e}', file=sys.stderr) + ok = False + else: + print(f' ✓ {f}') + if not ok: + sys.exit(1) + " + echo "::endgroup::" + + test-setup: + name: Test setup — ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -46,5 +101,102 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Run setup action (dry-run via PATH check skipped — orun not published yet) - run: echo "Setup action structure validated on ${{ matrix.os }}" + - name: Install orun (latest) + uses: ./ + id: setup + + - name: Verify orun is in PATH + run: | + echo "::group::Verify installation" + which orun + orun --help || true + echo "::endgroup::" + + - name: Verify version output + run: | + VERSION="${{ steps.setup.outputs.version }}" + echo "Reported version: $VERSION" + if [ -z "$VERSION" ]; then + echo "::error::Setup action returned empty version" + exit 1 + fi + echo "::notice::Setup verified — orun $VERSION on ${{ matrix.os }}" + + test-setup-pinned: + name: Test setup — pinned version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install orun (pinned) + uses: ./ + id: setup + with: + version: v1.12.6 + + - name: Verify pinned version + run: | + VERSION="${{ steps.setup.outputs.version }}" + echo "Reported version: $VERSION" + if [ -z "$VERSION" ]; then + echo "::error::Expected a version string, got empty" + exit 1 + fi + echo "::notice::Pinned install verified — $VERSION" + + test-validate: + name: Test validate + runs-on: ubuntu-latest + needs: [test-setup] + steps: + - uses: actions/checkout@v4 + + - name: Create test intent + run: | + cat > test-intent.yaml << 'EOF' + version: "1" + name: ci-test + components: + - name: hello + type: service + path: . + jobs: + - id: greet + steps: + - run: echo "hello world" + EOF + + - name: Validate intent + uses: ./validate + id: validate + with: + intent: test-intent.yaml + + - name: Check output + run: | + if [ "${{ steps.validate.outputs.valid }}" != "true" ]; then + echo "::error::Expected valid=true" + exit 1 + fi + + test-validate-missing-file: + name: Test validate — missing file + runs-on: ubuntu-latest + needs: [test-setup] + steps: + - uses: actions/checkout@v4 + + - name: Validate non-existent file (expect failure) + uses: ./validate + id: validate + continue-on-error: true + with: + intent: does-not-exist.yaml + + - name: Verify failure + run: | + if [ "${{ steps.validate.outputs.valid }}" = "true" ]; then + echo "::error::Expected validation to fail for missing file" + exit 1 + fi + echo "::notice::Correctly rejected missing file" diff --git a/README.md b/README.md index b7f6ea8..080f2a9 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ jobs: id: plan with: intent: intent.yaml - version: v1.12.4 execute: needs: plan @@ -77,8 +76,6 @@ jobs: download-artifact: true remote-state: true backend-url: ${{ vars.ORUN_BACKEND_URL }} - exec-id: ${{ github.run_id }}-${{ github.run_attempt }} - version: v1.12.4 ``` ## Inputs @@ -87,7 +84,7 @@ jobs: | Input | Default | Description | |---|---|---| -| `version` | `latest` | orun version tag or `latest` | +| `version` | `latest` | orun version tag or `latest` (auto-resolves to newest release) | | `install-dir` | `~/.local/bin` | Directory to install the binary | | `install-url` | upstream | Override install script URL (air-gapped) | @@ -146,21 +143,23 @@ jobs: ## Version pinning ```yaml -# Floating major (convenience) +# Floating major (convenience — always gets latest orun) - uses: sourceplane/orun-action/plan@v1 # Pinned semver (recommended) -- uses: sourceplane/orun-action/plan@v1.0.0 +- uses: sourceplane/orun-action/plan@v1.1.0 # Pinned SHA (high-assurance / supply-chain audited) -- uses: sourceplane/orun-action/plan@ # v1.0.0 +- uses: sourceplane/orun-action/plan@ # v1.1.0 ``` The `v1` floating tag is force-pushed on every patch and minor release. Major version increments only on breaking input/output changes. ## Caching -The orun binary is cached by `runner.os`, `runner.arch`, and `version`. A pinned version produces a stable cache hit for the lifetime of the runner image. Optionally cache composition archives: +The orun binary is cached by `runner.os`, `runner.arch`, and the resolved version tag. When `version: latest` is used, the action resolves the actual release tag first so the cache key stays stable until a new orun release is published. + +Optionally cache composition archives: ```yaml - uses: actions/cache@v4 @@ -168,3 +167,9 @@ The orun binary is cached by `runner.os`, `runner.arch`, and `version`. A pinned path: .orun/cache key: orun-compositions-${{ hashFiles('.orun/compositions.lock.yaml') }} ``` + +## Log output + +All actions use GitHub Actions [log grouping](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines) for clean, collapsible output. Key events are surfaced as `::notice::` annotations and failures use `::error::` annotations with file-level targeting where applicable. + +Each action writes a structured [job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary) with execution results. diff --git a/action.yml b/action.yml index c0f52a8..0a38f11 100644 --- a/action.yml +++ b/action.yml @@ -20,9 +20,32 @@ outputs: runs: using: composite steps: + - name: Resolve version + id: version + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + echo "::group::Resolve orun version" + VERSION="${{ inputs.version }}" + if [ "$VERSION" = "latest" ] || [ -z "$VERSION" ]; then + AUTH_HEADER="" + if [ -n "$GH_TOKEN" ]; then + AUTH_HEADER="Authorization: Bearer $GH_TOKEN" + fi + VERSION=$(curl -fsSL \ + -H "Accept: application/vnd.github+json" \ + ${AUTH_HEADER:+-H "$AUTH_HEADER"} \ + https://api.github.com/repos/sourceplane/orun/releases/latest \ + | python3 -c "import sys,json; print(json.load(sys.stdin)['tag_name'])") + echo "Resolved latest → $VERSION" + fi + echo "tag=$VERSION" >> "$GITHUB_OUTPUT" + echo "::endgroup::" + - name: Resolve install dir id: dirs - shell: sh + shell: bash run: | INSTALL_DIR=$(echo "${{ inputs.install-dir }}" | sed "s|^~|$HOME|") mkdir -p "$INSTALL_DIR" @@ -33,21 +56,38 @@ runs: uses: actions/cache@v4 with: path: ${{ steps.dirs.outputs.path }}/orun - key: orun-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} + key: orun-${{ runner.os }}-${{ runner.arch }}-${{ steps.version.outputs.tag }} - name: Install orun if: steps.cache.outputs.cache-hit != 'true' - shell: sh + shell: bash env: - ORUN_VERSION: ${{ inputs.version }} + ORUN_VERSION: ${{ steps.version.outputs.tag }} ORUN_INSTALL_DIR: ${{ steps.dirs.outputs.path }} - run: curl -fsSL "${{ inputs.install-url }}" | sh + run: | + echo "::group::Install orun ${{ steps.version.outputs.tag }}" + curl -fsSL "${{ inputs.install-url }}" | sh + echo "::endgroup::" - name: Add to PATH - shell: sh + shell: bash run: echo "${{ steps.dirs.outputs.path }}" >> "$GITHUB_PATH" - - name: Resolve installed version + - name: Verify installation id: resolve - shell: sh - run: echo "version=$(orun version 2>/dev/null || echo unknown)" >> "$GITHUB_OUTPUT" + shell: bash + run: | + echo "::group::Verify orun" + ORUN_BIN="${{ steps.dirs.outputs.path }}/orun" + if [ ! -x "$ORUN_BIN" ]; then + echo "::error::orun installation failed — binary not found at $ORUN_BIN" + exit 1 + fi + INSTALLED_VERSION=$("$ORUN_BIN" version 2>&1 || "$ORUN_BIN" --version 2>&1 || echo "${{ steps.version.outputs.tag }}") + INSTALLED_VERSION=$(echo "$INSTALLED_VERSION" | grep -oE 'v?[0-9]+\.[0-9]+\.[0-9]+' | head -1) + if [ -z "$INSTALLED_VERSION" ]; then + INSTALLED_VERSION="${{ steps.version.outputs.tag }}" + fi + echo "version=$INSTALLED_VERSION" >> "$GITHUB_OUTPUT" + echo "::notice::orun $INSTALLED_VERSION ready" + echo "::endgroup::" diff --git a/plan/action.yml b/plan/action.yml index 1f123b0..26b3a25 100644 --- a/plan/action.yml +++ b/plan/action.yml @@ -48,24 +48,34 @@ runs: with: version: ${{ inputs.version }} - - name: Generate plan + - name: Compile plan id: plan shell: bash run: | set -euo pipefail + echo "::group::Compile execution plan" + CHANGED_FLAGS="" if [ "${{ inputs.changed-only }}" = "true" ]; then CHANGED_FLAGS="--changed" [ -n "${{ inputs.base-ref }}" ] && CHANGED_FLAGS="$CHANGED_FLAGS --base ${{ inputs.base-ref }}" [ -n "${{ inputs.head-ref }}" ] && CHANGED_FLAGS="$CHANGED_FLAGS --head ${{ inputs.head-ref }}" + echo "Scoping to changed components (base=${{ inputs.base-ref }}, head=${{ inputs.head-ref }})" fi + echo "Intent: ${{ inputs.intent }}" + echo "Output: ${{ inputs.output }}" + orun plan \ --intent "${{ inputs.intent }}" \ --output "${{ inputs.output }}" \ $CHANGED_FLAGS + echo "::endgroup::" + + echo "::group::Extract plan metadata" + PLAN_FILE="$(realpath "${{ inputs.output }}")" CHECKSUM="$(python3 -c "import json; d=json.load(open('${{ inputs.output }}')); print(d['metadata']['checksum'])")" JOB_IDS="$(python3 -c "import json; d=json.load(open('${{ inputs.output }}')); print(json.dumps([j['id'] for j in d['jobs']]))")" @@ -76,9 +86,29 @@ runs: echo "job-ids=$JOB_IDS" >> "$GITHUB_OUTPUT" echo "job-count=$JOB_COUNT" >> "$GITHUB_OUTPUT" - echo "## Plan" >> "$GITHUB_STEP_SUMMARY" - echo "- Checksum: \`$CHECKSUM\`" >> "$GITHUB_STEP_SUMMARY" - echo "- Jobs: $JOB_COUNT" >> "$GITHUB_STEP_SUMMARY" + echo "::endgroup::" + + # Job summary + { + echo "### Plan compiled" + echo "" + echo "| Property | Value |" + echo "|----------|-------|" + echo "| Checksum | \`$CHECKSUM\` |" + echo "| Jobs | **$JOB_COUNT** |" + echo "| Changed-only | ${{ inputs.changed-only }} |" + echo "" + if [ "$JOB_COUNT" -gt 0 ]; then + echo "
Job IDs" + echo "" + echo "\`\`\`json" + echo "$JOB_IDS" | python3 -c "import sys,json; print(json.dumps(json.load(sys.stdin), indent=2))" + echo "\`\`\`" + echo "
" + fi + } >> "$GITHUB_STEP_SUMMARY" + + echo "::notice::Plan compiled — $JOB_COUNT job(s), checksum $CHECKSUM" - name: Upload plan artifact if: inputs.upload-artifact == 'true' diff --git a/run/action.yml b/run/action.yml index 80674cc..5ab7539 100644 --- a/run/action.yml +++ b/run/action.yml @@ -57,7 +57,7 @@ runs: with: name: ${{ inputs.artifact-name }} - - name: Execute job + - name: Execute id: run shell: bash env: @@ -65,17 +65,57 @@ runs: run: | set -euo pipefail + JOB_LABEL="${{ inputs.job }}" + [ -z "$JOB_LABEL" ] && JOB_LABEL="all (sequential)" + echo "::group::Execute job: $JOB_LABEL" + FLAGS="" [ -n "${{ inputs.job }}" ] && FLAGS="$FLAGS --job ${{ inputs.job }}" [ "${{ inputs.remote-state }}" = "true" ] && FLAGS="$FLAGS --remote-state" [ "${{ inputs.dry-run }}" = "true" ] && FLAGS="$FLAGS --dry-run" + echo "Plan: ${{ inputs.plan }}" + echo "Runner: ${{ inputs.runner }}" + echo "Exec ID: ${{ inputs.exec-id }}" + echo "Remote state: ${{ inputs.remote-state }}" + echo "Dry run: ${{ inputs.dry-run }}" + echo "---" + + EXEC_STATUS=0 orun run \ --plan "${{ inputs.plan }}" \ --runner "${{ inputs.runner }}" \ --workdir "${{ inputs.workdir }}" \ --exec-id "${{ inputs.exec-id }}" \ - $FLAGS + $FLAGS || EXEC_STATUS=$? + + echo "::endgroup::" echo "exec-id=${{ inputs.exec-id }}" >> "$GITHUB_OUTPUT" - echo "status=success" >> "$GITHUB_OUTPUT" + + if [ $EXEC_STATUS -eq 0 ]; then + echo "status=success" >> "$GITHUB_OUTPUT" + echo "::notice::Job $JOB_LABEL completed successfully" + { + echo "### Job executed: \`$JOB_LABEL\`" + echo "" + echo "| Property | Value |" + echo "|----------|-------|" + echo "| Status | :white_check_mark: success |" + echo "| Exec ID | \`${{ inputs.exec-id }}\` |" + echo "| Runner | ${{ inputs.runner }} |" + } >> "$GITHUB_STEP_SUMMARY" + else + echo "status=failure" >> "$GITHUB_OUTPUT" + echo "::error::Job $JOB_LABEL failed with exit code $EXEC_STATUS" + { + echo "### Job executed: \`$JOB_LABEL\`" + echo "" + echo "| Property | Value |" + echo "|----------|-------|" + echo "| Status | :x: failure (exit $EXEC_STATUS) |" + echo "| Exec ID | \`${{ inputs.exec-id }}\` |" + echo "| Runner | ${{ inputs.runner }} |" + } >> "$GITHUB_STEP_SUMMARY" + exit $EXEC_STATUS + fi diff --git a/validate/action.yml b/validate/action.yml index d48f624..12ad959 100644 --- a/validate/action.yml +++ b/validate/action.yml @@ -21,9 +21,37 @@ runs: with: version: ${{ inputs.version }} - - name: Validate + - name: Validate intent id: validate shell: bash run: | - orun validate --intent "${{ inputs.intent }}" - echo "valid=true" >> "$GITHUB_OUTPUT" + set -euo pipefail + echo "::group::Validate ${{ inputs.intent }}" + + if [ ! -f "${{ inputs.intent }}" ]; then + echo "::error file=${{ inputs.intent }}::Intent file not found: ${{ inputs.intent }}" + echo "valid=false" >> "$GITHUB_OUTPUT" + echo "::endgroup::" + exit 1 + fi + + if orun validate --intent "${{ inputs.intent }}"; then + echo "valid=true" >> "$GITHUB_OUTPUT" + echo "::notice::Validation passed for ${{ inputs.intent }}" + { + echo "### Validation: :white_check_mark: passed" + echo "" + echo "Intent file \`${{ inputs.intent }}\` is valid." + } >> "$GITHUB_STEP_SUMMARY" + else + echo "valid=false" >> "$GITHUB_OUTPUT" + echo "::error file=${{ inputs.intent }}::Validation failed for ${{ inputs.intent }}" + { + echo "### Validation: :x: failed" + echo "" + echo "Intent file \`${{ inputs.intent }}\` has errors. Check the logs above for details." + } >> "$GITHUB_STEP_SUMMARY" + exit 1 + fi + + echo "::endgroup::"